0

I am trying to configure uswgi with nginx

The steps I followed are:

Install NGINX

sudo yum install nginx
sudo /etc/init.d/nginx start &

Pip

yum -y install python-pip

Install 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

pip install uwsgi

Install 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

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

/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. Is this making any difference?

3
  • What happen when you "import os" in "python manage.py shell"? And what is "Python version" printed in uwsgi's logs?
    – ZZY
    Sep 10, 2014 at 6:55
  • oh it is different 2.6.9 Sep 10, 2014 at 7:10
  • "import os" works fine. How I can upgrade python? Sep 10, 2014 at 7:11

1 Answer 1

1

Assume you did need all your stuff running in Python2.7. Then you may try to re-install uwsgi with Python27 support:

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, ...).
The guide also introduces virtualenv, it's a strongly recommended tool for development with 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.

3
  • Thank you :). I am done with it. Now there is another error. Set PythonHome to /usr/local/.localpython/bin/python ImportError: No module named site Do I need to set the environment variable? Sep 10, 2014 at 10:28
  • I haven't seen this error. You may try "-H ......" to set PythonHome for uwsgi. If you're using Virtualenv, the path will be under virtualenv folder. This answer mentioned about using "--no-site" parameter to solve the issue, you may also give a try: stackoverflow.com/questions/18417823/…
    – ZZY
    Sep 10, 2014 at 13:56
  • The importError means that uwsgi can't find the modules it's looking for in the virtualenv. Make sure the virtualenv path is correct. make sure the modules are in the virtualenv. Don't use the "--no-site" flag unless you aren't planning on using anything in 'site-packages'. Feb 18, 2015 at 0:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.