python2和3共存时pip安装的问题,python2pip,安装有python2


安装有python2和python3多版本的情况下,我们使用pip安装模块容易出问题:

[[email protected] ~]# python -m pip install psutil

Collecting psutil

Downloading psutil-5.4.1.tar.gz (408kB)

Installed /usr/local/python3/lib/python3.6/site-packages/psutil-5.4.0-py3.6-linux-x86_64.egg

Processing dependencies for psutil==5.4.0

Finished processing dependencies for psutil==5.4.0

[[email protected] psutil-5.4.0]# python

Python 3.6.3 (default, Nov 9 2017, 00:02:58)

[GCC 4.8.5 20150623 (Red Hat 4.8.5-16)] on linux

Type "help", "copyright", "credits" or "license" for more information.

>>> import psutil

Traceback (most recent call last):

File "<stdin>", line 1, in <module>

File "/root/psutil-5.4.0/psutil/__init__.py", line 93, in <module>

from . import _pslinux as _psplatform

File "/root/psutil-5.4.0/psutil/_pslinux.py", line 26, in <module>

from . import _psutil_linux as cext

ImportError: cannot import name ‘_psutil_linux‘

这个错误,并不是没有psutil模块报的错,而是因为我的系统里面装了python2和python3,所以在使用pip安装的时候,会安装到2里面,导致了这个报错

当我们安装了2和3的时候,使用pip安装模块的时候,需要在pip之前声明是2还是3

[[email protected] ~]# python -m pip install psutil#我的系统里面有python2.7和python3.6,python就是3.6版本

Collecting psutil

Downloading psutil-5.4.1.tar.gz (408kB)

.....................

97% |███████████████████████████████▎| 399kB 738kB/s eta 0:00 100% |████████████████████████████████| 409kB 539kB/s

Installing collected packages: psutil

Running setup.py install for psutil ... done

Successfully installed psutil-5.4.1

[[email protected] ~]# python

Python 3.6.3 (default, Nov 9 2017, 00:02:58)

[GCC 4.8.5 20150623 (Red Hat 4.8.5-16)] on linux

Type "help", "copyright", "credits" or "license" for more information.

>>> import psutil

>>>

我在pip前面使用python声明我当前使用的是3,而不是python2.7,这样安装就正常了.


PS:个人之见,如果有错误的地方,欢迎大家指正

本文出自 “一路向上” 博客,请务必保留此出处http://zhenghong.blog.51cto.com/1676992/1980181

python2和3共存时pip安装的问题

相关内容

    暂无相关文章

评论关闭