确保在Debian / Ubuntu中禁用了系统python


10

我正在尝试为我的Django应用程序的开发创建虚拟环境。我正在使用的突击队:

vagrant@vagrant:/var/www/djangogirls$ python3 -m venv myvenv
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: ['/var/www/djangogirls/myvenv/bin/python3', '-Im', 'ensurepip', '--upgrade', '--default-pip']


vagrant@vagrant:/var/www/djangogirls$ sudo apt-get install python3-venv
Reading package lists... Done
Building dependency tree       
Reading state information... Done
python3-venv is already the newest version (3.5.1-3).
The following packages were automatically installed and are no longer required:
  javascript-common libjs-jquery libjs-sphinxdoc libjs-underscore python-pbr python-pkg-resources
  python-six python-stevedore python3-virtualenv virtualenv virtualenv-clone
Use 'sudo apt autoremove' to remove them.
0 upgraded, 0 newly installed, 0 to remove and 108 not upgraded.

vagrant@vagrant:/var/www/djangogirls$ python3 -m ensurepip
ensurepip is disabled in Debian/Ubuntu for the system python.

Python modules for the system python are usually handled by dpkg and apt-get.

    apt-get install python-<module name>

Install the python-pip package to use pip itself.  Using pip together
with the system python might have unexpected results for any system installed
module, so use it on your own risk, or make sure to only use it in virtual
environments.


vagrant@vagrant:/var/www/djangogirls$ rm -r myvenv/ 

vagrant@vagrant:/var/www/djangogirls$ python3 -m venv myvenv
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: ['/var/www/djangogirls/myvenv/bin/python3', '-Im', 'ensurepip', '--upgrade', '--default-pip']

如您所见,我正在尝试制作myvenv,由于缺少python3-venv而无法创建。我已经安装了它,但是确保缺少点子。搜索后,似乎系统(Ubuntu 16.04)不鼓励使用该软件包。有人可以帮我解决这个问题吗?


失败的实际命令是/var/www/djangogirls/myvenv/bin/python3 -Im ensurepip ...,可能由于完全不同的原因而失败。
muru

Answers:


14

有一个相关的bug报告在这里

确保在Ubuntu上缺少/禁用了组件组件

解决方法是创建一个没有pip的虚拟环境

python3 -m venv myvenv --without-pip

在这种情况下,不会调用surepip组件,并且会创建一个新环境。

但是,在虚拟环境中缺少点可能是一个问题。

一种解决方案是在虚拟环境中直接安装系统pip3软件包并使用系统pip模块。

虚拟环境必须有权访问系统站点程序包才能使用系统pip模块。

  1. 安装系统python3 pip软件包

    sudo apt-get install python3-pip
  2. 创建虚拟环境而无需使用pip并可以访问系统站点程序包

    python3 -m venv myvenv --without-pip --system-site-packages

您现在可以使用系统pip模块将python软件包安装到您的虚拟环境中。

不必pip install Django使用显式

myvenv/bin/python3 -m pip install Django

或者您可以先激活虚拟环境

source myvenv/bin/activate
python3 -m pip install Django

python3 -m pip --version 可能会很方便地查看使用哪个python环境。

基于此处找到的解决方案,但请勿python get-pip.py在虚拟环境中使用,因为它会窃取系统pip命令


这个问题的Debian错误在这里:bugs.debian.org/cgi-bin/bugreport.cgi?
nnyby

1

水蟒

如果您正在使用 Anaconda Conda,则此解决方案可以为您提供帮助:

与仅管理Python软件包的pip相比,Conda本身将python作为软件包进行管理,因此可以进行conda更新python。Conda可在Anaconda和Miniconda中使用(仅使用Python和conda即可轻松安装的下载)。

对我来说很困扰,但是好吧,请在终端窗口中将手放在键盘上:

conda update python

看看这张照片的结果,也许对您有帮助,祝您有美好的一天!

By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.