Flask+Nginx+uWSGI : ImportError: No module named site

情到浓时终转凉″ 提交于 2019-12-07 06:47:52

问题


I installed as the http://www.reinbach.com/uwsgi-nginx-flask-virtualenv-mac-os-x.html link's tutorial and when executing the command uwsgi --ini deploy/deploy.ini, the terminal says there was an import error:

Set PYTHONHOME to /virtualenv/sample/

ImportError: No module named site

I have set my PYTHONHOME and PYTHONPATH as

export PYTHONPATH=$PYTHONPATH:/Library/Python/2.7/site-packages
export PYTHONHOME=$PYTHONHOME:/Library/Python/2.7

I cannot figure out what wrong with it.

Could someone help me with the problem?

The whole info in the terminal is shown as below if it is helpful:

(env)ios-devmatoMacBook-Pro:hello ios_dev$ uwsgi --ini deploy/deploy.ini
[uWSGI] getting INI configuration from deploy/deploy.ini
*** Starting uWSGI 1.9.10 (64bit) on [Fri May 17 16:42:22 2013] ***
compiled with version: 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2336.11.00) on 17 May 2013 12:41:07
os: Darwin-11.4.2 Darwin Kernel Version 11.4.2: Thu Aug 23 16:25:48 PDT 2012; root:xnu-
1699.32.7~1/RELEASE_X86_64
nodename: ios-devmatoMacBook-Pro.local
machine: x86_64
clock source: unix
detected number of CPU cores: 4
current working directory: /Users/ios_dev/Desktop/sample/hello
detected binary path: /Users/ios_dev/Documents/little/little-web/little_web_dev/env/bin/uwsgi
your processes number limit is 709
your memory page size is 4096 bytes
detected max file descriptor number: 256
lock engine: OSX spinlocks
uwsgi socket 0 bound to TCP address 127.0.0.1:3031 fd 3
Python version: 2.7.1 (r271:86832, Jun 16 2011, 16:59:05)  [GCC 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2335.15.00)]

Set PYTHONHOME to /virtualenv/sample/

ImportError: No module named site

回答1:


Here's how I resolved the same error message (ImportError: No module named site) that I got while trying the Django and NGINX tutorial — uWSGI 2.0 documentation.

Deactivate the virtualenv:

deactivate

Install uWSGI system-wide (if not already installed system-wide)

sudo pip install uwsgi

Edit the uwsgi.ini file. I commented out the line with the:

home = /path/to/virtualenv

Run uWSGI --ini mysite_uwsgi.ini.




回答2:


I read a lot of document about the question, but get no answer.

By coincidentally, I fix this problem by edit uid and gid as root.

It seem like a permissions problem. I don't know why, but it just work. Remember, it is very unsafe to run a product environment as root.




回答3:


1、active the virtual you used

2、 pip install uwsgi

this the key action,then the

command -v wsgi

show this

/virtual-path/bin/uwsgi

3、use current user to run uwsgi, because other user is not active the virtualenv




回答4:


Im My case I wasn't using virtualEnv. Just using django + ngnix. My solution was removing HOME variable into the *.ini configuration file:

sudo nano /etc/uwsgi/sites/c_app.ini

[uwsgi]
    project = c_app
    uid = ubuntu
    base = /home/%(uid)

    chdir = %(base)/%(project)
    **home = %(base)/%(project)** (REMOVED IT)
    module = %(project).wsgi:application

    master = true
    processes = 5

    socket = /run/uwsgi/%(project).sock
    chown-socket = %(uid):www-data
    chmod-socket = 660
    vacuum = true

then it works.



来源:https://stackoverflow.com/questions/16605048/flasknginxuwsgi-importerror-no-module-named-site

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!