2015-02-08 207 views
7

我是Python開發新手,我試圖在項目目錄中安裝virtualenv。Virtualenv venv失敗,出現以下錯誤

不過,我有以下錯誤:

Installing collected packages: pip, setuptools 

    Exception: 
    Traceback (most recent call last): 
    File "/Library/Python/2.7/site-packages/virtualenv_support/pip-6.0.8-py2.py3-none-any.whl/pip/basecommand.py", line 232, in main 
     status = self.run(options, args) 
    File "/Library/Python/2.7/site-packages/virtualenv_support/pip-6.0.8-py2.py3-none-any.whl/pip/commands/install.py", line 347, in run 
     root=options.root_path, 
    File "/Library/Python/2.7/site-packages/virtualenv_support/pip-6.0.8-py2.py3-none-any.whl/pip/req/req_set.py", line 549, in install 
     **kwargs 
    File "/Library/Python/2.7/site-packages/virtualenv_support/pip-6.0.8-py2.py3-none-any.whl/pip/req/req_install.py", line 754, in install 
     self.move_wheel_files(self.source_dir, root=root) 
    File "/Library/Python/2.7/site-packages/virtualenv_support/pip-6.0.8-py2.py3-none-any.whl/pip/req/req_install.py", line 963, in move_wheel_files 
     isolated=self.isolated, 
    File "/Library/Python/2.7/site-packages/virtualenv_support/pip-6.0.8-py2.py3-none-any.whl/pip/wheel.py", line 234, in move_wheel_files 
     clobber(source, lib_dir, True) 
    File "/Library/Python/2.7/site-packages/virtualenv_support/pip-6.0.8-py2.py3-none-any.whl/pip/wheel.py", line 212, in clobber 
     shutil.copyfile(srcfile, destfile) 
    File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/shutil.py", line 82, in copyfile 
     with open(dst, 'wb') as fdst: 
    IOError: [Errno 13] Permission denied: '/Library/Python/2.7/site-packages/pip/__init__.py' 

---------------------------------------- 
...Installing setuptools, pip...done. 
Traceback (most recent call last): 
    File "/usr/local/bin/virtualenv", line 11, in <module> 
    sys.exit(main()) 
    File "/Library/Python/2.7/site-packages/virtualenv.py", line 825, in main 
    symlink=options.symlink) 
    File "/Library/Python/2.7/site-packages/virtualenv.py", line 993, in create_environment 
    install_wheel(to_install, py_executable, search_dirs) 
    File "/Library/Python/2.7/site-packages/virtualenv.py", line 961, in install_wheel 
    'PIP_NO_INDEX': '1' 
    File "/Library/Python/2.7/site-packages/virtualenv.py", line 903, in call_subprocess 
    % (cmd_desc, proc.returncode)) 
OSError: Command /Users/alexandrurada...oard/venv/bin/python -c "import sys, pip; sys...d\"] + sys.argv[1:]))" setuptools pip failed with error code 2 

我安裝PIP與

easy_install pip

然後我安裝的virtualenv與

pip install virtualenv

沒有任何錯誤。不過,我仍然得到這個。我不想用sudo嘗試它。我是不是該?

更新:我安裝了sudo,我擺脫了這個錯誤。但是另外一個嘗試與PIP安裝的東西時:

air:dashboard alexandrurada$ pip install flask 

-bash:在/ usr/local/bin目錄/ PIP: 「path_here」:壞的解釋:沒有這樣的文件或目錄

更新2:之前的錯誤是因爲目錄名稱中有空格。看起來路徑不適用於這些名稱。

反正,現在我得到的錯誤是

File "/usr/local/bin/pip", line 7, in <module> 
    from pip import main 
ImportError: No module named pip 

我檢查了我的/ usr/local/bin目錄/畫中畫和文件是否存在。

+0

您是否需要特權?您可能需要運行'sudo your_cmd' – ForceBru 2015-02-08 14:45:20

回答

12

您需要sudo pip install virtualenv全球安裝virtualenv。當設置你的virtualenvs時,確保你在試圖安裝前,確保你沒有使用sudo並且你激活你的virtualenv。

[Errno 13] Permission denied:表示您沒有寫入權限。

+1

謝謝!它爲我工作。 – heloisasim 2016-02-01 02:20:38

+1

您拯救了我的一天! – 2017-10-15 04:23:52

4

安裝較新版本的pip並避免使用easy_install。

下載點子來自:https://bootstrap.pypa.io/get-pip.py

,然後在其上運行的Python:

$ python get-pip.py 

如果你想安裝pip爲全局路徑,你可能要運行使用sudo去年命令。在不使用sudo的情況下,pip將被安裝以供任何Python解釋器在您的路徑中使用。

從這裏,你可以用PIP安裝的virtualenv:

$ pip install virtualenv 

從你的反應,好像你想通過讓您的系統在已知狀態下提供最好的服務:下載該文件,然後運行sudo python get-pip.py所以你正在運行一個已知的pip安裝。

+0

請解釋downvote。 – 2015-02-08 14:53:10

+0

我這樣做後,激活venv,我得到使用哪個點(這python顯示本地一個)的全局點子路徑 – 2015-02-08 14:56:34

+0

@AlexandruRada你想完成什麼? – 2015-02-08 15:00:13

相關問題