文章目录
- 一、pip安装过程太慢咋整
- 二、pip的默认安装目录在哪里?
- 二、如何用pip查看有哪些可以安装的版本
- 三、CentOS如何升级Python2.6到Python2.7并安装pip
- 四、pip install tensorflow报错
- 五、pip install 报错——“ValueError: invalid literal for int() with base 10“
- 六:pip install BTrees报错
- 七、pip install fasttext报错
- 八、pip install numpy报错
- 九、报错:ImportError: cannot import name ‘_argmax‘
- 十、pip install jupyter_contrib_nbextensions报错
- 十一、pip install --upgrade pip报错
一、pip安装过程太慢咋整
方法一:每次输入都加上国内镜像源的参数” -i https://pypi.tuna.tsinghua.edu.cn/simple“,例如
pip install torch -i https://pypi.tuna.tsinghua.edu.cn/simple
方法二:一劳永逸,直接修改配置
-
在用户根目录下创建目录.pip【如果这个目录不存在,创建:mkdir ~/.pip】,然后在这个目录下创建文件 pip.conf 。
-
在pip.conf文件中添加如下内容:
[global]
index-url = https://pypi.tuna.tsinghua.edu.cn/simple
[install]
trusted-host = https://pypi.tuna.tsinghua.edu.cn
二、pip的默认安装目录在哪里?
- 如果你用的是独立的pip,那么默认安装目录为:
~/.cache/pip
- 如果你用的是anaconda下面的pip,那么默认安装目录为:
/path_to/anaconda3/envs/your_name/lib/python3.10/site-packages/
二、如何用pip查看有哪些可以安装的版本
例如想看看scikit-learn有哪些版本可安装:
pip index versions scikit-learn
三、CentOS如何升级Python2.6到Python2.7并安装pip
貌似CentOS 6.X系统默认安装的Python都是2.6版本的?平时使用以及很多的库都是要求用到2.7版本或以上,所以新系统要做的第一件事必不可少就是升级Python啦!在这里做个简单的升级操作记录
yum -y update
yum install epel-release
yum install sqlite-devel
yum install -y zlib-devel.x86_64
yum install -y openssl-devel.x86_64
- 升级Python
系统默认安装的Python是2.6.6的,我们需要升级到Python2.7,用wget命令从官方下载源文件,然后解压进行编译
wget http://www.python.org/ftp/python/2.7.10/Python-2.7.10.tar.xz
unxz Python-2.7.10.tar.xz
tar -vxf Python-2.7.10.tar
执行完以上命令会解压得到Python-2.7.10这个文件夹,进入该目录并执行以下命令进行配置
./configure --enable-shared --enable-loadable-sqlite-extensions --with-zlib
其中–enable-loadable-sqlite-extensions是sqlite的扩展,如果需要使用的话则带上这个选项。之后执行
vi ./Modules/Setup
找到#zlib zlibmodule.c -I ( p r e f i x ) / i n c l u d e − L (prefix)/include -L (prefix)/include−L(exec_prefix)/lib -lz去掉注释并保存,然后进行编译和安装
make && make install
安装好Python2.7之后我们需要先把Python2.6备份起来,然后再对yum的配置进行修改,如果不进行这一步操作的话,执行yum命令将会提示你Python的版本不对。
执行以下命令,对Python2.6进行备份,然后为Python2.7创建软链接
mv /usr/bin/python /usr/bin/python2.6.6
ln -s /usr/local/bin/python2.7 /usr/bin/python
然后编辑/usr/bin/yum,将第一行的#!/usr/bin/python修改成#!/usr/bin/python2.6.6
现在执行yum命令已经不会出现之前的错误信息了。
我们执行python -V查看版本信息,如果出现错误
error while loading shared libraries: libpython2.7.so.1.0: cannot open shared object file: No such file or directory
编辑配置文件
vi /etc/ld.so.conf
添加新的一行内容/usr/local/lib,保存退出,然后
/sbin/ldconfig
/sbin/ldconfig -v
- 安装pip
下载最新版的pip,然后安装
wget https://bootstrap.pypa.io/get-pip.py
python get-pip.py
查找pip的位置
whereis pip
找到pip2.7的路径,为其创建软链作为系统默认的启动版本
ln -s /usr/local/bin/pip2.7 /usr/bin/pip
pip安装完毕,现在可以用它下载安装各种包了 😃
四、pip install tensorflow报错
pip install tensorflow==1.10.0始终报错
报错信息如下:
distutils.errors.CompileError: command 'gcc' failed with exit status 1
Failed building wheel for grpcio
解决办法:
pip install --upgrade pip
然后再执行:pip install tensorflow==1.10.0
五、pip install 报错——“ValueError: invalid literal for int() with base 10“
File "/usr/lib64/python2.7/urlparse.py", line 117, in port
port = int(port, 10)
ValueError: invalid literal for int() with base 10: ''
解决办法:
在urlparse.py代码中新增下面两行代码:
六:pip install BTrees报错
报错现象:
Looking in indexes: https://pypi.tuna.tsinghua.edu.cn/simple
ERROR: Could not find a version that satisfies the requirement BTrees==4.9.2 (from versions: none)
ERROR: No matching distribution found for BTrees==4.9.2
解决办法:
pip install BTrees==4.9.2 -i http://pypi.douban.com/simple/ --trusted-host pypi.douban.com
七、pip install fasttext报错
报错现象:
error: command '/usr/local/bin/gcc' failed with exit code 1
----------------------------------------
ERROR: Command errored out with exit status 1:
解决办法:
sudo yum install centos-release-scl
sudo yum install scl-utils-build
sudo yum install devtoolset-9
scl enable devtoolset-9 bash
pip install fasttext
八、pip install numpy报错
error: ‘for’ loop initial declarations are only allowed in C99 mode#
报错现象:
解决办法:
在命令中输入
export CFLAGS='-std=c99'
然后重新pip install numpy即可
九、报错:ImportError: cannot import name ‘_argmax‘
解决办法:
pip install scikit-learn==0.19.1
十、pip install jupyter_contrib_nbextensions报错
报错信息:
Cannot uninstall 'terminado'. It is a distutils installed project and thus we cannot accurately determine which files belong to it which would lead to only a partial uninstall.
解决办法:
pip install terminado==0.9.1 --user --ignore-installed
十一、pip install --upgrade pip报错
执行命令
pip install --upgrade pip
错误信息如下:
Could not fetch URL https://pypi.tuna.tsinghua.edu.cn/simple/pip/:
There was a problem confirming the ssl certificate:
[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:777) - skipping
解决办法:
pip --trusted-host pypi.python.org --trusted-host pypi.tuna.tsinghua.edu.cn install --upgrade pip -i https://pypi.tuna.tsinghua.edu.cn/simple/
- 参考文献
- http://ruter.sundaystart.net/2015/12/03/Update-python/