uwsgi + Flask + virtualenv ImportError: no module named site

前端 未结 8 681
感动是毒
感动是毒 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: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.

提交回复
热议问题