Python pyvenv 不工作,因为 ensurepip 不可用
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/39539110/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
pyvenv not working because ensurepip is not available
提问by Louis M
I upgraded from ubuntu 14.04 to ubuntu 16.04 a few days ago. When I try to create a virtual env by using
几天前我从 ubuntu 14.04 升级到 ubuntu 16.04。当我尝试使用创建虚拟环境时
pyvenv .venv
or
或者
python3 -m venv .venv
There is an error:
有一个错误:
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-venv
You may need to use sudo with that command. After installing the python3-venv
package, recreate your virtual environment.
Failing command: ['/usr/bin/python3.5', '-Im', 'ensurepip', '--upgrade', '--default-pip']
I tried running both
我试过同时运行
sudo apt-get install python3-venv
and
和
sudo apt-get install python3.5-venv
but it did not solve my problem.
但它没有解决我的问题。
回答by Louis M
It seems that it was a locale problem. Solved by executing:
似乎这是一个区域设置问题。通过执行解决:
export LC_ALL="en_US.UTF-8"
export LC_CTYPE="en_US.UTF-8"
sudo dpkg-reconfigure locales
found on this thread Python locale error: unsupported locale setting
在此线程上发现Python 语言环境错误:不支持的语言环境设置
回答by jnicho02
try installing python3.6-venv:
尝试安装 python3.6-venv:
sudo apt-get install python3.6-venv
回答by Aaron F
One of the other answers fixed it for me last time, but with Python 3.7 I had to do:
上次其他答案之一为我修复了它,但使用 Python 3.7 我必须这样做:
apt install python3-pip python3-setuptools python3.7-venv
Followed by
其次是
python3.7 -m venv /path/to/venv
回答by Eponymous
Under Windows Linux Subsystem and Ubuntu 18.04, this was caused by my not having upgraded recently.
在 Windows Linux 子系统和 Ubuntu 18.04 下,这是由于我最近没有升级造成的。
I ran:
我跑了:
sudo apt update
sudo apt upgrade
Then sudo apt install python3-venv
worked.
然后sudo apt install python3-venv
工作了。
Note that I had also tried the UTF-8 solutionbeforehand (I made it part of my .bashrc
), so that could have been a contributing factor.
请注意,我事先也尝试过UTF-8 解决方案(我将其作为我的 一部分.bashrc
),因此这可能是一个促成因素。
回答by nbwoodward
In case this helps anyone down the line, I was getting the same error on Ubuntu 18.04. Setting the locales didn't work and trying to install python3-venv
gave the error:
如果这可以帮助任何人,我在 Ubuntu 18.04 上遇到了同样的错误。设置语言环境不起作用,尝试安装时python3-venv
出现错误:
$ sudo apt-get install python3-venv
Reading package lists... Done
Building dependency tree
Reading state information... Done
Some packages could not be installed. This may mean that you have
requested an impossible situation or if you are using the unstable
distribution that some required packages have not yet been created
or been moved out of Incoming.
The following information may help to resolve the situation:
The following packages have unmet dependencies:
python3-venv : Depends: python3.6-venv (>= 3.6.5-2~) but it is not going to be installed
Depends: python3 (= 3.6.5-3) but 3.6.7-1~18.04 is to be installed
E: Unable to correct problems, you have held broken packages.
And it looks like the apt repository had two versions of python:
看起来apt存储库有两个版本的python:
$ apt list python3 -a
python3/bionic-updates,now 3.6.7-1~18.04 amd64 [installed]
python3/bionic 3.6.5-3 amd64
I tried to install Python3.6.5-3
but apt wanted to uninstall every dependency. I was able to solve the problem by installing Python3.7 and creating the venv with that:
我尝试安装,Python3.6.5-3
但 apt 想卸载每个依赖项。我能够通过安装 Python3.7 并用它创建 venv 来解决这个问题:
$ sudo apt-get install python3.7 python3.7-venv
$ python3.7 -m venv my_venv
回答by Rustam A.
Resolved similar problems on Ubuntu18 when came upon this answer. It is similar to the one that worked for @Niko Rikken, accept doesn't really need any new PPA's and "python3.8-distutils" package. I was installing new python3.8 environment with venv and I already had "python3-venv" installed and up to date, so my solution was to install only "python3.8-venv":
找到这个答案时解决了 Ubuntu18 上的类似问题。它类似于为@Niko Rikken 工作的那个,accept 并不真正需要任何新的 PPA 和“python3.8-distutils”包。我正在使用 venv 安装新的 python3.8 环境,并且我已经安装了“python3-venv”并且是最新的,所以我的解决方案是只安装“python3.8-venv”:
% sudo apt-get install python3.8-venv
And that got this lines working:
这让这条线工作:
% python3.8 -m venv ~/envs/new_env
% source ~/envs/new_env/bin/activate
回答by Eduardo RE
In my case the next steps worked:
在我的情况下,接下来的步骤有效:
- Ubuntu 18.04.4 LTS
- Ubuntu 18.04.4 LTS
$ sudo apt-get install python3-venv python3.7-venv
$ python3.7 -m venv [your_path_to_virtual_env_here]
回答by Nico Rikken
I encountered this problem on Ubuntu 18.04for the recent release of Python-3.8. My solution was to add the Deadsnakes PPAwhich supplies the required python3.8-distutils
package. The python3.8-venv
package is already in the repository. Thanks to this blogpost:
我在最近发布的Python-3.8 的Ubuntu 18.04上遇到了这个问题。我的解决方案是添加提供所需包的Deadsnakes PPA。该软件包已在存储库中。感谢这篇博文:python3.8-distutils
python3.8-venv
sudo add-apt-repository ppa:deadsnakes/ppa
sudo apt update
sudo apt install python3.8
sudo apt install python3.8-distutils
sudo apt install python3.8-venv
Note:This is only a temporary solution. In the near future the required python3.8-distutils
package will probably be available in the default Ubuntu repository.
注意:这只是一个临时解决方案。在不久的将来,所需的python3.8-distutils
软件包可能会在默认的 Ubuntu 存储库中可用。
回答by Nax
Try : python3.* -m venv myvenv -
尝试 : python3.* -m venv myvenv -
And don't forget to replace * with your specific version of python
并且不要忘记将 * 替换为您的特定版本的 python
回答by samiya umar
I had the same problem - the python env has 2 versions for 2.7 and 3.6.
我遇到了同样的问题——python env 有 2.7 和 3.6 的 2 个版本。
All you need to do is:
您需要做的就是:
- Install the latest version of pip by installing pyenv installer
- Make sure you follow the steps of installing pyenv found here
- 通过安装pyenv installer 安装最新版本的 pip
- 确保您按照此处找到的安装 pyenv 的步骤进行操作
Good Luck!
祝你好运!