首先,如果我错过了找到一个解决方案已经张贴,我道歉。我真的试着想明白了。
下面是执行的命令:“(VENV)user@server:/var/www/html/django-apps/GT 1 $ python manage.py createsuperuser
返回错误:
Traceback (most recent call last):
File "/var/www/html/django-apps/GT1/manage.py", line 11, in main
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 "/var/www/html/django-apps/GT1/manage.py", line 22, in <module>
main()
File "/var/www/html/django-apps/GT1/manage.py", line 13, in main
raise ImportError(
ImportError: Couldn't import Django. Are you sure it's installed and available on your PYTHONPATH environment variable?
虚拟环境的存在显然是因为当我尝试时它是活动的。
我已删除虚拟并尝试重新安装。当我这样做时,我得到一条消息,说django已经安装了。
这个信息是:
(VENV) darren@server:/var/www/html/django-apps$ sudo pip install django
Requirement already satisfied: django in /usr/local/lib/python3.10/dist-packages (4.2.2)
Requirement already satisfied: sqlparse>=0.3.1 in /usr/local/lib/python3.10/dist-packages (from django) (0.4.4)
Requirement already satisfied: asgiref<4,>=3.6.0 in /usr/local/lib/python3.10/dist-packages (from django) (3.7.2)
Requirement already satisfied: typing-extensions>=4 in /usr/local/lib/python3.10/dist-packages (from asgiref<4,>=3.6.0->django) (4.6.3)
WARNING: Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager. It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv
更新:这是我尝试过的。我完全卸载了django,因为它最初是使用sudo安装的,sudo将它放在默认的Python位置。现在,当我尝试将其安装到创建的虚拟环境时,它失败了。
我肯定我有一个权利问题,但不知道如何解决它。
我在/var/www下创建了一个python_envs文件夹来保存虚拟对象。然后创建VENV,它现在作为GT_Dev1存在于python_envs文件夹下。当我试图安装到venv我得到一个权限错误。
我使用sudo创建了python_envs文件夹和虚拟文件夹,因为我的用户没有var/www文件夹的权限。
我应该删除虚拟本身和envs文件夹,然后使用sudo重新创建吗?我可能真的做了,我输入了很多命令试图解决这个问题,我已经失去了跟踪。
谢谢,达伦
1条答案
按热度按时间2jcobegt1#
你想在VENV中使用Django吗?但是通过
sudo
安装了它(具有管理权限)。Python没有足够的权限。要么安装Django并拥有爬虫权限,要么通过sudo
运行manage.py