我通常使用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 版本相关联的 pip ,因此,我卸载了 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
,我没有收到任何此类权限错误,并且我的虚拟环境已成功创建。
有关其他信息,我使用上面的ppa by deadsnakes * 在系统上安装了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