gpt4 book ai didi

python - django、python、postgres 和 web 部署

转载 作者:行者123 更新时间:2023-12-04 19:12:21 28 4
gpt4 key购买 nike

这个错误一直困扰着我。我实际上已经开发了修复程序并记录了它,并且我成功地在以下 IP 地址上运行了服务器。重新安装 Ubuntu 操作系统后,我尝试重现我的成功......同样的错误相同的修复将不再这样做......现在我需要外部帮助。我已经在互联网上梳理了解决方案。我尝试将 django 添加到 PYTHONPATH 并添加了它,但是当我退出 python 解释器时,附加的 django 路径消失了!

另一个可能有帮助的细节是我的网站 www.doman.com/admin 被定向到 django admin 登录屏幕。我尝试使用用户名和密码登录,但失败了,这让我认为 django 无法正常工作。

$ sudo python3 manage.py runserver 192.165.4.3:80

我得到错误:
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 安装在我的环境中:
$ django-admin --version
2.0.6

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()

立即确认 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 绕过它以 root 用户身份运行的虚拟环境,并且 django 未安装在 root 帐户中。这就是它抛出错误的原因。你可以在没有 sudo 的情况下运行,或者你可以在你的 root 帐户中安装 django
sudo python3 -m pip install django

关于python - django、python、postgres 和 web 部署,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50867705/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com