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

查看:48
本文介绍了如何在 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 商店.
  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

下面有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天全站免登陆