Ubuntu16.04自带Python2.7和Python3,为什么用pip安装的包在Python3中不能用
来源:互联网 发布:小米笔记本装mac系统 编辑:程序博客网 时间:2024/05/22 02:01
问题描述:
在Ubuntu16.04中,我一直是用pip来安装Python所需的包的,今天我用Python3时,报错:提示说包不存在!!!我在想,这是为什么呢?我不是已经用pip安装过包了吗,为什么在Python3中提示没有安装包???
探索过程:
Ubuntu16.04自带的Python两个版本:
我在ipython3中导入numpy 包时报错:
既然提示我没有这个包,那么我就安装这个包,
提示说这个包已经安装了,我切换到Python3的这个文件夹下面的dist-packages目录下,发现下面时空的;这时我产生一个想法,既然都是Python的包,那么我能不能把Python2.7安装的包,即Python2.7下的dist-packages这个文件夹直接复制到Python3中,这样不就可以用了吗,于是我这样做了,
复制完后,我再次在ipython3中导入numpy这个包
发现再次报错!!!
查找资料发现,Python2.7安装包时是用pip安装的,然而,Python3安装包时,需要用pip3来安装,
分别显示各自的pip list和pip3 list
Ubuntu默认Python为2.7,所以安装Python包时安装的为py2的包。
在py2下执行pip install xxx命令安装的是py2对应的安装包,系统会自动选择下载。
所以要是想在Python3中用包,需要用pip3 install xxx,来安装Python3的包。这样问题就得到了解决,
I ran into this issue myself recently and found that I wasn't getting the right pip for Python 3, on my Linux system that also has Python 2.
First you must ensure that you have installed pip for your python version:
For Python 2:
sudo apt-get install python-pip
For Python 3:
sudo apt-get install python3-pip
Then to install packages for one version of Python or the other, simply use the following for Python 2:
pip install <package>
or for Python 3:
pip3 install <package>
pip is also a python package. So the easiest way to install modules to a specific python version would be below
python2.7 /usr/bin/pip install foo
or
python2.7 -m pip install foo
阅读全文
0 0
- Ubuntu16.04自带Python2.7和Python3,为什么用pip安装的包在Python3中不能用
- Ubuntu16.04默认安装了Python2和Python3的版本
- 在python3中安装python2的包(比如builtwith)
- Ubuntu16.04 下同时使用 Python2 和 Python3 及对应的 pip 的方法
- python2和Python3的同时安装的pip的解决
- python2和python3同时在windows下pip的使用
- 同时安装python2和python3的pip使用问题
- 同时安装python2.x和python3.x用pip
- ubuntu16.04如何同时安装python2和python3
- ubuntu16.04 Python2和Python3同时存在安装flask框架
- centos中python2.7及pip的安装(python3的安装方法类似)
- 在ubuntu16.04中安装python3.6.3和pip3.6
- python3中builtwith包不能用怎么办
- ubuntu下安装python3.5(系统默认自带的是python2.7)
- Ubuntu16.04 python2.7升级python3.5
- Ubuntu16.04 python2.7升级python3.5
- win下pip在python2和python3兼容性配置
- Debian8下python3和python2同时安装如何使用pip
- DIV在100%下iframe宽度高度的自适应的问题
- 洛谷 P1074 靶形数独
- os_time.c
- 前端性能优化之视频优化方法
- QML中鼠标拖动移动ListView中项的位置
- Ubuntu16.04自带Python2.7和Python3,为什么用pip安装的包在Python3中不能用
- JAVA注解说明及应用实例
- 【leetcode】20. Valid Parentheses(Python & C++)
- BMP格式-dephi
- Nginx+Tomcat搭建负载均衡
- 天地图按照官方教程闪退的问题
- jQuery选择器
- @ModelAttribute
- arcgis rest server动态图层管理