我尝试使用 python3-pip 安装 Django,当我运行
pip3 install Django
或者sudo pip3 install Django
它给出了这个错误信息
Traceback (most recent call last):
File "/usr/bin/pip3", line 9, in <module>
from pip import main
File "/home/amir/.local/lib/python3.5/site-packages/pip/__init__.py", line 26, in <module>
from pip.utils import get_installed_distributions, get_prog
File "/home/amir/.local/lib/python3.5/site-packages/pip/utils/__init__.py", line 27, in <module>
from pip._vendor import pkg_resources
File "/home/amir/.local/lib/python3.5/site-packages/pip/_vendor/pkg_resources/__init__.py", line 3018, in <module>
@_call_aside
File "/home/amir/.local/lib/python3.5/site-packages/pip/_vendor/pkg_resources/__init__.py", line 3004, in _call_aside
f(*args, **kwargs)
File "/home/amir/.local/lib/python3.5/site-packages/pip/_vendor/pkg_resources/__init__.py", line 3046, in _initialize_master_working_set
dist.activate(replace=False)
File "/home/amir/.local/lib/python3.5/site-packages/pip/_vendor/pkg_resources/__init__.py", line 2578, in activate
declare_namespace(pkg)
File "/home/amir/.local/lib/python3.5/site-packages/pip/_vendor/pkg_resources/__init__.py", line 2152, in declare_namespace
_handle_ns(packageName, path_item)
File "/home/amir/.local/lib/python3.5/site-packages/pip/_vendor/pkg_resources/__init__.py", line 2092, in _handle_ns
_rebuild_mod_path(path, packageName, module)
File "/home/amir/.local/lib/python3.5/site-packages/pip/_vendor/pkg_resources/__init__.py", line 2121, in _rebuild_mod_path
orig_path.sort(key=position_in_sys_path)
AttributeError: '_NamespacePath' object has no attribute 'sort'
我能做些什么?!
答案1
在 Ubuntu 16.04 及更高版本中,您不需要使用 pip3 安装 Django,因为 Django 位于默认存储库中。打开终端并输入:
sudo apt update
sudo apt install python3-django
如果您仍想使用 pip3 安装 Django,则应将 pip3 更新到最新版本,以便 pip3 能够安装 Django 及其依赖项。运行以下命令:
sudo python3 -m pip install --upgrade pip
sudo python3 -m pip install django
您可以通过输入以下命令来验证安装是否成功:
django-admin --version