英文:
Creating a venv with python 3.10 manually installed on Ubuntu, fails
问题
我已在Ubuntu 20.04上使用deadsnakes ppa安装了Python 3.10。它可以正常运行。但尝试使用它创建一个虚拟环境失败了:
$ python3.10 -m venv venv3.10
错误:命令 ''['<my-working-directory>/venv3.10/bin/python3.10', '-m', 'ensurepip', '--upgrade', '--default-pip']' 返回了非零的退出状态 1。
这与关于Python 3.11的一个类似问题相似,还有一个关于旧版本的类似问题。然而,安装pip并不是一个解决方案,因为后续可能会出现问题,尤其是在PyCharm中使用新的虚拟环境时,由于缺少setuptools而失败。我已经升级到了pip的最新版本,正如一些相关问题中提到的。我还尝试重新安装了版本3.10的pip:
$ curl -sS https://bootstrap.pypa.io/get-pip.py | python3.10
我获取了它的版本信息:
$ python3.10 -m pip --version
pip 23.1 from /home/matan/.local/lib/python3.10/site-packages/pip (python 3.10)
但尝试使用Python 3.10创建一个新的虚拟环境仍然以前面提到的错误消息结束。就好像venv和/或pip没有完全集成,或者本地某些东西指向了Python 3.10的旧文件。
英文:
I have installed python 3.10 on Ubuntu 20.04 using the deadsnakes ppa. It works.
However trying to create a venv with it fails:
$ python3.10 -m venv venv3.10
Error: Command '['<my-working-directory>/venv3.10/bin/python3.10', '-m', 'ensurepip', '--upgrade', '--default-pip']' returned non-zero exit status 1.
This is quite similar to a similar question regardgin python 3.11, there was also something similar regarding older versions. However the installation of pip is not a solution because it will be an issue later on, if only for being able to use the new venv in PyCharm which currently fails over missing setuptools. I have already upgraded to the latest version of pip, as some related issues mention. I also did manage re-installing pip as if for/with version 3.10,
$ curl -sS https://bootstrap.pypa.io/get-pip.py | python3.10
And I am getting this version information for it:
$ python3.10 -m pip --version
pip 23.1 from /home/matan/.local/lib/python3.10/site-packages/pip (python 3.10)
But trying to create a new python 3.10 venv using python 3.10 just ends up with the originally above mentioned error message. As if venv and/or pip are not fully integrated or something locally is pointing at old artifacts for python 3.10.
答案1
得分: 4
运行 sudo apt install python3.10-venv
会安装 Python 3.10 的虚拟环境包,而在只安装 Python 3.10 本身而不安装它时,你将无法获得这个包。
要验证这一点,我下载了一个全新的 Ubuntu 20.04 LTS 副本到我的 VirtualBox,并使用以下步骤:
sudo add-apt-repository ppa:deadsnakes/ppa
sudo apt-get update
sudo apt-get install python3.10 python3.10-venv
之后,创建 Python 3.10 的虚拟环境是可能的:
kyrlon@pc23:~$ python3.10 -m venv py_venv
kyrlon@pc23:~$ source py_venv/bin/activate
(py_venv) kyrlon@pc23:~$
正如在 deadsnakes 的主 PPA 页面的软件包部分 所述:
这些软件包遵循 Debian 的模式,通常不包括仅通过
apt install python#.#
安装的完整 Python 发行版。
当使用命令 apt install python3.10
时,不会包括 Python 3.10 的虚拟环境包 (venv
),以及其他有用的包如 dev
、distutils
、lib2to3
、gdbm
和 tk
。正如从 PPA 页面中提到的,apt install python#.#
(#
代表 python 版本)不是一个包含所有内容的 Python 发行版,因为它们遵循Debian 的打包模式/惯例。
在6.1.3. 多个二进制软件包中指出:
一个单一的源软件包通常会构建多个二进制软件包,要么提供相同软件的多个变种(例如 vim 源软件包),要么创建多个小软件包而不是一个大的软件包(例如用户可以仅安装所需的子集,从而节省一些磁盘空间,例如 lyx 源软件包)。
考虑到这种背景,可以理解为什么它被省略了。正如上面提到的,由于用户有选择安装特定的软件包,他们可以避免不需要的软件包的膨胀,以满足他们的用例需求。
希望这能澄清对用户(包括我自己)来说运行 apt install python3
不会像为 Windows OS 提供的二进制软件包那样安装 venv
或其他有益的软件包,正如你可以从那里看到的。
英文:
Running sudo apt install python3.10-venv
installs the virtual environment package for python 3.10, which you otherwise are not getting when just installing python 3.10 itself from deadsnakes.
To verify this, I downloaded a brand-new copy of Ubuntu 20.04 LTS for my VirtualBox and used the procedures listed below:
sudo add-apt-repository ppa:deadsnakes/ppa
sudo apt-get update
sudo apt-get install python3.10 python3.10-venv
Afterwards creating a virtual environment for python 3.10 is possible:
kyrlon@pc23:~$ python3.10 -m venv py_venv
kyrlon@pc23:~$ source py_venv/bin/activate
(py_venv) kyrlon@pc23:~$
As stated in the packages section of the main PPA page for deadsnakes
> the packages follow debian's patterns and often do not include a full
> python distribution with just apt install python#.#
When using the command apt install python3.10
, the python virtual environment package for python 3.10 (venv
), as well as other useful packages dev
, distutils
, lib2to3
, gdbm
, and tk
, are not included. As mentioned from the PPA page, apt install python#.#
(with #
representing the version of python in that instance) is not an all in one python distribution since they follow debian's packaging pattern/practice.
Stated in 6.1.3. Multiple binary packages
> A single source package will often build several binary packages,
> either to provide several flavors of the same software (e.g., the vim
> source package) or to make several small packages instead of a big one
> (e.g., so the user can install only the subset needed, and thus save
> some disk space, see for example the lyx source package).
Given such context, it is understandable why it was left out. As mentioned above, since the user has the option to install particular packages, they can avoid the bloat of packages they do not need for their use case.
Hopefully this clears up to users (including myself) that running apt install python3
does not install venv
or other beneficial packages as one encompassing distribution from the deadsnakes PPA, as you could see from a binary package as offered for Windows OS.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论