如何在 Ubuntu 18 上为 python 3.7 安装 pip?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/54633657/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to Install pip for python 3.7 on Ubuntu 18?
提问by ZeCarioca
EDIT 18/02: Since I still don't have a solution, I'm updating with what I know so far.
编辑 18/02:由于我仍然没有解决方案,我正在更新我目前所知道的。
I've installed python 3.7 successfully. I can install modules using pip (or pip3) but those modules are installed in Python 3.6 (Comes with ubuntu). Therefore I can't import those modules in python 3.7 (get a module not found) Python 3.7 doesn't recognize pip/pip3, so I can't install through pip/pip3 I need python 3.7
我已经成功安装了 python 3.7。我可以使用 pip(或 pip3)安装模块,但这些模块安装在 Python 3.6(随 ubuntu 一起提供)中。因此我无法在 python 3.7 中导入这些模块(找不到模块)Python 3.7 无法识别 pip/pip3,所以我无法通过 pip/pip3 安装我需要 python 3.7
--
——
I've installed Python 3.7 on my Ubuntu 18.04 machine. Following this instructions in case it's relevant:
我已经在我的 Ubuntu 18.04 机器上安装了 Python 3.7。如果相关,请按照此说明进行操作:
Download : Python 3.7 from Python Website [1] ,on Desktop and manually unzip it, on Desktop Installation : Open Terminal (ctrl +shift+T)
Go to the Extracted folder $ cd ~/Desktop/Python-3.7.0 $ ./configure $ make $ sudo make install
Making Python 3.7 default Python :
$ sudo vim ~/.bashrc press i on the last and new line - Type alias python= python3.7 press Esc type - to save and exit vim :wq now type $ source ~/.bashrc
From here: https://www.quora.com/How-can-I-upgrade-Python-3-6-to-3-7-in-Ubuntu-18-04
从 Python 网站 [1] 下载:Python 3.7,在桌面上并手动解压缩,在桌面安装:打开终端 (ctrl +shift+T)
Go to the Extracted folder $ cd ~/Desktop/Python-3.7.0 $ ./configure $ make $ sudo make install
使 Python 3.7 默认 Python :
$ sudo vim ~/.bashrc press i on the last and new line - Type alias python= python3.7 press Esc type - to save and exit vim :wq now type $ source ~/.bashrc
从这里:https: //www.quora.com/How-can-I-upgrade-Python-3-6-to-3-7-in-Ubuntu-18-04
I've downloaded several modules through pip install module
but when I try to import them, I get a ModuleNotFoundError: No module names 'xx'
我已经下载了几个模块,pip install module
但是当我尝试导入它们时,我得到了一个ModuleNotFoundError: No module names 'xx'
So I did some research and apparently when used pip to install, it installed in the modules in previous version of Python.
Somewhere (probably a question in SO) I found a suggestion to install the module using python3.7 -m pip install module
but then I get /usr/local/bin/python3.7: no module named pip
.
所以我做了一些研究,显然当使用 pip 安装时,它安装在以前版本的 Python 的模块中。在某处(可能是 SO 中的一个问题)我发现了一个使用安装模块的建议,python3.7 -m pip install module
但后来我得到了/usr/local/bin/python3.7: no module named pip
.
Now I'm stuck, pip is installed, but apparently not for Python 3.7. I'm assuming that if I can install pip for Python 3.7, I can run the pip install command and get the modules I need. If that is the case, how can I install pip for python 3.7, since it's already installed?
现在我被卡住了,pip 已安装,但显然不适用于 Python 3.7。我假设如果我可以为 Python 3.7 安装 pip,我可以运行 pip install 命令并获取我需要的模块。如果是这种情况,我如何为 python 3.7 安装 pip,因为它已经安装了?
回答by mpenkov
回答by dangel
A quick add-on to mpenkov's answer above(didn't want this to get lost in the comments)
对上面 mpenkov 的回答的快速补充(不想在评论中迷失)
For me, I had to install pip for 3.6 first
对我来说,我必须先为 3.6 安装 pip
sudo apt install python3-pip
now you can install python 3.7
现在你可以安装 python 3.7
sudo apt install python3.7
and then I could install pip for 3.7
然后我可以为 3.7 安装 pip
python3.7 -m pip install pip
and as a bonus, to install other modules just preface with
作为奖励,安装其他模块只需
python3.7 -m pip install <module>
EDIT 1 (12/2019):
编辑 1 (12/2019):
I know this is obvious for most. but if you want python 3.8, just substitute python3.8
in place of python3.7
我知道这对大多数人来说是显而易见的。但如果你想蟒蛇3.8,刚刚替补python3.8
代替python3.7
EDIT 2 (5/2020):
编辑 2 (5/2020):
For those that are able to upgrade, Python 3.8 is available out-of-the-box for Ubuntu 20.04 which was released a few weeks ago.
对于那些能够升级的用户,几周前发布的 Ubuntu 20.04 可以直接使用 Python 3.8。
回答by Tomek Tajne
This works for me.
这对我有用。
curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
Then this command with sudo:
然后使用 sudo 执行此命令:
python3.7 get-pip.py
python3.7 get-pip.py
Based on this instruction.
基于此指令。
回答by Kealen
I used apt-get to install python3.7 in ubuntu18.04. The installations are as follows.
我在ubuntu18.04中使用apt-get安装python3.7。安装如下。
- install python3.7
- 安装python3.7
sudo apt-get install python3.7
- install pip3. It should be noted that this may install pip3 for python3.6.
- 安装pip3。需要注意的是,这可能会为python3.6安装pip3。
sudo apt-get install python3-pip
- change the default of python3 for python3.7. This is where the magic is, which will make the pip3 refer to python3.7.
- 为 python3.7 更改 python3 的默认值。这就是魔法所在,这将使 pip3 引用 python3.7。
sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.7 1
Hope it works for you.
希望对你有效。
回答by S. Brunner
To install all currently supported python versions (python 3.6 is already pre-installed) including pip for Ubuntu 18.04 do the following:
要安装所有当前支持的 python 版本(python 3.6 已经预安装),包括 Ubuntu 18.04 的 pip,请执行以下操作:
To install python3.5 and python3.7, use the deadsnakes ppa:
要安装 python3.5 和 python3.7,请使用 deadsnakes ppa:
sudo add-apt-repository ppa:deadsnakes/ppa
sudo apt-get update
sudo apt-get install python3.5
sudo apt-get install python3.7
Install python2.7 via distribution packages:
通过分发包安装python2.7:
sudo apt install python-minimal # on Ubuntu 18.04 python-minimal maps to python2.7
To install pip use:
要安装 pip 使用:
sudo apt install python-pip # on Ubuntu 18.04 this refers to pip for python2.7
sudo apt install python3-pip # on Ubuntu 18.04 this refers to pip for python3.6
python3.5 -m pip install pip # this will install pip only for the current user
python3.7 -m pip install pip
I used it for setting up a CI-chain for a python project with tox and Jenkins.
我用它为带有 tox 和 Jenkins 的 python 项目设置 CI 链。
回答by bob
Combining the answers from @mpenkon and @dangel, thisis what worked for me:
结合@mpenkon 和@dangel 的答案,这对我有用:
sudo apt install python3-pip
python3.7 -m pip install pip
sudo apt install python3-pip
python3.7 -m pip install pip
Step #1 is required (assuming you don't already have pip for python3) for step #2 to work. It uses pip for Python3.6 to install pip for Python 3.7 apparently.
第 1 步是必需的(假设您还没有用于 python3 的 pip)才能使第 2 步工作。它显然使用 Python3.6 的 pip 来安装 Python 3.7 的 pip。
回答by JJP
When i use apt install python3-pip
, i get a lot of packages need install, but i donot need them. So, i DO like this:
当我使用时apt install python3-pip
,我得到很多需要安装的软件包,但我不需要它们。所以,我喜欢这样:
apt update
apt-get install python3-setuptools
curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
python3 get-pip.py
rm -f get-pip.py
回答by Anil Konduru
The following steps can be used:
可以使用以下步骤:
sudo apt-get -y update
---------
sudo apt-get install python3.7
--------------
python3.7
-------------
curl -O https://bootstrap.pypa.io/get-pip.py
-----------------
sudo apt install python3-pip
-----------------
sudo apt install python3.7-venv
-----------------
python3.7 -m venv /home/ubuntu/app
-------------
cd app
----------------
source bin/activate
回答by James T
For those who intend to use venv
:
对于那些打算使用的人venv
:
If you don't already have pip
for Python 3:
如果您还没有pip
Python 3:
sudo apt install python3-pip
Install venv
package:
安装venv
包:
sudo apt install python3.7-venv
Create virtual environment (which will be bootstrapped with pip
by default):
创建虚拟环境(pip
默认情况下将引导):
python3.7 -m venv /path/to/new/virtual/environment
To activate the virtual environment, source
the appropriate script for the current shell, from the bin
directory of the virtual environment. The appropriate scripts for the different shells are:
从虚拟环境source
的bin
目录中激活虚拟环境,当前 shell 的适当脚本。不同 shell 的适当脚本是:
bash/zsh – activate
bash/zsh – activate
fish – activate.fish
鱼 - activate.fish
csh/tcsh – activate.csh
csh/tcsh – activate.csh
For example, if using bash:
例如,如果使用 bash:
source /path/to/new/virtual/environment/bin/activate
Optionally, to update pip
for the virtual environment (while it is activated):
(可选)更新pip
虚拟环境(激活时):
pip install --upgrade pip
When you want to deactivate the virtual environment:
当您要停用虚拟环境时:
deactivate
回答by Patrick Conwell
pip3
not pip
. You can create an alias like you did with python3
if you like.
pip3
不是pip
。python3
如果您愿意,您可以像以前一样创建别名。