[英]Django and apache2 (no virtualenv): ImportError: No module named 'django'
I'm trying to port over a small Django site from one server to another. 我试图将一个小型Django站点从一台服务器移植到另一台服务器。 On the new server, I have the following installed:
在新服务器上,我安装了以下软件:
Ubuntu 16.04.3 LTS
Python 3.5.2
apache 2.4.18
mod_wsgi 4.5.17 (built from source with Python 3.5)
django 1.11.4 (installed using pip3 **without** a virtualenv)
At the bottom of my apache2.conf file, I added the following lines 在我的apache2.conf文件的底部,添加了以下几行
# Django settings
LoadModule wsgi_module /usr/lib/apache2/modules/mod_wsgi.so
WSGIPythonPath /home/user/ProductionServer
Where /home/user/ProductionServer is the root directory of my django site. 其中/ home / user / ProductionServer是django站点的根目录。
In sites-enabled/000-default.conf, I have the following: 在sites-enabled / 000-default.conf中,我具有以下内容:
<VirtualHost *:2799>
ServerName myserver.com
ServerAdmin webmaster@localhost
DocumentRoot /var/www/html
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
WSGIScriptAlias / /home/user/ProductionServer/my_app/wsgi.py
Alias /static /home/user/ProductionServer/static
<Directory /home/user/ProductionServer/my_app>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
<Directory /home/user/ProductionServer/static>
Require all granted
</Directory>
</VirtualHost>
# vim: syntax=apache ts=4 sw=4 sts=4 sr noet
I can run the site fine using the manage.py runserver command. 我可以使用manage.py runserver命令正常运行该站点。 When I come to run it through apache, however, I got the following error message in the apache2.error file:
但是,当我通过apache运行它时,我在apache2.error文件中收到以下错误消息:
[Tue Aug 08 10:53:39.291771 2017] [mpm_event:notice] [pid 1892:tid 139862763386752] AH00489: Apache/2.4.18 (Ubuntu) mod_wsgi/4.5.17 Python/3.5 configured -- resuming normal operations
[Tue Aug 08 10:53:39.291903 2017] [core:notice] [pid 1892:tid 139862763386752] AH00094: Command line: '/usr/sbin/apache2'
[Tue Aug 08 10:53:49.966143 2017] [wsgi:error] [pid 1893:tid 139862665881344] [client 85.97.123.183:56389] mod_wsgi (pid=1893): Target WSGI script '/home/user/ProductionServer/my_app/wsgi.py' cannot be loaded as Python module.
[Tue Aug 08 10:53:49.966273 2017] [wsgi:error] [pid 1893:tid 139862665881344] [client 85.97.123.183:56389] mod_wsgi (pid=1893): Exception occurred processing WSGI script '/home/user/ProductionServer/my_app/wsgi.py'.
[Tue Aug 08 10:53:49.966521 2017] [wsgi:error] [pid 1893:tid 139862665881344] [client 85.97.123.183:56389] Traceback (most recent call last):
[Tue Aug 08 10:53:49.966584 2017] [wsgi:error] [pid 1893:tid 139862665881344] [client 85.97.123.183:56389] File "/home/user/ProductionServer/my_app/wsgi.py", line 12, in <module>
[Tue Aug 08 10:53:49.966595 2017] [wsgi:error] [pid 1893:tid 139862665881344] [client 85.97.123.183:56389] from django.core.wsgi import get_wsgi_application
[Tue Aug 08 10:53:49.966620 2017] [wsgi:error] [pid 1893:tid 139862665881344] [client 85.97.123.183:56389] ImportError: No module named 'django'
My folder structure is as follows: 我的文件夹结构如下:
ProductionServer
├── another_app
│ ├── ....
├── manage.py
├── my_app
│ ├── __init__.py
│ ├── settings.py
│ ├── urls.py
│ └── wsgi.py
└── static
└── ...
Any thoughts? 有什么想法吗?
if you use daemon mode, you can add two lines before WSGIScriptAlias
如果使用守护程序模式,则可以在
WSGIScriptAlias
之前添加两行
you can check django manual 你可以查看Django手册
example 例
WSGIDaemonProcess projectname python-path=/home/user/ProductServer/:/home/user/myvenv/lib/Python3.5/site-packages
WSGIProcessGroup projectname
WSGIScriptAlias / /home/user/ProductionServer/my_app/wsgi.py
The problem was that despite what I initially thought, pip had installed django only for my local user. 问题是,尽管我最初想到的是,pip仅为我的本地用户安装了django。 To install django globally, I had to run pip with the -H option:
要全局安装django,我必须使用-H选项运行pip:
sudo -H pip3 install django
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.