[英]ImportError: No module named os uwsgi + django + linux
I am trying to configure uswgi with nginx 我正在尝试使用Nginx配置uswgi
The steps I followed are: 我遵循的步骤是:
Install NGINX 安装NGINX
sudo yum install nginx
sudo /etc/init.d/nginx start &
Pip 果仁
yum -y install python-pip
Install Python 安装Python
wget http://www.python.org/ftp/python/2.7.6/Python-2.7.6.tgz
tar -xzf Python-2.7.6.tgz
cd Python-2.7.6
./configure
make
sudo make install
Install Uwsgi 安装Uwsgi
pip install uwsgi
Install Django 安装Django
sudo pip install git+https://github.com/django-nonrel/django
Command 命令
uwsgi --socket /tmp/wsgi.sock --module App.wsgi:application --chmod-socket=666 -H /usr/local/bin/python --master --processes 4 --threads 2 &
Error 错误
"wsgi.py", line 10, in <module>
import os
ImportError: No module named os
unable to load app 0 (mountpoint='') (callable not found or import error)
wsgi.py content wsgi.py内容
10: import os
11: os.environ.setdefault("DJANGO_SETTINGS_MODULE", "SecurityInsights.settings")
12:
13: from django.core.wsgi import get_wsgi_application
14: application = get_wsgi_application()
And there is no problem while loading os module in console 并且在控制台中加载os模块时没有问题
/usr/local/bin/python
Python 2.7.6 (default, Sep 9 2014, 18:55:35)
[GCC 4.8.2 20131212 (Red Hat 4.8.2-7)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import os
>>>
EDIT 编辑
as per @ZZY suggesstion I checked the python version in python manage.py shell
, it is different 2.6.9 than global 2.7.6. 根据@ZZY的建议,我在
python manage.py shell
检查了python版本,它的2.6.9与全局2.7.6不同。 Is this making any difference? 这有什么区别吗?
Assume you did need all your stuff running in Python2.7. 假设您确实需要在Python2.7中运行所有内容。 Then you may try to re-install uwsgi with Python27 support:
然后,您可以尝试使用Python27支持重新安装uwsgi:
sudo pip uninstall uwsgi
wget http://projects.unbit.it/downloads/uwsgi-latest.tar.gz
tar zxvf uwsgi-latest.tar.gz
cd <dir>
sudo python2.7 uwsgiconfig.py --plugin plugins/python core python27
make
Another possible solution: follow this guide to install pip2.7, then use pip2.7 to install everything (uwsgi, Django, ...). 另一个可能的解决方案:按照本指南安装pip2.7,然后使用pip2.7安装所有内容(uwsgi,Django等)。
The guide also introduces virtualenv , it's a strongly recommended tool for development with Python. 该指南还介绍了virtualenv ,它是强烈建议使用Python开发的工具。 As the name indicates, it creates separate "python package spaces", so you can have different versions of Django or any Python packages in a computer, for different projects.
顾名思义,它创建了单独的“ python软件包空间”,因此对于不同的项目,您可以在计算机中使用不同版本的Django或任何Python软件包。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.