我正在跟随digitalocean.com的教程使用nginx和gunicorn部署python django应用程序,但是gunicorn指向我的旧应用程序python路径,而不是实际路径。
我用来部署应用程序的教程链接: https://www.digitalocean.com/community/tutorials/how-to-set-up-django-with-postgres-nginx-and-gunicorn-on-ubuntu-16-04。
运行命令sudo journalctl -u gunicorn
后出现错误:
Apr 05 19:35:15 szymon-MS-7B86 gunicorn[9375]: Traceback (most recent call last):
Apr 05 19:35:15 szymon-MS-7B86 gunicorn[9375]: File "/home/szymon/Desktop/digital_ocean/myprojectenv/local/lib/python2.7/site-packages/gunicorn/arbiter.py", l
Apr 05 19:35:15 szymon-MS-7B86 gunicorn[9375]: worker.init_process()
Apr 05 19:35:15 szymon-MS-7B86 gunicorn[9375]: File "/home/szymon/Desktop/digital_ocean/myprojectenv/local/lib/python2.7/site-packages/gunicorn/workers/base.p
Apr 05 19:35:15 szymon-MS-7B86 gunicorn[9375]: self.load_wsgi()
Apr 05 19:35:15 szymon-MS-7B86 gunicorn[9375]: File "/home/szymon/Desktop/digital_ocean/myprojectenv/local/lib/python2.7/site-packages/gunicorn/workers/base.p
Apr 05 19:35:15 szymon-MS-7B86 gunicorn[9375]: self.wsgi = self.app.wsgi()
Apr 05 19:35:15 szymon-MS-7B86 gunicorn[9375]: File "/home/szymon/Desktop/digital_ocean/myprojectenv/local/lib/python2.7/site-packages/gunicorn/app/base.py",
Apr 05 19:35:15 szymon-MS-7B86 gunicorn[9375]: self.callable = self.load()
Apr 05 19:35:15 szymon-MS-7B86 gunicorn[9375]: File "/home/szymon/Desktop/digital_ocean/myprojectenv/local/lib/python2.7/site-packages/gunicorn/app/wsgiapp.py
Apr 05 19:35:15 szymon-MS-7B86 gunicorn[9375]: return self.load_wsgiapp()
Apr 05 19:35:15 szymon-MS-7B86 gunicorn[9375]: File "/home/szymon/Desktop/digital_ocean/myprojectenv/local/lib/python2.7/site-packages/gunicorn/app/wsgiapp.py
Apr 05 19:35:15 szymon-MS-7B86 gunicorn[9375]: return util.import_app(self.app_uri)
Apr 05 19:35:15 szymon-MS-7B86 gunicorn[9375]: File "/home/szymon/Desktop/digital_ocean/myprojectenv/local/lib/python2.7/site-packages/gunicorn/util.py", line
Apr 05 19:35:15 szymon-MS-7B86 gunicorn[9375]: __import__(module)
Apr 05 19:35:15 szymon-MS-7B86 gunicorn[9375]: ImportError: No module named myproject.wsgi
我实际的申请路径为:/home/szymon/digital_ocean/myprojectenv
我尝试了此命令
PYTHONPATH=`pwd`/.. gunicorn --bind 0.0.0.0:8000 myproject.wsgi:application
但它不能解决问题。
重新启动Gunicorn甚至重新安装也无法解决问题。
我希望有人可以提供解决方案来为gunicorn更新python路径。 我正在运行linux mint 19。