Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
199 views
in Technique[技术] by (71.8m points)

python - How do I run uwsgi with virtualenv

I'm currently developing my first real python flask project and am about to set up the build server to deploy the "Latest Build" which is built on every check-in.

I have set up a startup script where I start the application using uwsgi and this part is working fine. I have recently also started using virtualenv and by doing so the packages installed are added to my project under projectnameflaskLibsite-packages.

I'm using nginx as the web server and the config looks like this:

location / { try_files $uri @graderbuild; }
location @graderbuild {
    include uwsgi_params;
    uwsgi_param UWSGI_CHDIR /usr/local/grader/build;
    uwsgi_param UWSGI_PYHOME /usr/local/grader/build;
    uwsgi_pass 127.0.0.1:3031;
}

I'm starting uwsgi using this:

exec /usr/local/bin/uwsgi --master --socket 127.0.0.1:3031
    --wsgi-file restserver.py --callable app --processes 4 --die-on-term
    --threads 2 >> /var/log/grader-build.log 2>&1

Now to where I know if I'm doing it right... currently I am deploying the entire folder to the build server. I don't want to install global python modules just to get my build to work. Right or wrong?

The error I get currently is:

ImportError: No module named flask_wtf

If I'm right, how do I configure the setup to use the virtualenv site-packages? My preferred location would be in the startup script and not in the nginx config.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Use -H to set virtualenv to python path.

uwsgi -H /path/to/your/virtualenv 

http://uwsgi-docs.readthedocs.org/en/latest/Options.html#virtualenv


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...