创建virtualenv会拒绝权限

时间:2018-01-22 16:43:52

标签: python virtualenv

我正在尝试创建virtualenv,但我收到了Permission denied错误。我使用以下代码

python2.7 -m virtualenv -p `which python2.7` test

提供此错误消息:

- 编辑 -

我收到了权限被拒绝错误

Traceback (most recent call last):
  File "/home/marco/.local/lib/python2.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 "/home/marco/.local/lib/python2.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 "/home/marco/.local/lib/python2.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 "/home/marco/.local/lib/python2.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 "/home/marco/.local/lib/python2.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 "/home/marco/.local/lib/python2.7/site-packages/virtualenv_support/pip-9.0.1-py2.py3-none-any.whl/pip/wheel.py", line 345, in move_wheel_files
    clobber(source, lib_dir, True)
  File "/home/marco/.local/lib/python2.7/site-packages/virtualenv_support/pip-9.0.1-py2.py3-none-any.whl/pip/wheel.py", line 287, in clobber
    ensure_dir(dest)  # common for the 'include' path
  File "/home/marco/.local/lib/python2.7/site-packages/virtualenv_support/pip-9.0.1-py2.py3-none-any.whl/pip/utils/__init__.py", line 83, in ensure_dir
    os.makedirs(path)
  File "/home/marco/development/openplus/lambda/resizeTestSam/test/lib/python2.7/os.py", line 152, in makedirs
    makedirs(head, mode)
  File "/home/marco/development/openplus/lambda/resizeTestSam/test/lib/python2.7/os.py", line 159, in makedirs
    mkdir(name, mode)
OSError: [Errno 13] Permission denied: '/lib/python2.7'

并且操作失败的最终错误

...Installing setuptools, pip, wheel...done.
Traceback (most recent call last):
  File "/home/marco/.local/lib/python2.7/site-packages/virtualenv.py", line 2328, in <module>
    main()
  File "/home/marco/.local/lib/python2.7/site-packages/virtualenv.py", line 713, in main
    symlink=options.symlink)
  File "/home/marco/.local/lib/python2.7/site-packages/virtualenv.py", line 945, in create_environment
    download=download,
  File "/home/marco/.local/lib/python2.7/site-packages/virtualenv.py", line 901, in install_wheel
    call_subprocess(cmd, show_stdout=False, extra_env=env, stdin=SCRIPT)
  File "/home/marco/.local/lib/python2.7/site-packages/virtualenv.py", line 797, in call_subprocess
    % (cmd_desc, proc.returncode))
OSError: Command /home/marco/developm...m/test/bin/python2.7 - setuptools pip wheel failed with error code 2

为了调试os.py中的错误,我添加了一个print语句,看起来脚本试图创建目录/lib/python2.7 and /lib/python2.7/site-packages。我不明白为什么virtualenv尝试在那里创建这些目录而不是在我当前的目录中。

我已经安装了没有sudo的virtualenv,所以我不希望它在root拥有的路径中创建目录。

最后,只有python可执行文件被复制到&#39; test&#39;目录,但不是setuptools,pip和wheel。

有没有办法避免virtualenv访问root拥有的目录?

- 更新 -

使用python3与venv工作正常,问题在于virtualenv具体。

从我的主目录执行virtualenv不会出错。

2 个答案:

答案 0 :(得分:1)

您似乎正在尝试在test内创建virtualenv /lib/python2.7/site-packages,根据所有权利,您不应该拥有写访问权。

首先尝试运行cd ~,在主目录中创建venv。

答案 1 :(得分:0)

我有同样的神秘错误;事实证明我忘记了我的$ HOME / .pip / pip.conf中的一个更改前缀的设置。