使用14.04的pip问题

Trusty Tahr (长期支持)
回复
头像
sh42
帖子: 97
注册时间: 2011-05-01 20:18
送出感谢: 3 次
接收感谢: 0

使用14.04的pip问题

#1

帖子 sh42 » 2018-05-08 11:41

各位好,我是python新手。我在我机器上安装了pip和python,python好像安装了好几个版本,有3.6.1和3.4,我运行pip的时候弹出这个东西,不知道什么意思,请各位指点。谢谢!

luhang@hive:~$ pip --version
Traceback (most recent call last):
File "/usr/local/bin/pip", line 6, in <module>
from pkg_resources import load_entry_point
File "/usr/local/lib/python3.4/dist-packages/pkg_resources/__init__.py", line 3036, in <module>
@_call_aside
File "/usr/local/lib/python3.4/dist-packages/pkg_resources/__init__.py", line 3020, in _call_aside
f(*args, **kwargs)
File "/usr/local/lib/python3.4/dist-packages/pkg_resources/__init__.py", line 3049, in _initialize_master_working_set
working_set = WorkingSet._build_master()
File "/usr/local/lib/python3.4/dist-packages/pkg_resources/__init__.py", line 654, in _build_master
ws.require(__requires__)
File "/usr/local/lib/python3.4/dist-packages/pkg_resources/__init__.py", line 968, in require
needed = self.resolve(parse_requirements(requirements))
File "/usr/local/lib/python3.4/dist-packages/pkg_resources/__init__.py", line 854, in resolve
raise DistributionNotFound(req, requirers)
pkg_resources.DistributionNotFound: The 'pip==1.5.4' distribution was not found and is required by the application
头像
sh42
帖子: 97
注册时间: 2011-05-01 20:18
送出感谢: 3 次
接收感谢: 0

Re: 使用14.04的pip问题

#2

帖子 sh42 » 2018-05-08 11:43

在线等。追加个问题,怎么设置默认的python版本呢,我看我系统里稀里糊涂装了python2.7.6 python3.6.1和python3.4,pip和python版本怎么对应起来。
头像
astolia
论坛版主
帖子: 3202
注册时间: 2008-09-18 13:11
送出感谢: 1 次
接收感谢: 538 次

Re: 使用14.04的pip问题

#3

帖子 astolia » 2018-05-08 11:54

先把你装的都删掉。再用系统源里自带的
sudo apt-get install --reinstall python3.4 python3-pip
头像
astolia
论坛版主
帖子: 3202
注册时间: 2008-09-18 13:11
送出感谢: 1 次
接收感谢: 538 次

Re: 使用14.04的pip问题

#4

帖子 astolia » 2018-05-08 11:58

不要改默认版本,你要用python2.7.x的就运行python2.7,python3.4的就运行python3.4。
.py里的shebang也写成 #!/usr/bin/python2.7这样带上版本号
这些用户感谢了作者 astolia 于这个帖子:
sh42 (2018-05-08 12:06)
评价: 3.7%
头像
sh42
帖子: 97
注册时间: 2011-05-01 20:18
送出感谢: 3 次
接收感谢: 0

Re: 使用14.04的pip问题

#5

帖子 sh42 » 2018-05-08 12:05

astolia 写了:不要改默认版本,你要用python2.7.x的就运行python2.7,python3.4的就运行python3.4。
.py里的shebang也写成 #!/usr/bin/python2.7这样带上版本号
感谢回复。按照您的说法,pip -v没有问题了,但是运行其他程序还是有问题:
luhang@hive:~$ jupyter notebook
Traceback (most recent call last):
File "/usr/local/bin/jupyter", line 6, in <module>
from pkg_resources import load_entry_point
File "/usr/local/lib/python3.4/dist-packages/pkg_resources/__init__.py", line 3036, in <module>
@_call_aside
File "/usr/local/lib/python3.4/dist-packages/pkg_resources/__init__.py", line 3020, in _call_aside
f(*args, **kwargs)
File "/usr/local/lib/python3.4/dist-packages/pkg_resources/__init__.py", line 3049, in _initialize_master_working_set
working_set = WorkingSet._build_master()
File "/usr/local/lib/python3.4/dist-packages/pkg_resources/__init__.py", line 654, in _build_master
ws.require(__requires__)
File "/usr/local/lib/python3.4/dist-packages/pkg_resources/__init__.py", line 968, in require
needed = self.resolve(parse_requirements(requirements))
File "/usr/local/lib/python3.4/dist-packages/pkg_resources/__init__.py", line 854, in resolve
raise DistributionNotFound(req, requirers)
pkg_resources.DistributionNotFound: The 'decorator' distribution was not found and is required by traitlets

我打印了一下which python3和which python:
luhang@hive:~$ which python
/usr/bin/python
luhang@hive:~$ which python3
/usr/local/bin/python3
发现python3默认的是python3.6,在/usr/local/bin/python3这个link。而python3.4是在/usr/bin/python3这个link,我直觉感觉,是不是把默认的python3改成指向3.4就行了。别的程序还要用3.6我就没删除
回复

回到 “Ubuntu 14.04 LTS”