uwsgi + Flask + virtualenv ImportError: no module named site

前端 未结 8 679
感动是毒
感动是毒 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 07:47

    I had this problem when my homebrew updated my Python version to Python 3.7 and it stopped working. What worked for me was brew info python - that will show you all your available Python versions. Than I rolled back to Python 3.6.5 using brew switch python 3.6.5.

    After that I simply reinstalled my uWSGI using:

    pip3 uninstall uwsgi
    pip3 install uwsgi
    

    And that solved it. If you're not sure what version of Python you were using, brew info python shows you the install dates. Also, you can check using pip3 list if your uWSGI is installed for the current version.

    Hope this helps!

    0 讨论(0)
  • 2021-02-05 07:50

    I had the similar issue before. My problem is that I have both python2.x and python3.x on my ubuntu system, and I want my project to run in a virtual env in which python3 environment is installed. How I resolved this issue:

    apt-get install python3-pip

    pip3 install uWSGI

    That's all.

    0 讨论(0)
  • 2021-02-05 07:50

    If your virtual environment is running on Python3 then you must install uwsgi using pip3, not pip otherwise, version mismatch will create this import problem

    pip uninstall uwsgi    
    pip3 install uwsgi
    
    0 讨论(0)
  • 2021-02-05 07:55

    The path to your virtual environment is wrong. That's the reason for this error.

    I'm using virtualenvwrapper and my virtual environments are set at ~/.virtualenvs. So in my case, the uwsgi call would look something like

    sudo uwsgi -s /tmp/uwsgi.sock -w myapp:app -H ~/.virtualenvs/myapp
    

    Hope this helps next time someone comes looking for this one.

    Thanks to Cody for pointing it out in the comments.

    0 讨论(0)
  • 2021-02-05 07:58

    THIS MAY BE BAD FOR SECURITY FOR SEVERAL REASONS. IT WORKS FOR TESTING. BUT REVIEW FOR SECURITY BEFORE USING THIS EXACT SOLUTION IN PRODUCTION

    Another reason this error may occur is permissions related. If using an .ini file as described in the official tutorial for uWSGI for django, you may have created the ini file with a user and group that makes the file inaccessible to the user that's running the process.

    Check the owner and permissions for the file and the directory path it's in. Use chown and chmod to set the needed permissions.

    sudo chown -R www-data:www-data /srv

    sudo chmod 0775 -R /srv

    In my case, I was using a vagrant box for testing and the default user is "vagrant" while nginx is using www-data for the user and group. I have set the owner of all of the files in the project to the www-data user and group and added the vagrant user to the www-data group.

    sudo gpasswd -a vagrant www-data

    I'm not sure if this is good security practice, so I'll be working with my system admin when the time comes to put it in production. But for my test environment it works. Either way, permissions will be something to look closely at for many of these issues.

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

    I encountered the same and my problem was with the python version where uwsgi was running. uwsgi was running on python2 yet my virtualenv python path was set to python3. This created the conflict, it kept on failing to locate the installed site package.

    Double check the python version where uwsgi is running so that it is the same as that set on your virtualenv.

    0 讨论(0)
提交回复
热议问题