在Python Mac OSX中执行virtualenv venv时出现IOError

时间:2017-02-22 10:07:01

标签: python macos virtualenv

每当我virtualenv venv时,我都会收到以下错误。我已通过sudo pip install --user virtualenv

安装了virtualenv
New python executable in /Users/rajrohit/Desktop/Work/LambdaAnsible/TestLambda/venv/bin/python
Please make sure you remove any previous custom paths from your /Users/rajrohit/.pydistutils.cfg file.
Installing setuptools, pip, wheel...
  Complete output from command /Users/rajrohit/Desk...mbda/venv/bin/python - setuptools pip wheel:
  Collecting setuptools
  Using cached setuptools-34.2.0-py2.py3-none-any.whl
Collecting pip
Collecting wheel
Collecting packaging>=16.8 (from setuptools)
  Using cached packaging-16.8-py2.py3-none-any.whl
Collecting appdirs>=1.4.0 (from setuptools)
  Using cached appdirs-1.4.0-py2.py3-none-any.whl
Collecting six>=1.6.0 (from setuptools)
  Using cached six-1.10.0-py2.py3-none-any.whl
Collecting pyparsing (from packaging>=16.8->setuptools)
  Using cached pyparsing-2.1.10-py2.py3-none-any.whl
Installing collected packages: six, pyparsing, packaging, appdirs, setuptools, pip, wheel
Exception:
Traceback (most recent call last):
  File "/Library/Python/2.7/site-packages/virtualenv_support/pip-9.0.1-py2.py3-none-any.whl/pip/basecommand.py", line 215, in main
    status = self.run(options, args)
  File "/Library/Python/2.7/site-packages/virtualenv_support/pip-9.0.1-py2.py3-none-any.whl/pip/commands/install.py", line 342, in run
    prefix=options.prefix_path,
  File "/Library/Python/2.7/site-packages/virtualenv_support/pip-9.0.1-py2.py3-none-any.whl/pip/req/req_set.py", line 784, in install
    **kwargs
  File "/Library/Python/2.7/site-packages/virtualenv_support/pip-9.0.1-py2.py3-none-any.whl/pip/req/req_install.py", line 851, in install
    self.move_wheel_files(self.source_dir, root=root, prefix=prefix)
  File "/Library/Python/2.7/site-packages/virtualenv_support/pip-9.0.1-py2.py3-none-any.whl/pip/req/req_install.py", line 1064, in move_wheel_files
    isolated=self.isolated,
  File "/Library/Python/2.7/site-packages/virtualenv_support/pip-9.0.1-py2.py3-none-any.whl/pip/wheel.py", line 478, in move_wheel_files
    generated.extend(maker.make(spec))
  File "/Library/Python/2.7/site-packages/virtualenv_support/pip-9.0.1-py2.py3-none-any.whl/pip/_vendor/distlib/scripts.py", line 372, in make
    self._make_script(entry, filenames, options=options)
  File "/Library/Python/2.7/site-packages/virtualenv_support/pip-9.0.1-py2.py3-none-any.whl/pip/_vendor/distlib/scripts.py", line 276, in _make_script
    self._write_script(scriptnames, shebang, script, filenames, ext)
  File "/Library/Python/2.7/site-packages/virtualenv_support/pip-9.0.1-py2.py3-none-any.whl/pip/_vendor/distlib/scripts.py", line 250, in _write_script
    self._fileop.write_binary_file(outname, script_bytes)
  File "/Library/Python/2.7/site-packages/virtualenv_support/pip-9.0.1-py2.py3-none-any.whl/pip/_vendor/distlib/util.py", line 407, in write_binary_file
    with open(path, 'wb') as f:
IOError: [Errno 1] Operation not permitted: '/bin/easy_install'
----------------------------------------
...Installing setuptools, pip, wheel...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 713, in main
    symlink=options.symlink)
  File "/Library/Python/2.7/site-packages/virtualenv.py", line 945, in create_environment
    download=download,
  File "/Library/Python/2.7/site-packages/virtualenv.py", line 901, in install_wheel
    call_subprocess(cmd, show_stdout=False, extra_env=env, stdin=SCRIPT)
  File "/Library/Python/2.7/site-packages/virtualenv.py", line 797, in call_subprocess
    % (cmd_desc, proc.returncode))
OSError: Command /Users/rajrohit/Desk...mbda/venv/bin/python - setuptools pip wheel failed with error code 2

如何使用此权限错误,并使virtualenv正常工作?

2 个答案:

答案 0 :(得分:0)

在运行/修改默认的OSX python解释器时,我总是遇到权限问题。目前我使用PyEnv(https://github.com/yyuu/pyenv)安装单独的用户可修改的python解释器,并与pyenv-virtualenv(https://github.com/yyuu/pyenv-virtualenv)一起使用它就像一个魅力。自改变以来,我一直没有遇到任何问题。

答案 1 :(得分:0)

我最近有类似的问题设置新机器,我发现这个解决方案效果最好。 https://apple.stackexchange.com/a/209583/226131

更详细的解释包含在同一个问题中。 https://apple.stackexchange.com/a/223163/226131

TLDR:安装python brew install python的用户可修改版本,然后就可以进行安装。