uwsgi + Flask + virtualenv ImportError: no module named site

前端 未结 8 662
感动是毒
感动是毒 2021-02-05 07:37

(Other posts on SO are similar, but none have the specific combination of uwsgi + Flask + virtualenv) (This one is closest)

I installed uwsgi via apt-get. I also tried

相关标签:
8条回答
  • 2021-02-05 08:08

    See the answer from @JRajan first.

    If you're sure you just want to suppress the error and not actually solve the underlying issue, you should add --no-site to your command or no-site=true to your uwsgi.ini file.

    0 讨论(0)
  • 2021-02-05 08:11

    In my case the problem was the python version uWSGI tried to use.

    My project was written in python 3.4, but I was not specifying this in uWSGI config. So uWSGI tried to use python 2 and tried to import modules from the folder lib/python2.7 inside the virtualenv.

    So I received the 'No module named site' error, because all the modules, including the site module, where inside lib/python3.4, not lib/python2.7.

    To solve it, i had to do two things:

    • Install the python3 plugin for uWSGI, with:
      apt-get install uwsgi-plugin-python3

    • Use it in the .ini config file, with:
      plugins = python34

    Hope this helps someone with the same problem in the future.

    As requested, here follows my .ini file:

    [uwsgi]
    base = /your/app/path
    
    pythonpath = %(base)
    module = your_module_name
    
    callable = app #Here you put the name of the variable which holds your app inside your module
    
    home = /your/virtualenv/path
    plugins = python34
    
    master = true
    processes = 2
    
    uid = www-data
    gid = www-data
    
    socket = /path/to/socket
    chmod-socket = 660
    
    die-on-term = true
    
    logto = /var/log/uwsgi/%n.log
    
    0 讨论(0)
提交回复
热议问题