Virtualenv venv失败,出现以下错误

时间:2015-02-08 14:42:57

标签: python pip virtualenv

我是Python开发的新手,我试图在我的项目目录中安装virtualenv。

但是我有以下错误:

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:&#34; path_here&#34;:错误的解释器:没有这样的文件或目录

更新2:之前的错误是由于目录名称中的空格。看起来路径并没有使用这些名称。

无论如何,我现在得到的错误是

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

我检查了我的/ usr / local / bin / pip,文件存在。

2 个答案:

答案 0 :(得分:13)

您需要sudo pip install virtualenv全局安装virtualenv。在设置virtualenvs时,请确保使用sudo,并在尝试安装之前激活您的virtualenv。

[Errno 13] Permission denied:表示您没有写入权限。

答案 1 :(得分: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安装运行。< / p>