ubuntu安装python3.6,如何在Ubuntu 16.10上为Python 3.6安装pip?

I'd like to start by pointing out that this question may seem like a duplicate, but it isn't. All the questions I saw here were regarding pip for Python 3 and I'm talking about Python 3.6. The steps used back then don't work for Python 3.6.

I got a clear Ubuntu 16.10 image from the official docker store.

Run apt-get update

Run apt-get install python3.6

Run apt-get install python3-pip

Run pip3 install requests bs4

Run python3.6 script.py

Got ModuleNotFoundError below:

Traceback (most recent call last):

File "script.py", line 6, in

import requests

ModuleNotFoundError: No module named 'requests'

Python's and pip's I have in the machine:

python3

python3.5

python3.5m

python3.6

python3m

python3-config

python3.5-config

python3.5m-config

python3.6m

python3m-config

pip

pip3

pip3.5

解决方案

Let's suppose that you have a system running Ubuntu 16.04, 16.10, or 17.04, and you want Python 3.6 to be the default Python.

If you're using Ubuntu 16.04 LTS, you'll need to use a PPA:

sudo add-apt-repository ppa:jonathonf/python-3.6 # (only for 16.04 LTS)

Then, run the following (this works out-of-the-box on 16.10 and 17.04):

sudo apt update

sudo apt install python3.6

sudo apt install python3.6-dev

sudo apt install python3.6-venv

wget https://bootstrap.pypa.io/get-pip.py

sudo python3.6 get-pip.py

sudo ln -s /usr/bin/python3.6 /usr/local/bin/python3

sudo ln -s /usr/local/bin/pip /usr/local/bin/pip3

# Do this only if you want python3 to be the default Python

# instead of python2 (may be dangerous, esp. before 2020):

# sudo ln -s /usr/bin/python3.6 /usr/local/bin/python

When you have completed all of the above, each of the following shell commands should indicate Python 3.6.1 (or a more recent version of Python 3.6):

python --version # (this will reflect your choice, see above)

python3 --version

$(head -1 `which pip` | tail -c +3) --version

$(head -1 `which pip3` | tail -c +3) --version

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值