简体   繁体   English

Django和apache2(无virtualenv):ImportError:没有名为“ django”的模块

[英]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.

相关问题 VirtualEnv apache2服务器没有名为“ django”的模块 - VirtualEnv apache2 server No module named 'django' Apache virtualenv和mod_wsgi:ImportError:没有名为&#39;django&#39;的模块 - Apache virtualenv and mod_wsgi : ImportError : No module named 'django' Django + mod_wsgi + apache2:ImportError:未命名模块<project> - Django + mod_wsgi + apache2: ImportError: No module named <project> ImportError:在virtualenv中没有名为“ django”的模块 - ImportError: No module named 'django' when in virtualenv Apache ImportError:没有名为“ django”的模块 - Apache ImportError: No module named 'django' Apache2 和 Django - [wsgi:error] ImportError: cannot import name 'get_version' -&gt; No module named 'django' - Apache2 and Django - [wsgi:error] ImportError: cannot import name 'get_version' -> No module named 'django' Django+Apache | 导入错误:没有名为 django 的模块 - Django+Apache | ImportError: No Module named django Django,Python 3.4,CentOS 6.4,virtualenv:ImportError:没有名为Django的模块 - Django, Python 3.4, CentOS 6.4, virtualenv: ImportError: No module named Django Apache WSGI没有名为django whitout virtualenv的模块 - Apache WSGI no module named django whitout virtualenv 如何解决:ImportError:Apache2日志中没有名为django.core.wsgi的模块? - How to solve: ImportError: No module named django.core.wsgi in Apache2 log?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM