[PYTHON] Django, nginx, uWSGI, virtualenv ImportError: No module named site Solution Note

error

I tried to make an app with Django and finally publish it

sudo /usr/local/bin/uwsgi --ini myapp_uwsgi.ini --uid nginx --gid nginx

If you hit the command

Set PythonHome to /home/uesrname/.virtualenvs/virtualenvname
ImportError: No module named site

I get an error and it doesn't work. What a mess.

myapp_uwsgi.ini looks like this

myapp_uwsgi.ini


# myapp_uwsgi.ini file
[uwsgi]

# Django-related settings
# the base directory (full path)
chdir           = /var/www/myapp
# Django's wsgi file
module          = myapp.wsgi
# the virtualenv (full path)
#home            = /usr/local/bin/virtualenv
home            = /home/username/.virtualenvs/virtualenvname

# process-related settings
# master
master          = true
# maximum number of worker processes
processes       = 10
# the socket (use the full path to be safe
socket          = /tmp/myapp.sock
# ... with appropriate permissions - may be needed
 chmod-socket    = 666
# clear environment on exit
vacuum          = true

By the way, without sudo

/usr/local/bin/uwsgi --ini myapp_uwsgi.ini --uid nginx --gid nginx

If so, it worked without problems, so the mystery just deepened. By the way, the OS is CentOS 6.9.

Solution

It seemed to be a permissions issue and it worked when I changed the permissions on / home / username from 700 to 755. I'm not sure why it doesn't work even though it's sudo. Is it a linux kernel permission or credential issue?

Supplement

The same error, No module named site, seems to have various symptoms, so I couldn't find a pinpoint solution. If it helps someone.

Recommended Posts

Django, nginx, uWSGI, virtualenv ImportError: No module named site Solution Note
Django / Apache / mod_wsgi: No module named importlib
Solution for "Import Error: No module named requests"
python> import seiral> ImportError: No module named serial
Resolve No module named tkinter
[Solved] ImportError: No module named pyexpat and pyenv install is moss
python / netCDF / CentOS 6.8> ImportError: No module named netCDF4> sudo yum install netcdf4-python.x86_64
'lambda_function': No module named When'selenium' appears
Wall to put OpenCV 3.1.0 in raspberry pi 3 and run sample on python3: ImportError: No module named cv2 solution