我想virtualenv
在 Ubuntu 18.04 上使用 Python 3。具体来说,我使用的是 Python 3.6.6 和 virtualenv 16.0.0。
sudo
我按照建议安装了 virtualenv在这里的答案中:sudo pip3 install --upgrade virtualenv
我使用 创建了一个新的虚拟环境
python3 -m virtualenv venv
。并像往常一样激活它:source venv/bin/activate
。当我尝试安装我的 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 所有权的文件夹的指令。
停用虚拟环境。
尝试递归修复所有者:
sudo chown -R stefan:stefan /home/stefan/git-repos/tng-sdk-project/
激活虚拟环境并测试它。