0

我通常使用virtualenvvirtualenvwrapper为我的项目创建虚拟环境。尝试使用以下命令创建新的虚拟环境:

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
4

1 回答 1

2

在尝试此解决方案之前,请尝试运行sudo su 然后重复您的解决方案,...如果它很酷。别的

第 2 部分 ======>

检查你的 python 版本。 python --version

在python中查找所有python ls /usr/bin/python*

如果 python 3.7 是列出路径的一部分,那就太酷了。

设置python默认路径 alias python='/usr/bin/python3.7'

重新登录您的来源 . ~/.bashrc

确认你的python版本已经改变了 python --version

然后安装虚拟环境 pip install virtualenv

然后创建虚拟环境 virtualenv venv

并激活它 source venv/bin/activate

于 2020-09-07T08:14:11.317 回答