Ubuntu:pip 不适用于 python3.4

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/24137291/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-19 04:05:31  来源:igfitidea点击:

Ubuntu: pip not working with python3.4

pythonubuntupython-3.xpip

提问by val_

Trying to get pip working on my Ubuntu pc. pip seems to be working for python2.7, but not for others.

试图让 pip 在我的 Ubuntu 电脑上工作。pip 似乎适用于 python2.7,但不适用于其他人。

Here's the problem:

这是问题所在:

$ pip
Traceback (most recent call last):
File "/usr/local/bin/pip", line 9, in <module>
load_entry_point('pip==1.4.1', 'console_scripts', 'pip')()
File "/usr/local/lib/python3.4/dist-packages/setuptools-1.1.5-py3.4.egg /pkg_resources.py", line 357, in load_entry_point
def get_entry_info(dist, group, name):
File "/usr/local/lib/python3.4/dist-packages/setuptools-1.1.5-py3.4.egg/pkg_resources.py", line 2394, in load_entry_point
break
File "/usr/local/lib/python3.4/dist-packages/setuptools-1.1.5-py3.4.egg/pkg_resources.py", line 2108, in load
name = some.module:some.attr [extra1,extra2]
ImportError: No module named 'pip'

$ which pip
/usr/local/bin/pip

$ python2.7 -m pip //here can be just python, btw
Usage:   
/usr/bin/python2.7 -m pip <command> [options]
//and so on...

$ python3.4 -m pip
/usr/bin/python3.4: No module named pip

From the home/user/.pip/pip.log :

从 home/用户/.pip/pip.log :

Exception:
Traceback (most recent call last):
File "/usr/lib/python2.7/dist-packages/pip/basecommand.py", line 122, in main
status = self.run(options, args)
File "/usr/lib/python2.7/dist-packages/pip/commands/install.py", line 283, in run
requirement_set.install(install_options, global_options, root=options.root_path)
File "/usr/lib/python2.7/dist-packages/pip/req.py", line 1431, in install
requirement.uninstall(auto_confirm=True)
File "/usr/lib/python2.7/dist-packages/pip/req.py", line 598, in uninstall
paths_to_remove.remove(auto_confirm)
File "/usr/lib/python2.7/dist-packages/pip/req.py", line 1836, in remove
renames(path, new_path)
File "/usr/lib/python2.7/dist-packages/pip/util.py", line 295, in renames
shutil.move(old, new)
File "/usr/lib/python2.7/shutil.py", line 303, in move
os.unlink(src)
OSError: [Errno 13] Permission denied: '/usr/bin/pip'

There's no /usr/bin/pip btw.

顺便说一句,没有/usr/bin/pip。

How can I fix this issue to work with pip and python 3.4 normally? I am trying to use pycharm, but it's package manager also stucks in this problem.

如何解决此问题以正常使用 pip 和 python 3.4?我正在尝试使用 pycharm,但它的包管理器也遇到了这个问题。

Thanks for attention!

谢谢关注!

采纳答案by Ivo

You have pip installed for python 2, but not python 3.

您已经为 python 2 安装了 pip,但没有为 python 3 安装。

Ubuntu distributes python-pip, python3-pip, python-setuptoolsand python3-setuptoolspackages, which you can install (apt-get installetc) as necessary. Thereafter, note that pipinstalls for python 2, and pip3installs for python 3 (similar to python, and python3).

Ubuntu的分布python-pippython3-pippython-setuptoolspython3-setuptools包,您可以安装(apt-get install等)是必要的。此后,请注意pip为 python 2pip3安装,为 python 3 安装(类似于python、 和python3)。

Setuptoolscould be said to provide python's "build" process for packages, and Pipprovides its "install" process. Usually you want both present.

setuptools可以说是提供了python对包的“构建”过程,而Pip则提供了它的“安装”过程。通常你想要两个都存在。

If you want the very latest pip / setuptools, you could always get it from PyPA's bootstrap site:

如果你想要最新的 pip/setuptools,你总是可以从 PyPA 的引导站点获得它:

$ curl https://bootstrap.pypa.io/get-pip.py | python3.4

Afterwards you can install the latest setuptools for the appropriate python, e.g

之后您可以为适当的python安装最新的setuptools,例如

$ python{2.7,3.4} -m pip install -U setuptools

If you try to install these for the system python, you might need root / sudo.

如果您尝试为系统 python 安装这些,您可能需要 root / sudo

回答by Louis-Philippe Descamps

I had a similar issue when running this command on my raspberry pi

在我的树莓派上运行这个命令时我遇到了类似的问题

python3.4 -m pip install RPi.GPIO

and got this error

并得到这个错误

/usr/bin/python3.4: No module named pip

resolved it by installing python3-pip

通过安装 python3-pip 解决了它

sudo apt-get install python3-pip

回答by Zahra

curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
sudo python3 get-pip.py

confirm its installation:

确认其安装:

pip3 --version    

or

或者

python3 -m pip --version

now go ahead and install your desired packages (for example numpy) using:

现在继续numpy使用以下方法安装所需的软件包(例如):

pip3 install numpy

or

或者

python3 -m pip install numpy

Here is the reference: https://pip.pypa.io/en/stable/installing/

这是参考:https: //pip.pypa.io/en/stable/installing/

回答by Cees Timmerman

This worked on my Ubuntu 19.04:

这适用于我的 Ubuntu 19.04:

sudo apt install python3-pip

Then pip3or python3 -m pipto install python packages.

然后pip3python3 -m pip安装python包。