在Mac OS X Yosemite上使用virtualenv

时间:2015-03-14 21:46:15

标签: python macos virtualenv

我一直在努力在Mac OS X Yosemite上设置virtualenv和pip。我一直遇到同样的问题:

$ virtualenv foobar
New python executable in foobar/bin/python
Installing setuptools, pip...
  Complete output from command /Users/name/foobar/bin/python -c "import sys, pip; sys...d\"] + sys.argv[1:]))" setuptools pip:
  Ignoring indexes: https://pypi.python.org/simple
Collecting setuptools
Collecting pip
Installing collected packages: pip, setuptools

  Exception:
  Traceback (most recent call last):
    File "/Library/Python/2.7/site-packages/virtualenv-12.0.7-py2.7.egg/virtualenv_support/pip-6.0.8-py2.py3-none-any.whl/pip/basecommand.py", line 232, in main
      status = self.run(options, args)
...
"/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 9, in <module>
    load_entry_point('virtualenv==12.0.7', 'console_scripts', 'virtualenv')()
....
    OSError: Command /Users/name/foobar/bin/python -c "import sys, pip; sys...d\"] + sys.argv[1:]))" setuptools pip failed with error code 2

有谁知道造成这个问题的原因或我如何解决这个问题。我尝试了各种版本的virtualenv和pip本地/全局无效。

1 个答案:

答案 0 :(得分:1)

这可能意味着您没有在系统python环境中安装pipvirtualenv取决于pip,因此它试图提供帮助并为您安装(并且失败,因为它无法写入/Library/Python/2.7/site-packages)。

首先尝试将pip安装到系统python中(使用sudo):

$ sudo easy_install pip

之后,virtualenv应该可以在没有sudo的情况下工作。