【发布时间】:2020-09-03 11:19:07
【问题描述】:
我通常使用 virtualenv 和 virtualenvwrapper 为我的项目创建虚拟环境。尝试使用以下命令创建新的虚拟环境:
mkvirtualenv -a . -p python3.7 venv
我收到以下错误消息:
Exception in thread Thread-1:
Traceback (most recent call last):
File "/usr/lib/python3.6/threading.py", line 916, in _bootstrap_inner
self.run()
File "/usr/lib/python3.6/threading.py", line 864, in run
self._target(*self._args, **self._kwargs)
File "/home/ubuntu/.local/lib/python3.6/site-packages/virtualenv/seed/via_app_data/via_app_data.py", line 75, in _get
self.app_data,
File "/home/ubuntu/.local/lib/python3.6/site-packages/virtualenv/seed/embed/wheels/acquire.py", line 28, in get_wheels
acquire_from_bundle(processed, for_py_version, wheel_cache_dir)
File "/home/ubuntu/.local/lib/python3.6/site-packages/virtualenv/seed/embed/wheels/acquire.py", line 57, in acquire_from_bundle
copy2(str(bundle), str(bundled_wheel_file))
File "/usr/lib/python3.6/shutil.py", line 263, in copy2
copyfile(src, dst, follow_symlinks=follow_symlinks)
File "/usr/lib/python3.6/shutil.py", line 121, in copyfile
with open(dst, 'wb') as fdst:
PermissionError: [Errno 13] Permission denied: '/home/ubuntu/.local/share/virtualenv/seed-app-data/v1.0.1/3.7/wheels/pip-20.0.2-py2.py3-none-any.whl'
created virtual environment CPython3.7.9.final.0-64 in 257ms
creator CPython3Posix(dest=/home/ubuntu/.virtualenvs/cosine, clear=False, global=False)
seeder FromAppData(download=False, pip=latest, setuptools=latest, wheel=latest, via=copy, app_data_dir=/home/ubuntu/.local/share/virtualenv/seed-app-data/v1.0.1)
activators BashActivator,CShellActivator,FishActivator,PowerShellActivator,PythonActivator,XonshActivator
Setting project for cosine to /home/ubuntu/cosine_similarity
虚拟环境仍在创建中,正在运行:
pip -V
我明白了
pip 20.1 from /home/ubuntu/.local/lib/python3.6/site-packages/pip (python 3.6)
这与服务器上的默认 python 版本相关联,因此,我卸载了 python3.7,并在我的终端上运行 python3.7 得到:
Command 'python3.7' not found, but can be installed with:
sudo apt install python3.7-minimal
因此假设没有正确安装python3.7,我再次使用deadsnakes的ppa重新安装了它,如下所示:
sudo add-apt-repository ppa:deadsnakes/ppa
sudo apt-get update
sudo apt install python3.7
但遗憾的是我仍然遇到同样的错误,我在虚拟环境之上使用诗歌并运行以下内容:(我有poetry.lock 文件)
poetry install
我收到以下错误消息:
[CalledProcessError]
Command '['/home/ubuntu/.cache/pypoetry/virtualenvs/cosine-similarity-SzdRNlpw-py3.7/bin/python', '-Im', 'ensurepip', '--upgrade', '--default-pip']' returned non-zero exit status 1.
如果有人能解释为什么会发生这种情况以及如何解决这个问题,那就太好了,谢谢。
[编辑]
在我使用-p python3.6 时添加更多信息,我没有收到任何此类权限错误,并且我的虚拟环境已成功创建。
有关更多信息,我使用上述 deadsnakes 的 ppa* 在系统上安装了 python3.8,然后尝试使用 python3.8 创建虚拟环境。
命令
mkvirutalenv -a . -p python3.8 venv2
stdout中的输出如下:
created virtual environment CPython3.8.5.final.0-64 in 627ms
creator CPython3Posix(dest=/home/ubuntu/.virtualenvs/venv2, clear=False, global=False)
seeder FromAppData(download=False, pip=latest, setuptools=latest, wheel=latest, via=copy, app_data_dir=/home/ubuntu/.local/share/virtualenv/seed-app-data/v1.0.1)
activators BashActivator,CShellActivator,FishActivator,PowerShellActivator,PythonActivator,XonshActivator
virtualenvwrapper.user_scripts creating /home/ubuntu/.virtualenvs/venv2/bin/predeactivate
virtualenvwrapper.user_scripts creating /home/ubuntu/.virtualenvs/venv2/bin/postdeactivate
virtualenvwrapper.user_scripts creating /home/ubuntu/.virtualenvs/venv2/bin/preactivate
virtualenvwrapper.user_scripts creating /home/ubuntu/.virtualenvs/venv2/bin/postactivate
virtualenvwrapper.user_scripts creating /home/ubuntu/.virtualenvs/venv2/bin/get_env_details
Setting project for venv2 to /home/ubuntu/main_xyz/app
【问题讨论】:
-
@aaron :
ls -l /home/ubuntu/.local/share/virtualenv/seed-app-data的输出是total 4 drwxrwxr-x 5 ubuntu ubuntu 4096 May 15 23:51 v1.0.1,echo $USER的输出是ubuntu -
ls: cannot access '/home/ubuntu/.local/share/virtualenv/seed-app-data/v1.0.1/3.7/wheels/pip-20.0.2-py2.py3-none-any.whl': No such file or directory, 嗯...我想知道为什么 -
ls -l /home/ubuntu/.local/share/virtualenv/seed-app-data/v1.0.1/3.7/wheels显示total 2056 -rw-r--r-- 1 root root 1489786 May 14 10:02 pip-20.1-py2.py3-none-any.whl -rw-r--r-- 1 root root 582683 May 14 10:02 setuptools-46.1.3-py3-none-any.whl -rw-r--r-- 1 root root 26502 May 14 10:02 wheel-0.34.2-py2.py3-none-any.whl -
which python输出/usr/bin/python和python3.7 --version输出Python 3.7.9 -
所以只有
-p python3.7有错误?
标签: python python-3.x pip virtualenv virtualenvwrapper