gpt4 book ai didi

Django mod_wsgi : ImportError: No module named '$myproject'

转载 作者:行者123 更新时间:2023-12-04 18:37:50 25 4
gpt4 key购买 nike

所以我一直在摸索一段时间试图弄清楚这一点。我在 Ubuntu 16.04 上,有 2 个不同的 django 项目。此处的目的是使用“sites-(enabled|available)”文件夹中的两个不同文件在同一服务器上的两个单独域上并排运行两者。一个工作正常(并且已经有一段时间了,第二个站点是新站点)。第二个不是。我猜这与我的 wsgi 设置有关。为了使事情复杂化,我也使用了lets-encrypt。我确信这不是问题,但我会发布他们的 confs 以确保。

项目一位于目录 /home/arlyon/arlyon nr2 在目录 /home/arlyon/threeswords 中.

000-default.conf

<VirtualHost *:80>

ServerName www.site1.com
ServerAlias site1.com
ServerAdmin mail@me.com
DocumentRoot /home/arlyon/arlyon

WSGIScriptAlias / /home/arlyon/arlyon/arlyon/apache/wsgi.py
WSGIDaemonProcess arlyon python-home=/home/arlyon/arlyon/venv python-path=/home/arlyon/arlyon
WSGIProcessGroup arlyon


Alias /static/ /home/arlyon/arlyon/static/
<Directory /home/arlyon/arlyon/static>
Require all granted
</Directory>

Alias /media/ /home/arlyon/arlyon/media/
<Directory /home/arlyon/arlyon/media>
Require all granted
</Directory>

ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined

RewriteEngine on
RewriteCond %{SERVER_NAME} =www.site1.com
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,QSA,R=permanent]

RewriteCond %{HTTPS} !=on
RewriteCond %{HTTP_HOST} !^www\..+$ [NC]
RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

</VirtualHost>

000-默认-le-ssl
<IfModule mod_ssl.c>
<VirtualHost *:443>

ServerName www.site1.com
ServerAlias site1.com
ServerAdmin mail@me.com
DocumentRoot /home/arlyon/arlyon

# user/project/projectapp
# project and home dir are the same

WSGIScriptAlias / /home/arlyon/arlyon/arlyon/apache/wsgi.py
Alias /static/ /home/arlyon/arlyon/static/
<Directory /home/arlyon/arlyon/static>
Require all granted
</Directory>

Alias /media/ /home/arlyon/arlyon/media/
<Directory /home/arlyon/arlyon/media>
Require all granted
</Directory>


ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined

SSLCertificateFile /etc/letsencrypt/live/www.site1.com/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/www.site1.com/privkey.pem
Include /etc/letsencrypt/options-ssl-apache.conf

</VirtualHost>
</IfModule>

site2.conf
<VirtualHost *:80>

ServerName www.site2.com
ServerAlias *.site2.com
ServerAdmin mail@me.com
DocumentRoot /home/arlyon/threeswords

WSGIScriptAlias / /home/arlyon/threeswords/threeswords/wsgi.py
WSGIDaemonProcess threeswords python-path=/home/arlyon/threeswords python-home=/home/arlyon/threeswords/venv
WSGIProcessGroup threeswords

<Directory "/home/arlyon/threeswords/threeswords/">
<Files wsgi.py>
Require all granted
</Files>
</Directory>

Alias /static/ /home/arlyon/threeswords/static/
<Directory /home/arlyon/threeswords/static>
Require all granted
</Directory>

Alias /media/ /home/arlyon/threeswords/media/
<Directory /home/arlyon/threeswords/media>
Require all granted
</Directory>

ErrorLog ${APACHE_LOG_DIR}/ts_error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined

RewriteEngine on
RewriteCond %{SERVER_NAME} =www.site2.no [OR]
RewriteCond %{SERVER_NAME} =*.site2.no
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,QSA,R=permanent]

</VirtualHost>

三剑-le-ssl.conf
<IfModule mod_ssl.c>
<VirtualHost *:443>

ServerName www.site2.no
ServerAlias *.site2.no
ServerAdmin arlyon@me.com
DocumentRoot /home/arlyon/threeswords

