Yesterday, due to work needs, the python that comes with centos6.7 was upgraded to 2.7. Among them, I have encountered some small twists and turns, let me record it, and you can make a reference when you encounter similar problems.
Install readlin-devel, yum install readline-devel
The next step is to unzip: tar xvf Python-2.7.8.tgz,
Then enter Python-2.7.8, cd Python-2.7.6
To compile:
. /configure --prefix=/usr/local/python2.7
make
make install
ln -fs /usr/local/python2.7/bin/python2.7 /usr/bin/python
python –V
vi /usr/bin/yum
Modify the #!/usr/bin/python in the first line to the original python version address #!/usr/bin/python2.6
At this point, python has been upgraded. If you have used easy_install or pip to install a third-party module before, you will find that easy_install or pip cannot be used after the upgrade.
The reason is: Although you have upgraded Python to version 2.7, pip is still the original version and is still in the original python site-package. So you can copy all the things in the original /usr/lib/python2.6/site-packages to the python2.7 directory (/usr/local/python2.7/lib/python2.7/site-packages/)
cp -pr /usr/lib/python2.6/site-packages/* /usr/local/python2.7/lib/python2.7/site-packages/
Ok, now you can happily install third-party modules with pip.
yum install pip: yum install python-pip
In addition, when I installed the pillow module, I found that the python official website download was too slow, so I provided several python domestic mirror sites (fast flying).
Alibaba Cloud is the fastest https://mirrors.aliyun.com/pypi/simple/
University of Science and Technology of China https://pypi.mirrors.ustc.edu.cn/simple/
Douban https://pypi.douban.com/simple/
××× http://pypi.mirrors.opencas.cn/simple/
Tsinghua University https://pypi.tuna.tsinghua.edu.cn/simple/
Using the mirror source is very simple, just specify it with -i, for example: easy_install -i https://pypi.douban.com/simple/ pillow
Pip is the same. pip install pillow -i https://mirrors.aliyun.com/pypi/simple/
To specify the global installation source, add the following content to vim $HOME/.pip/pip.conf (if there is no such file, create one manually)
[ global]
timeout =6000
index-url = https://mirrors.aliyun.com/pypi/simple/
Pip installs multiple third-party packages at once (pip install -r requirements.txt) Write the name of the package to be installed in requirements.txt
pip list (view installed packages)
pip wheel package name (package)
If you want to install the specified version of the python package, just add == the specified version after the package. Such as pip install matplotlib==2.1.1 -i https://mirrors.aliyun.com/pypi/simple/
Note that after upgrading pip to 9.0.1, the error pkg_resources.DistributionNotFound: pip==7.1.0 is reported. The solution is as follows:
vim /usr/bin/pip Change the version behind pip== to the installed pip version
Recommended Posts