如何在Ubuntu 18.04上安装python3.7和pip创建virtualenv? [英] How to install python3.7 and create a virtualenv with pip on Ubuntu 18.04?

查看:673
本文介绍了如何在Ubuntu 18.04上安装python3.7和pip创建virtualenv?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在Ubuntu 18.04上使用python 3.7通过pip(或通过某种方式在virtualenv中安装软件包)设置标准的virtualenv.安装python3.7的标准方法似乎是: % sudo apt install python3.7 python3.7-venv % python3.7 -m venv py37-venv 但第二条命令失败,提示:

I'm trying to set up a standard virtualenv with python 3.7 on Ubuntu 18.04, with pip (or some way to install packages in the virtualenv). The standard way to install python3.7 seems to be: % sudo apt install python3.7 python3.7-venv % python3.7 -m venv py37-venv but the second command fails, saying:

虚拟环境未成功创建,因为surepip 不可用.在Debian/Ubuntu系统上,您需要安装 python3-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-venv

您可能需要在该命令中使用sudo.安装完后 python3-venv软件包,重新创建您的虚拟环境.

You may need to use sudo with that command. After installing the python3-venv package, recreate your virtual environment.

失败的命令:['/py37-venv/bin/python3.7'、'-Im'、'ensurepip', '--upgrade','-default-pip']

Failing command: ['/py37-venv/bin/python3.7', '-Im', 'ensurepip', '--upgrade', '--default-pip']

这是真的;没有与此Python一起安装的ensurepip和pip.而且我确实已经安装了python3.7-venv(python3-venv用于Debian/Ubuntu上的python3.6).由于多个python版本和/或需要root用户访问权限,以及通过apt或类似方式安装python模块的替代方法,我在python社区中对此进行了一些讨论.

This is true; there is no ensurepip nor pip installed with this python. And I did install python3.7-venv already (python3-venv is for python3.6 on Debian/Ubuntu). I gather there has been some discussion about this in the python community because of multiple python versions and/or requiring root access, and alternate ways to install python modules via apt or similar.

创建不带pip(--without-pip)的virtualenv可以成功,但是无法在新的virtualenv中安装软件包,这似乎在很大程度上违背了这个目的.

Creating a virtualenv without pip (--without-pip) succeeds, but then there's no way to install packages in the new virtualenv which seems to largely defeat the purpose.

那么在18.04上使用virtualenv安装和使用python3.7的最佳实践"方法是什么?

So what's the accepted "best practice" way to install and use python3.7 on 18.04 with a virtualenv?

推荐答案

我不知道这是否是最佳实践,但是如果我还安装了python3-venv,那么一切正常(已在新鲜的Debian Buster上进行了测试泊坞窗图片):

I don't know if it's best practices or not, but if I also install python3-venv then everything works (this is tested on a fresh stock Debian buster docker image):

% sudo apt install python3.7 python3-venv python3.7-venv
% python3.7 -m venv py37-venv
% . py37-venv/bin/activate
(py37-venv) % 

请注意,它也不需要安装所有python3.6,所以我不能确切地说我喜欢它,但至少它确实可以工作,并且不需要像get-pip.py那样运行未签名的脚本.

Note that it also installs all of python3.6 needlessly, so I can't exactly say I like it, but at least it does work and doesn't require running an unsigned script the way get-pip.py does.

这篇关于如何在Ubuntu 18.04上安装python3.7和pip创建virtualenv?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