如何在Ubuntu 16.10上为Python 3.6安装pip? [英] How to install pip for Python 3.6 on Ubuntu 16.10?

查看:521
本文介绍了如何在Ubuntu 16.10上为Python 3.6安装pip?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

首先,我想指出这个问题似乎是重复的,但事实并非如此.我在这里看到的所有问题都是关于Python 3的pip,而我正在谈论的是Python 3.6.那时使用的步骤不适用于Python 3.6.

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.

  1. 我从官方Docker存储区获得了清晰的Ubuntu 16.10映像.
  2. 运行apt-get update
  3. 运行apt-get install python3.6
  4. 运行apt-get install python3-pip
  5. 运行pip3 install requests bs4
  6. 运行python3.6 script.py
  1. I got a clear Ubuntu 16.10 image from the official docker store.
  2. Run apt-get update
  3. Run apt-get install python3.6
  4. Run apt-get install python3-pip
  5. Run pip3 install requests bs4
  6. Run python3.6 script.py

在下面找到ModuleNotFoundError

 Traceback (most recent call last):
    File "script.py", line 6, in <module>
     import requests
 ModuleNotFoundError: No module named 'requests'

我的机器中有Python和pip:

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

推荐答案

让我们假设您有一个运行Ubuntu 16.04、16.10或17.04的系统,并且您希望Python 3.6是默认的Python.

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.

如果您使用的是Ubuntu 16.04 LTS,则需要使用PPA:

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)

然后,运行以下命令(这在16.10和17.04上是开箱即用的):

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

完成上述所有操作后,以下每个shell命令都应指示Python 3.6.1(或Python 3.6的更新版本):

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

这篇关于如何在Ubuntu 16.10上为Python 3.6安装pip?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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