WSGIScriptAlias / /home/arlyon/threeswords/threeswords/wsgi.py

Alias /static/ /home/arlyon/threeswords/static/
<Directory /home/arlyon/threeswords/static>
Require all granted
</Directory>

Alias /media/ /home/arlyon/threeswords/media/
<Directory /home/arlyon/threeswords/media>
Require all granted
</Directory>

ErrorLog ${APACHE_LOG_DIR}/ts_error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined

RewriteEngine on
RewriteCond %{SERVER_NAME} =www.site2.no
# Some rewrite rules in this file were were disabled on your HTTPS site,
# because they have the potential to create redirection loops.
# RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,QSA,R=permanent]

RewriteCond %{HTTPS} !=on
RewriteCond %{HTTP_HOST} !^www\..+$ [NC]
RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

SSLCertificateFile /etc/letsencrypt/live/www.site1.com/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/www.site1.com/privkey.pem
Include /etc/letsencrypt/options-ssl-apache.conf

</VirtualHost>
</IfModule>

我的 wsgi 配置存在一些问题,导致服务器无法导入 myproject。但是,我不知道为什么会这样。这是有问题的 wsgi.py .
from __future__ import absolute_import, unicode_literals
import site
import os

from django.core.wsgi import get_wsgi_application

site.addsitedir('/home/arlyon/threeswords/venv/lib/python3.5/site-packages')
os.environ["DJANGO_SETTINGS_MODULE"] = "threeswords.settings.dev"

application = get_wsgi_application()

