我在我的機器上的virtualenv中安裝了Django 1.10。現在,我創建另一個的virtualenv(另一個項目),並使用下面的命令就可以安裝Django的1.11:在虛擬環境中安裝Django時出現權限錯誤
pip install Django
但我得到一個權限被拒絕的錯誤:
Collecting Django
Using cached Django-1.11.5-py2.py3-none-any.whl
Requirement already satisfied: pytz in /Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages (from Django)
Installing collected packages: Django
Exception:
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/pip/basecommand.py", line 215, in main
status = self.run(options, args)
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/pip/commands/install.py", line 342, in run
prefix=options.prefix_path,
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/pip/req/req_set.py", line 784, in install
**kwargs
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/pip/req/req_install.py", line 851, in install
self.move_wheel_files(self.source_dir, root=root, prefix=prefix)
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/pip/req/req_install.py", line 1064, in move_wheel_files
isolated=self.isolated,
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/pip/wheel.py", line 377, in move_wheel_files
clobber(source, dest, False, fixer=fixer, filter=filter)
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/pip/wheel.py", line 323, in clobber
shutil.copyfile(srcfile, destfile)
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/shutil.py", line 115, in copyfile
with open(dst, 'wb') as fdst:
PermissionError: [Errno 13] Permission denied: '/Library/Frameworks/Python.framework/Versions/3.5/bin/__pycache__/django-admin.cpython-35.pyc'
我已閱讀多個SO帖子關於這個,但他們的解決方案似乎並不適用於我。請注意:
1)我有已經激活新的virtualenv運行命令之前。
2)I 沒有使用sudo創建新的virtualenv。我只是做了以下內容來創建它:
virtualenv name-of-the-new-virtualenv
什麼可能我會丟失?
什麼是運行的結果在你嘗試安裝Django的virtualenv之後是哪個pip和'哪個python'?另外,你的VIRTUAL_ENV和PATH看起來像什麼('echo「$ VIRTUAL_ENV」'和'echo「$ PATH」')? –
布蘭登,你解決了這個問題。 '哪個pip'和'哪個python'返回系統路徑而不是virtualenv路徑。然後'echo「$ VIRTUAL_ENV」'返回了一條不存在的路徑!我實際上已經將virtualenv目錄從項目目錄移到了主目錄,以便將所有的virtualenv目錄保留在同一個地方(我認爲我讀了某處可以移動它們的地方,但看起來這不是個好主意)。我把它移回來,它工作得很好。隨時寫一個答案,所以我可以給你信用 – Anupam
太棒了!很高興幫助。我回答了一些有關virtualenvs的其他一般信息,以幫助未來的旁觀者。 –