【问题标题】:Unable to create virtual enviroment for Python 3.8.10无法为 Python 3.8.10 创建虚拟环境
【发布时间】:2021-10-11 21:38:19
【问题描述】:

是否可以为 python 3.8.10 创建虚拟环境?

python3 -m venv venv

返回

The virtual environment was not created successfully because ensurepip is not
available.  On Debian/Ubuntu systems, you need to install the python3-venv
package using the following command.

    apt install python3.8-venv

apt-get install python3.8-venv

返回

The following packages have unmet dependencies:
 python3.8-venv : Depends: python3.8 (= 3.8.5-1~20.04) but 3.8.10-0ubuntu1~20.04 is to be installed
E: Unable to correct problems, you have held broken packages.

【问题讨论】:

  • 这个thread提供的解决方案有帮助吗?
  • 不。安装它的唯一方法似乎是从 3.8.10 降级
  • 使用 pyenv 或类似的东西,而不是搞乱系统的 Python 解释器

标签: python python-3.x python-venv


【解决方案1】:

TLDR

  • 正如@Maurice 所说,使用 pyenv 而不是乱用系统解释器。
  • 确保 pyenv 没有使用系统解释器 pyenv versions
  • 确保删除所有现有的 venv 文件夹。惊喜 第 2 步中的 venv 文件夹让我很困惑。

长篇大论:

  1. 已安装 pyenv,但版本仍设置为指向系统。
$ pyenv versions

- system (set by .pyenv/version)
  1. 使用 system Python 创建 venv 失败,消息如下所示。尽管失败,但仍创建了 venv 文件夹!!
$ python3 -m venv venv

The virtual environment was not created successfully because ensurepip is not
available.  On Debian/Ubuntu systems, you need to install the python3-venv
package using the following command.

$ apt-get install python3.8-venv

The following packages have unmet dependencies:
 python3.8-venv : Depends: python3.8 (= 3.8.5-1~20.04) but 3.8.10-0ubuntu1~20.04 is to be installed
E: Unable to correct problems, you have held broken packages.
  1. 安装和使用 3.8.10 pyenv 返回不同的错误
$ pyenv install 3.8.10
$ pyenv local 3.8.10
$ pyenv versions

  system 
* 3.8.10 (set by ./.python-version)

$ python3 -m venv venv

Error: Command '['home/project/venv/bin/python', '-Im', 'ensurepip', '--upgrade', '--default-pip']' returned non-zero exit status 1.
  1. 删除从第 2 步创建的 venv 文件夹并重新运行 python3 -m venv venv 可以正确激活它。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-11-19
    • 2014-01-24
    • 1970-01-01
    • 2019-12-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多