我想只在全球范围内安装Gunicorn(apt-get gunicorn3
,Ubuntu 18.04),但可以识别由pipenv
管理的虚拟环境。
这行得通-本地军用炸药:
# install dependencies from requirements.txt
$ pipenv install
# add local gunicorn
$ pipenv install gunicorn
# run the app, using local gunicorn
$ gunicorn my-site.wsgi:application
这不起作用,那是我真正需要的:
# install dependencies from requirements.txt
$ pipenv install
# activate the virtual environment
$ pipenv shell
# run the app, using global gunicorn
$ gunicorn3 my-site.wsgi:application
Error:
[2020-03-18 17:04:31 +0000] [33871] [ERROR] Exception in worker process
Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/gunicorn/arbiter.py", line 578, in spawn_worker
worker.init_process()
File "/usr/lib/python3/dist-packages/gunicorn/workers/base.py", line 126, in init_process
self.load_wsgi()
File "/usr/lib/python3/dist-packages/gunicorn/workers/base.py", line 135, in load_wsgi
self.wsgi = self.app.wsgi()
File "/usr/lib/python3/dist-packages/gunicorn/app/base.py", line 67, in wsgi
self.callable = self.load()
File "/usr/lib/python3/dist-packages/gunicorn/app/wsgiapp.py", line 65, in load
return self.load_wsgiapp()
File "/usr/lib/python3/dist-packages/gunicorn/app/wsgiapp.py", line 52, in load_wsgiapp
return util.import_app(self.app_uri)
File "/usr/lib/python3/dist-packages/gunicorn/util.py", line 377, in import_app
__import__(module)
File "/home/user/my-app/my-site/wsgi.py", line 10, in <module>
from django.core.wsgi import get_wsgi_application
ModuleNotFoundError: No module named 'django'
[2020-03-18 17:04:31 +0000] [33871] [INFO] Worker exiting (pid: 33871)
由于我在同一服务器上有多个python应用程序,并且其中一些不能修改为需要使用gunicorn,因此能够在全球范围内运行gunicorn3并使用pipenv
启动多个应用程序将非常方便
我想在全球范围内运行gunicorn但仍然加载虚拟环境中安装的软件包时会丢失什么?
答案 0 :(得分:1)
运行
pipenv run gunicorn my-site.wsgi:application
代替
gunicorn my-site.wsgi:application