安装python | python2.7.12一键脚本 & python3.6.0一键脚本。
最近因为有几个应用需要用到Python,作为折腾了一下安装Python。
- 安装
- 使用
- 其他(一键脚本)
安装
- 安装python2.7.x
①秋大的
CentOS 6.8安装Python2.7.13 | 秋水逸冰 https://teddysun.com/473.html
备份页
②fazero博客的一键脚本(方便)
Centos升级Python 2.7.12并安装最新pip | fazero https://blog.fazero.me/2016/10/13/centos-update-python/
备份页
具体自己查看。
- 安装python3.x
注意:文中有几处 - 减号,由于格式/或编码问题,会显示错,请自行更改。
另外为了减少折腾,请先安装必需包
centos:
yum install -y zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel gcc
Debian/Ubuntu:
apt-get install -y zlib1g-dev gcc make libssl-dev openssl libreadline-dev
使用
在使用过程中,遇到一些问题,只是小白的我,只能一步一步找办法解决。
问题一:python2.7中使用pip出现
Exception:
Traceback (most recent call last):
File "/usr/local/python2.7.12/lib/python2.7/site-packages/pip/basecommand.py", line 215, in main
....................
File "/usr/local/python2.7.12/lib/python2.7/site-packages/pkg_resources/__init__.py", line 1577, in _get
with open(path, 'rb') as stream:
IOError: [Errno 2] No such file or directory: '/usr/local/python2.7.12/lib/python2.7/site-packages/six-1.10.0.dist-info/METADATA'
解决方法:
确保软连接创建没有错,运行python -V的版本是2.7.X
方法①:执行 (我修复成功了)
python -m pip install -U --force-reinstall pip参考:http://blog.csdn.net/scdxmoe/article/details/53504117
#安装setuptool,easy_install 命令就会被安装在 /usr/local/bin 目录下
wget https://bootstrap.pypa.io/ez_setup.py -O - | python
#为新版 Python 安装 pip
easy_install pip
#安装pip
wget --no-check-certificate https://pypi.python.org/packages/source/p/pip/pip-8.0.2.tar.gz#md5=3a73c4188f8dbad6a1e6f6d44d117eeb
tar -zxvf pip-8.0.2.tar.gz
cd pip-8.0.2
python setup.py build
python setup.py install
#如果没有意外的话,pip安装完成。
#安装setuptools
#安装pip前需要前安装setuptoolswget --no-check-certificate https://pypi.python.org/packages/source/s/setuptools/setuptools-19.6.tar.gz#md5=c607dd118eae682c44ed146367a17e26
tar -zxvf setuptools-19.6.tar.gz
cd setuptools-19.6
python setup.py build
python setup.py install
方法④:找百度,找谷歌,找老司机
问题二:
There was a problem importing one of the Python modules
required to run yum. The error leading to this problem was:
No module named yum
Please install a package which provides this module, or
verify that the module is installed correctly.
It's possible that the above module doesn't match the
current version of Python, which is:
2.7.3 (default, Nov 24 2016, 00:21:41)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-17)]
If you cannot solve this problem yourself, please go to
the yum faq at:http://yum.baseurl.org/wiki/Faq
原因:猜测yum调用了高版本的python。
解决方法:
#查看系统中的python版本(有两个)
whereis python
#返回 python: /usr/bin/python2.7 /usr/bin/python2.6 /usr/bin/python /usr/lib/python2.6 /usr/lib64/python2.6 /usr/include/python2.6 /usr/local/python2.7 /usr/share/man/man1/python.1.gz
查看Python使用中的版本
python -V
#返回Python 2.7.3
vi /usr/bin/yum
#!/usr/bin/python
改为:
#!/usr/bin/python2.6
问题三:
在ubuntu16.04上编译安装Python3.6后,使用pip出现错误
Exception:
Traceback (most recent call last):
File "/tmp/tmpglkLpE/pip.zip/pip/basecommand.py", line 215, in main
.......................................
File "/tmp/tmpglkLpE/pip.zip/pip/_vendor/distro.py", line 933, in _get_lsb_release_info
CalledProcessError: Command 'lsb_release -a' returned non-zero exit status 1
没解决,建议ubuntu16上直接使用apt-get安装
apt-get update
apt-get install -y python3 python3-pip python3-dev
其他(一键脚本):
①整理一键脚本
1)update-python2.7.12一键脚本(来自fazero博客):
适用于centos
wget http://7xpt4s.com1.z0.glb.clouddn.com/update-python2.7.12.sh && bash update-python2.7.12.sh
2)update-python3.6.0一键脚本(我仿写)
已在centos6/7、Debian7/8、Ubuntu14上测试
wget --no-check-certificate https://raw.githubusercontent.com/kmm996/update-python/master/update-python3.6.0.sh && bash update-python3.6.0.sh
②Ubuntu系统自带Python3软件包,安装pip时,注意python与python3、pip与pip3的区分
apt-get install -y python3 python3-pip python3-devpython3 -V
pip3 -V
③手动编译安装setuptools、pip3
#安装pip前需要前置安装setuptoolswget --no-check-certificate https://pypi.python.org/packages/source/s/setuptools/setuptools-19.6.tar.gz#md5=c607dd118eae682c44ed146367a17e26
tar -zxvf setuptools-19.6.tar.gz
cd setuptools-19.6
python3 setup.py build
python3 setup.py install
#安装pip
wget --no-check-certificate https://pypi.python.org/packages/11/b6/abcb525026a4be042b486df43905d6893fb04f05aac21c32c638e939e447/pip-9.0.1.tar.gz#md5=35f01da33009719497f01a4ba69d63c9
tar -zxvf pip-9.0.1.tar.gz
cd pip-9.0.1
python3 setup.py build
python3 setup.py install
#如果没有意外的话,pip安装完成。
参考:
https://blog.fazero.me/2016/10/13/centos-update-python/
http://blog.csdn.net/tjj93622/article/details/52608087
http://blog.csdn.net/scdxmoe/article/details/53504117
End、
匿名