[英]Apache/wsgi using wrong python version
I have two versions of python installed on ubuntu -- 3.7 and 2.7.我在 ubuntu 上安装了两个版本的 python——3.7 和 2.7。 When I add in a "normal"
sites-enabled/000-default.conf
config, it is trying to use python2.7, so it doesn't find the installed application:当我添加一个“正常”
sites-enabled/000-default.conf
配置时,它正在尝试使用 python2.7,所以它找不到已安装的应用程序:
WSGIScriptAlias / home/david/data-py/wsgi.py
<VirtualHost *:80>
<Directory /home/david/data-py>
Order allow,deny
Allow from all
Require all granted
</Directory>
</VirtualHost>
ImportError: No module named django.core.wsgi
导入错误:没有名为 django.core.wsgi 的模块
However, if I specify the python path of my project (which was created using $ virtualenv.
, and I start the file with:但是,如果我指定我的项目的 python 路径(它是使用
$ virtualenv.
创建的,并且我使用以下文件启动文件:
WSGIScriptAlias / home/david/data-py/wsgi.py
WSGIPythonHome /home/david/data-py
Then I get another error:然后我得到另一个错误:
ImportError: No module named site
导入错误:没有名为站点的模块
What does this mean and how can I get the project installed in apache/wsgi?这是什么意思,我怎样才能在 apache/wsgi 中安装项目?
I just ran into the exact same issue and it turns out I had installed the wrong version of mod_wsgi on my server (I had the one for python 2 not python 3). 我刚刚遇到了完全相同的问题,事实证明我在我的服务器上安装了错误版本的mod_wsgi(我有一个用于python 2而不是python 3)。 You can see what version apache is attempting to use if you look at the tracebacks stored in the apache error.log file (in my case /var/log/apache2/error.log) I solved it as follows (on Ubuntu):
你可以看看apache尝试使用的版本,如果你看一下存储在apache error.log文件中的回溯(在我的案例中是/var/log/apache2/error.log)我解决了它如下(在Ubuntu上):
sudo apt-get remove libapache2-mod-python libapache2-mod-wsgi
sudo apt-get install libapache2-mod-wsgi-py3
sudo service apache2 restart
Also I made sure to install the mod_wsgi package into my virtual environment (I'm not sure whether this was necessary). 另外我确保将mod_wsgi包安装到我的虚拟环境中(我不确定这是否必要)。 To do this I did the following:
为此,我做了以下事情:
cd <path to my virtual env bin folder>
sudo ./pip3 install mod_wsgi-httpd
sudo ./pip3 install mod-wsgi
I also ran into the same issue about a month ago (caused by python2 vs python3). 我也在一个月前遇到了同样的问题(由python2和python3引起)。 Here is what I recommend:
这是我的建议:
As for me, I've had to process these steps to solve the error:至于我,我不得不处理这些步骤来解决错误:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.