ubuntu18.04安装python3_如何在Ubuntu 18.04上安装python3.7和pip创建virtualenv?

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:

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: ['/py37-venv/bin/python3.7', '-Im', 'ensurepip',

'--upgrade', '--default-pip']

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.

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.

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

解决方案

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) %

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.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值