尝试 python setup.py install 时 Virtualenv 权限被拒绝

尝试 python setup.py install 时 Virtualenv 权限被拒绝

我想virtualenv在 Ubuntu 18.04 上使用 Python 3。具体来说,我使用的是 Python 3.6.6 和 virtualenv 16.0.0。

  1. sudo我按照建议安装了 virtualenv在这里的答案中sudo pip3 install --upgrade virtualenv

  2. 我使用 创建了一个新的虚拟环境python3 -m virtualenv venv。并像往常一样激活它:source venv/bin/activate

  3. 当我尝试安装我的 Python 项目时python setup.py install收到以下错误消息:


    running install
    running bdist_egg
    running egg_info
    error: [Errno 13] Permission denied

如果我sudo在步骤 2 中创建虚拟环境,那么我会在步骤 3 中收到不同的错误消息:

error: can't create or remove files in install directory

The following error occurred while trying to add or remove files in the
installation directory:

    [Errno 13] Permission denied: '/home/stefan/git-repos/tng-sdk-project/venv/lib/python3.6/site-packages/test-easy-install-3769.write-test'

The installation directory you specified (via --install-dir, --prefix, or
the distutils default setting) was:

    /home/stefan/git-repos/tng-sdk-project/venv/lib/python3.6/site-packages/

Perhaps your account does not have write access to this directory?  If the
installation directory is a system-owned directory, you may need to sign in
as the administrator or "root" account.  If you do not have administrative
access to this machine, you may wish to choose a different installation
directory, preferably one that is listed in your PYTHONPATH environment
variable.

For information on other options, you may wish to consult the
documentation at:

  https://setuptools.readthedocs.io/en/latest/easy_install.html

Please make the appropriate changes for your system and try again.

我已经在 Google 上搜索并尝试了好几个小时,但还是无法正常工作。似乎无论我尝试什么都会导致更多新的错误... 有什么想法吗?

嗯,sudo python setup.py install在虚拟环境中可以工作,但这不是解决方案。

答案1

最有可能用于sudo一些创建具有 root 所有权的文件夹的指令。

  1. 停用虚拟环境。

  2. 尝试递归修复所有者:

    sudo chown -R stefan:stefan /home/stefan/git-repos/tng-sdk-project/
    
  3. 激活虚拟环境并测试它。

相关内容