venv 指向正确的位置。尝试设置设置模块时,它会抛出 导入错误 .最后这里是错误:
[Mon Nov 07 23:27:29.484760 2016] [wsgi:error] [pid 30535:tid 140472987141888] [client 92.221.32.65:56377] mod_wsgi (pid=30535): Target WSGI script '/home/arlyon/threeswords/threeswords/wsgi.py' cannot be loaded as Python module.
[Mon Nov 07 23:27:29.484844 2016] [wsgi:error] [pid 30535:tid 140472987141888] [client 92.221.32.65:56377] mod_wsgi (pid=30535): Exception occurred processing WSGI script '/home/arlyon/threeswords/threeswords/wsgi.py'.
[Mon Nov 07 23:27:29.485206 2016] [wsgi:error] [pid 30535:tid 140472987141888] [client 92.221.32.65:56377] Traceback (most recent call last):
[Mon Nov 07 23:27:29.485321 2016] [wsgi:error] [pid 30535:tid 140472987141888] [client 92.221.32.65:56377] File "/home/arlyon/threeswords/threeswords/wsgi.py", line 19, in <module>
[Mon Nov 07 23:27:29.485349 2016] [wsgi:error] [pid 30535:tid 140472987141888] [client 92.221.32.65:56377] application = get_wsgi_application()
[Mon Nov 07 23:27:29.485369 2016] [wsgi:error] [pid 30535:tid 140472987141888] [client 92.221.32.65:56377] File "/usr/local/lib/python3.5/dist-packages/django/core/wsgi.py", line 13, in get_wsgi_application
[Mon Nov 07 23:27:29.485379 2016] [wsgi:error] [pid 30535:tid 140472987141888] [client 92.221.32.65:56377] django.setup()
[Mon Nov 07 23:27:29.485397 2016] [wsgi:error] [pid 30535:tid 140472987141888] [client 92.221.32.65:56377] File "/usr/local/lib/python3.5/dist-packages/django/__init__.py", line 17, in setup
[Mon Nov 07 23:27:29.485407 2016] [wsgi:error] [pid 30535:tid 140472987141888] [client 92.221.32.65:56377] configure_logging(settings.LOGGING_CONFIG, settings.LOGGING)
[Mon Nov 07 23:27:29.485425 2016] [wsgi:error] [pid 30535:tid 140472987141888] [client 92.221.32.65:56377] File "/usr/local/lib/python3.5/dist-packages/django/conf/__init__.py", line 55, in __getattr__
[Mon Nov 07 23:27:29.485435 2016] [wsgi:error] [pid 30535:tid 140472987141888] [client 92.221.32.65:56377] self._setup(name)
[Mon Nov 07 23:27:29.485452 2016] [wsgi:error] [pid 30535:tid 140472987141888] [client 92.221.32.65:56377] File "/usr/local/lib/python3.5/dist-packages/django/conf/__init__.py", line 43, in _setup
[Mon Nov 07 23:27:29.485462 2016] [wsgi:error] [pid 30535:tid 140472987141888] [client 92.221.32.65:56377] self._wrapped = Settings(settings_module)
[Mon Nov 07 23:27:29.485480 2016] [wsgi:error] [pid 30535:tid 140472987141888] [client 92.221.32.65:56377] File "/usr/local/lib/python3.5/dist-packages/django/conf/__init__.py", line 99, in __init__
[Mon Nov 07 23:27:29.485489 2016] [wsgi:error] [pid 30535:tid 140472987141888] [client 92.221.32.65:56377] mod = importlib.import_module(self.SETTINGS_MODULE)
[Mon Nov 07 23:27:29.485507 2016] [wsgi:error] [pid 30535:tid 140472987141888] [client 92.221.32.65:56377] File "/usr/lib/python3.5/importlib/__init__.py", line 126, in import_module
[Mon Nov 07 23:27:29.485517 2016] [wsgi:error] [pid 30535:tid 140472987141888] [client 92.221.32.65:56377] return _bootstrap._gcd_import(name[level:], package, level)
[Mon Nov 07 23:27:29.485534 2016] [wsgi:error] [pid 30535:tid 140472987141888] [client 92.221.32.65:56377] File "<frozen importlib._bootstrap>", line 986, in _gcd_import
[Mon Nov 07 23:27:29.485554 2016] [wsgi:error] [pid 30535:tid 140472987141888] [client 92.221.32.65:56377] File "<frozen importlib._bootstrap>", line 969, in _find_and_load
[Mon Nov 07 23:27:29.485573 2016] [wsgi:error] [pid 30535:tid 140472987141888] [client 92.221.32.65:56377] File "<frozen importlib._bootstrap>", line 944, in _find_and_load_unlocked
[Mon Nov 07 23:27:29.485592 2016] [wsgi:error] [pid 30535:tid 140472987141888] [client 92.221.32.65:56377] File "<frozen importlib._bootstrap>", line 222, in _call_with_frames_removed
[Mon Nov 07 23:27:29.485612 2016] [wsgi:error] [pid 30535:tid 140472987141888] [client 92.221.32.65:56377] File "<frozen importlib._bootstrap>", line 986, in _gcd_import
[Mon Nov 07 23:27:29.485631 2016] [wsgi:error] [pid 30535:tid 140472987141888] [client 92.221.32.65:56377] File "<frozen importlib._bootstrap>", line 969, in _find_and_load
[Mon Nov 07 23:27:29.485650 2016] [wsgi:error] [pid 30535:tid 140472987141888] [client 92.221.32.65:56377] File "<frozen importlib._bootstrap>", line 944, in _find_and_load_unlocked
[Mon Nov 07 23:27:29.485669 2016] [wsgi:error] [pid 30535:tid 140472987141888] [client 92.221.32.65:56377] File "<frozen importlib._bootstrap>", line 222, in _call_with_frames_removed
[Mon Nov 07 23:27:29.485688 2016] [wsgi:error] [pid 30535:tid 140472987141888] [client 92.221.32.65:56377] File "<frozen importlib._bootstrap>", line 986, in _gcd_import
[Mon Nov 07 23:27:29.485707 2016] [wsgi:error] [pid 30535:tid 140472987141888] [client 92.221.32.65:56377] File "<frozen importlib._bootstrap>", line 969, in _find_and_load
[Mon Nov 07 23:27:29.485736 2016] [wsgi:error] [pid 30535:tid 140472987141888] [client 92.221.32.65:56377] File "<frozen importlib._bootstrap>", line 956, in _find_and_load_unlocked
[Mon Nov 07 23:27:29.485774 2016] [wsgi:error] [pid 30535:tid 140472987141888] [client 92.221.32.65:56377] ImportError: No module named 'threeswords'
[Mon Nov 07 23:27:29.700491 2016] [wsgi:error] [pid 30535:tid 140472978749184] [client 92.221.32.65:56378] mod_wsgi (pid=30535): Target WSGI script '/home/arlyon/threeswords/threeswords/wsgi.py' cannot be loaded as Python module., referer: https://www.site2.no/
[Mon Nov 07 23:27:29.700569 2016] [wsgi:error] [pid 30535:tid 140472978749184] [client 92.221.32.65:56378] mod_wsgi (pid=30535): Exception occurred processing WSGI script '/home/arlyon/threeswords/threeswords/wsgi.py'., referer: https://www.site2.com/
[Mon Nov 07 23:27:29.700934 2016] [wsgi:error] [pid 30535:tid 140472978749184] [client 92.221.32.65:56378] Traceback (most recent call last):, referer: https://www.site2.com/
[Mon Nov 07 23:27:29.701050 2016] [wsgi:error] [pid 30535:tid 140472978749184] [client 92.221.32.65:56378] File "/home/arlyon/threeswords/threeswords/wsgi.py", line 19, in <module>, referer: https://www.site2.com/
[Mon Nov 07 23:27:29.701061 2016] [wsgi:error] [pid 30535:tid 140472978749184] [client 92.221.32.65:56378] application = get_wsgi_application(), referer: https://www.site2.com/
[Mon Nov 07 23:27:29.701081 2016] [wsgi:error] [pid 30535:tid 140472978749184] [client 92.221.32.65:56378] File "/usr/local/lib/python3.5/dist-packages/django/core/wsgi.py", line 13, in get_wsgi_application, referer: https://www.site2.com/
[Mon Nov 07 23:27:29.701091 2016] [wsgi:error] [pid 30535:tid 140472978749184] [client 92.221.32.65:56378] django.setup(), referer: https://www.site2.com/
[Mon Nov 07 23:27:29.701110 2016] [wsgi:error] [pid 30535:tid 140472978749184] [client 92.221.32.65:56378] File "/usr/local/lib/python3.5/dist-packages/django/__init__.py", line 17, in setup, referer: https://www.site2.com/
[Mon Nov 07 23:27:29.701120 2016] [wsgi:error] [pid 30535:tid 140472978749184] [client 92.221.32.65:56378] configure_logging(settings.LOGGING_CONFIG, settings.LOGGING), referer: https://www.site2.com/
[Mon Nov 07 23:27:29.701139 2016] [wsgi:error] [pid 30535:tid 140472978749184] [client 92.221.32.65:56378] File "/usr/local/lib/python3.5/dist-packages/django/conf/__init__.py", line 55, in __getattr__, referer: https://www.site2.com/
[Mon Nov 07 23:27:29.701149 2016] [wsgi:error] [pid 30535:tid 140472978749184] [client 92.221.32.65:56378] self._setup(name), referer: https://www.site2.com/
[Mon Nov 07 23:27:29.701183 2016] [wsgi:error] [pid 30535:tid 140472978749184] [client 92.221.32.65:56378] File "/usr/local/lib/python3.5/dist-packages/django/conf/__init__.py", line 43, in _setup, referer: https://www.site2.com/
[Mon Nov 07 23:27:29.701193 2016] [wsgi:error] [pid 30535:tid 140472978749184] [client 92.221.32.65:56378] self._wrapped = Settings(settings_module), referer: https://www.site2.com/
[Mon Nov 07 23:27:29.701212 2016] [wsgi:error] [pid 30535:tid 140472978749184] [client 92.221.32.65:56378] File "/usr/local/lib/python3.5/dist-packages/django/conf/__init__.py", line 99, in __init__, referer: https://www.site2.com/
[Mon Nov 07 23:27:29.701222 2016] [wsgi:error] [pid 30535:tid 140472978749184] [client 92.221.32.65:56378] mod = importlib.import_module(self.SETTINGS_MODULE), referer: https://www.site2.com/
[Mon Nov 07 23:27:29.701240 2016] [wsgi:error] [pid 30535:tid 140472978749184] [client 92.221.32.65:56378] File "/usr/lib/python3.5/importlib/__init__.py", line 126, in import_module, referer: https://www.site2.com/
[Mon Nov 07 23:27:29.701250 2016] [wsgi:error] [pid 30535:tid 140472978749184] [client 92.221.32.65:56378] return _bootstrap._gcd_import(name[level:], package, level), referer: https://www.site2.com/
[Mon Nov 07 23:27:29.701285 2016] [wsgi:error] [pid 30535:tid 140472978749184] [client 92.221.32.65:56378] File "<frozen importlib._bootstrap>", line 986, in _gcd_import, referer: https://www.site2.com/
[Mon Nov 07 23:27:29.701306 2016] [wsgi:error] [pid 30535:tid 140472978749184] [client 92.221.32.65:56378] File "<frozen importlib._bootstrap>", line 969, in _find_and_load, referer: https://www.site2.com/
[Mon Nov 07 23:27:29.701326 2016] [wsgi:error] [pid 30535:tid 140472978749184] [client 92.221.32.65:56378] File "<frozen importlib._bootstrap>", line 944, in _find_and_load_unlocked, referer: https://www.site2.com/
[Mon Nov 07 23:27:29.701346 2016] [wsgi:error] [pid 30535:tid 140472978749184] [client 92.221.32.65:56378] File "<frozen importlib._bootstrap>", line 222, in _call_with_frames_removed, referer: https://www.site2.com/
[Mon Nov 07 23:27:29.701366 2016] [wsgi:error] [pid 30535:tid 140472978749184] [client 92.221.32.65:56378] File "<frozen importlib._bootstrap>", line 986, in _gcd_import, referer: https://www.site2.com/
[Mon Nov 07 23:27:29.701386 2016] [wsgi:error] [pid 30535:tid 140472978749184] [client 92.221.32.65:56378] File "<frozen importlib._bootstrap>", line 969, in _find_and_load, referer: https://www.site2.com/
[Mon Nov 07 23:27:29.701405 2016] [wsgi:error] [pid 30535:tid 140472978749184] [client 92.221.32.65:56378] File "<frozen importlib._bootstrap>", line 944, in _find_and_load_unlocked, referer: https://www.site2.com/
[Mon Nov 07 23:27:29.701425 2016] [wsgi:error] [pid 30535:tid 140472978749184] [client 92.221.32.65:56378] File "<frozen importlib._bootstrap>", line 222, in _call_with_frames_removed, referer: https://www.site2.com/
[Mon Nov 07 23:27:29.701445 2016] [wsgi:error] [pid 30535:tid 140472978749184] [client 92.221.32.65:56378] File "<frozen importlib._bootstrap>", line 986, in _gcd_import, referer: https://www.site2.com/
[Mon Nov 07 23:27:29.701465 2016] [wsgi:error] [pid 30535:tid 140472978749184] [client 92.221.32.65:56378] File "<frozen importlib._bootstrap>", line 969, in _find_and_load, referer: https://www.site2.com/
[Mon Nov 07 23:27:29.701484 2016] [wsgi:error] [pid 30535:tid 140472978749184] [client 92.221.32.65:56378] File "<frozen importlib._bootstrap>", line 956, in _find_and_load_unlocked, referer: https://www.site2.com/
[Mon Nov 07 23:27:29.701523 2016] [wsgi:error] [pid 30535:tid 140472978749184] [client 92.221.32.65:56378] ImportError: No module named 'threeswords', referer: https://www.site2.com/

到目前为止,我没有尝试过(我的谷歌是紫色链接的黑暗海洋)能够为我解决这个问题。不是权限,不是组。它可以很好地导入python。我不明白是什么原因造成的。

谢谢大家。

最佳答案

你不见了WSGIProcessGroup 443 VirtualHost 中的指令条目。对于这两个请求都没有被委派给正确的 mod_wsgi 守护进程组。由于 Python 模块搜索路径被设置为守护进程组定义的一部分,因此它将无法找到您的应用程序代码。

关于Django mod_wsgi : ImportError: No module named '$myproject' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40475953/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com