简体   繁体   English

django,python,postgres和Web部署

[英]django, python, postgres and web deployment

This error has been haunting me. 这个错误一直困扰着我。 I have actually developed fixes and I document it and I successfully run the server on the below IP address. 我实际上已经开发了修复程序,并记录了下来,并在以下IP地址上成功运行了服务器。 I try to reproduce my success after reinstalling the Ubuntu OS... with the same errors the same fixes won't do it anymore... now I need outside help. 重新安装Ubuntu OS后,我尝试重现我的成功...出现相同的错误,相同的修复程序不再起作用...现在我需要外部帮助。 I have combed the internet for solutions. 我已经在互联网上寻找解决方案。 I try to add django to the PYTHONPATH and it IS added but when I exit the python interpreter the appended django path disappears! 我尝试将django添加到PYTHONPATH中,并添加了它,但是当我退出python解释器时,附加的django路径消失了!

Another item of detail that may help is that my website www.doman.com/admin is directed to the django admin login screen. 另一个可能有用的详细信息是我的网站www.doman.com/admin被定向到django admin登录屏幕。 I tried to log in using username and password but it fails which makes me think django is not working properly. 我尝试使用用户名和密码登录,但失败,这使我认为django无法正常工作。

$ sudo python3 manage.py runserver 192.165.4.3:80

I get the error: 我得到错误:

Traceback (most recent call last):
File "manage.py", line 8, in <module>
from django.core.management import execute_from_command_line
ModuleNotFoundError: No module named 'django'

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "manage.py", line 14, in <module>
    ) from exc
ImportError: Couldn't import Django. Are you sure it's installed and
available on your PYTHONPATH environment variable? Did you forget to
activate a virtual environment?

Django is installed within my environment: Django已安装在我的环境中:

$ django-admin --version
2.0.6

Python path attempt: Python路径尝试:

$ PYTHONPATH=/home/kap/dev_env/lib/python3.6/site-packages/django python
Python 3.6.5 (default, Apr  1 2018, 05:46:30) 
[GCC 7.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import django
>>> sys.path
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'sys' is not defined
>>> import sys
>>> sys.path
['', '/home/kap/dev_env/lib/python3.6/site-packages/django', '/usr/lib/python36.zip', '/usr/lib/python3.6', '/usr/lib/python3.6/lib-dynload', '/home/kap/dev_env/lib/python3.6/site-packages']
>>> quit()

Immediately confirm django is added but it disappeared: 立即确认django已添加,但它消失了:

$ python3
Python 3.6.5 (default, Apr  1 2018, 05:46:30) 
[GCC 7.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> sys.path
['', '/usr/lib/python36.zip', '/usr/lib/python3.6', '/usr/lib/python3.6/lib-dynload', '/home/kap/dev_env/lib/python3.6/site-packages']

sudo bypasses your virtual-environment it runs as a root user and django is not installed in root account. sudo绕过您的虚拟环境,它以root用户身份运行,并且django未安装在root帐户中。 That is why it is throwing error .you can run without sudo or you can install django in your root account by 这就是为什么它会引发错误。您可以不使用sudo运行,也可以通过以下方式在您的root帐户中安装django:

sudo python3 -m pip install django

Try this: 尝试这个:

sudo python3 -m pip install django

Or if you have a requirements.txt 或者,如果您有requirements.txt

sudo python3 -m pip install -r requirements.txt

It is better to manage port 80 by nginx. 最好通过nginx管理端口80。

I actually solved it before anyone posted: 在有人发布之前,我实际上已经解决了它:

`pip install django`     

is what I used. 是我用的 More specifically I used 'pip install django psycopg2 and gunicorn' since installing all three together seemed to fix another issue. 更具体地说,我使用了“ pip install django psycopg2和gunicorn”,因为将这三个安装在一起似乎可以解决另一个问题。 I was using pip3 instead of pip. 我使用的是pip3而不是pip。 There are so many 'sensitivities' so that the order of installation, specific flags and package versions of installations can break or make the whole thing. 有太多的“敏感性”,因此安装的顺序,特定的标志和安装的软件包版本可能会破坏整个系统。 I'm thinking of making a tutorial of the whole thing and putting a video online. 我正在考虑制作完整的教程并将视频在线。 Maybe I can set a link on this page. 也许我可以在此页面上设置一个链接。

Consider pipenv - git repo is here , with more information. 考虑pipenv -git repo在这里 ,有更多信息。 Better control of packages, ease of deployment, and better control of virtual environments. 更好地控制程序包,简化部署并更好地控制虚拟环境。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM