我将创建自己的Django Web应用程序,但我无法准备虚拟环境并安装Python包。当我在终端中执行$ virtualenv
时,我收到错误:
Traceback (most recent call last):
File "/usr/bin/virtualenv", line 6, in <module>
from pkg_resources import load_entry_point
File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line 3161, in <module>
@_call_aside
File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line 3145, in _call_aside
f(*args, **kwargs)
File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line 3174, in _initialize_master_working_set
working_set = WorkingSet._build_master()
File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line 657, in _build_master
ws = cls()
File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line 650, in __init__
self.add_entry(entry)
File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line 706, in add_entry
for dist in find_distributions(entry, True):
File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line 2062, in find_on_path
for dist in factory(fullpath):
File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line 2124, in distributions_from_metadata
if len(os.listdir(path)) == 0:
PermissionError: [Errno 13] Permission denied: '/usr/local/lib/python3.6/dist-packages/pytz-2017.3.dist-info'
$ pip
命令的结果:
Traceback (most recent call last):
File "/usr/bin/pip", line 9, in <module>
from pip import main
File "/usr/lib/python2.7/dist-packages/pip/__init__.py", line 21, in <module>
from pip._vendor.requests.packages.urllib3.exceptions import DependencyWarning
File "/usr/lib/python2.7/dist-packages/pip/_vendor/__init__.py", line 76, in <module>
vendored("pkg_resources")
File "/usr/lib/python2.7/dist-packages/pip/_vendor/__init__.py", line 36, in vendored
__import__(modulename, globals(), locals(), level=0)
File "/usr/share/python-wheels/pkg_resources-0.0.0-py2.py3-none-any.whl/pkg_resources/__init__.py", line 3019, in <module>
File "/usr/share/python-wheels/pkg_resources-0.0.0-py2.py3-none-any.whl/pkg_resources/__init__.py", line 3003, in _call_aside
File "/usr/share/python-wheels/pkg_resources-0.0.0-py2.py3-none-any.whl/pkg_resources/__init__.py", line 3032, in _initialize_master_working_set
File "/usr/share/python-wheels/pkg_resources-0.0.0-py2.py3-none-any.whl/pkg_resources/__init__.py", line 646, in _build_master
File "/usr/share/python-wheels/pkg_resources-0.0.0-py2.py3-none-any.whl/pkg_resources/__init__.py", line 639, in __init__
File "/usr/share/python-wheels/pkg_resources-0.0.0-py2.py3-none-any.whl/pkg_resources/__init__.py", line 695, in add_entry
File "/usr/share/python-wheels/pkg_resources-0.0.0-py2.py3-none-any.whl/pkg_resources/__init__.py", line 2012, in find_on_path
OSError: [Errno 13] Permission denied: '/usr/local/lib/python2.7/dist-packages/pytz-2017.3.dist-info'
和$ pip3
命令:
Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/pip/_vendor/__init__.py", line 33, in vendored
__import__(vendored_name, globals(), locals(), level=0)
ModuleNotFoundError: No module named 'pip._vendor.pkg_resources'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/bin/pip3", line 9, in <module>
from pip import main
File "/usr/lib/python3/dist-packages/pip/__init__.py", line 21, in <module>
from pip._vendor.requests.packages.urllib3.exceptions import DependencyWarning
File "/usr/lib/python3/dist-packages/pip/_vendor/__init__.py", line 76, in <module>
vendored("pkg_resources")
File "/usr/lib/python3/dist-packages/pip/_vendor/__init__.py", line 36, in vendored
__import__(modulename, globals(), locals(), level=0)
File "<frozen importlib._bootstrap>", line 971, in _find_and_load
File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 656, in _load_unlocked
File "<frozen importlib._bootstrap>", line 626, in _load_backward_compatible
File "/usr/share/python-wheels/pkg_resources-0.0.0-py2.py3-none-any.whl/pkg_resources/__init__.py", line 3019, in <module>
File "/usr/share/python-wheels/pkg_resources-0.0.0-py2.py3-none-any.whl/pkg_resources/__init__.py", line 3003, in _call_aside
File "/usr/share/python-wheels/pkg_resources-0.0.0-py2.py3-none-any.whl/pkg_resources/__init__.py", line 3032, in _initialize_master_working_set
File "/usr/share/python-wheels/pkg_resources-0.0.0-py2.py3-none-any.whl/pkg_resources/__init__.py", line 646, in _build_master
File "/usr/share/python-wheels/pkg_resources-0.0.0-py2.py3-none-any.whl/pkg_resources/__init__.py", line 639, in __init__
File "/usr/share/python-wheels/pkg_resources-0.0.0-py2.py3-none-any.whl/pkg_resources/__init__.py", line 695, in add_entry
File "/usr/share/python-wheels/pkg_resources-0.0.0-py2.py3-none-any.whl/pkg_resources/__init__.py", line 2012, in find_on_path
PermissionError: [Errno 13] Permission denied: '/usr/local/lib/python3.6/dist-packages/pytz-2017.3.dist-info'
以root身份运行的 virtualenv
,pip
,pip3
似乎正在运行。我正在进行Debian 9测试。
任何人都可以帮助我吗?
答案 0 :(得分:1)
请勿使用{
"_id": "59f372389f89d1cb0dbabdbad",
"residence": "Katowice, Poland",
"orientation": "Bisexual",
"lastName": "Kowalczyk",
"job": "Web Developer @ Freelance",
"gender": "Female",
"firstName": "Marina",
"dob": "7/10/1998",
"about": "Computer science student",
"lastConnection": "2017-11-24T19:16:28.780Z",
"created_at": "2017-10-27T20:55:06.070Z",
"phone": {
"number": "7183173136"
},
"profilePicture": {
"url": "https://.JPG",
"pictureType": ".JPG"
},
"interests": [
"Sports",
"Food",
"Cycling",
"Running",
"Cooking",
"Movies",
"Fashion",
"Business",
"Travel",
"Music",
"Theatre",
"Yoga",
"Party",
"Dancing",
"Reading"
],
"__v": 38}
。你真的不需要它。
以下是如何在虚拟环境中使用Django(强烈推荐)。
{
"_id": "59a83258c7fd5b4ae586c53b",
"visibilityLocation": true,
"visibilityGenderPreferences": true,
"visibilityFb": false,
"visibilityDistance": false,
"visibilityAge": false,
"showMyProfileAs": "Male",
"showMe": "Males",
"locationAccuracy": 0,
"accountId": "59f372389f89d1cb0dbabdbad",
"created_at": "2017-08-31T13:29:42.462Z",
"distance": {
"max": 30,
"metrics": "K",
"min": 0
},
"ageRange": {
"max": 32,
"min": 18
},
"__v": 0}
:root
myproj
mkdir myproj && cd myproj
python -mvenv venv
你很高兴。
请记住每次需要使用此项目时都要激活虚拟环境。
也就是说,每次打开一个新的shell来使用这个项目时,
. venv/bin/activate
pip install django
再次使用cd
再次运行激活脚本。
虚拟环境在当前shell中保持活动状态,
所以你不需要在每次操作之前重新运行,
你只需要在每个新shell中运行一次。