centos python 2.7 安装
一开始有这个需求,是因为用 YaH3C 替代 iNode 进行校园网认证时,一直编译错误,提示找不到 Python 的某个模块,百度了一下,此模块是在 Python2.7 以上才有的,但是系统的自带的Python是2.6版本,难怪一直连不上网。于是,继续百度google,进行安装,后来又出现问题...在此开篇记录一下,权当备忘。
python2.7安装
探测机操作 升级python2.6到2.7 复制粘贴执行 cd /home/work/prober/src/lib/thirdparty yum install xz unzip libcurl-devel zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gcc make -y wget https://www.python.org/ftp/python/2.7.9/Python-2.7.9.tar.xz tar xf Python-2.7.9.tar.xz cd Python-2.7.9 ./configure make all make install make clean make distclean /usr/local/bin/python2.7 -V mv /usr/bin/python /usr/bin/python2.6.6 ln -s /usr/local/bin/python2.7 /usr/bin/python cd .. 修改yum vi /usr/bin/yum 将文件头部的 #!/usr/bin/python 改成 #!/usr/bin/python2.6.6 安装setuptool pip 复制粘贴执行 https://pypi.python.org/pypi/setuptools页面最下面的有它的安装链接 cd /home/work/prober/src/lib/thirdparty wget --no-check-certificate https://pypi.python.org/packages/source/s/setuptools/setuptools-12.0.3.tar.gz#md5=f07e4b0f4c1c9368fcd980d888b29a65 tar xvf setuptools-12.0.3.tar.gz cd setuptools-12.0.3 python setup.py install cd .. wget --no-check-certificate https://pypi.python.org/packages/41/27/9a8d24e1b55bd8c85e4d022da2922cb206f183e2d18fee4e320c9547e751/pip-8.1.1.tar.gz#md5=6b86f11841e89c8241d689956ba99ed7 tar -xzf pip-8.1.1.tar.gz cd pip-8.1.1 python setup.py install cd .. # 升级pip python -m pip install --upgrade pip
查看python的版本
python3.6安装
yum search python3 | grep devel
[root@localhost ~]# yum search python3 | grep devel python3-devel.aarch64 : Libraries and header files needed for Python development python3-idle.aarch64 : A basic graphical development environment for Python
echo "source `which activate.sh`" >> ~/.bashrc yum install perl-Digest-SHA source ~/.bashrc
yum install xz unzip libcurl-devel zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gcc make -y
yum -y install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel libffi-devel
yum install mysql-devel python-devel zlib-devel cd /home/liujianzuo wget https://www.python.org/ftp/python/3.8.0/Python-3.8.0a1.tar.xz tar xf Python-3.8.0a1.tar.xz
cd Python-3.8.0a1 ./configure --prefix=/home/liujianzuo/python3.8 --enable-optimizations make make install make clean wget https://files.pythonhosted.org/packages/1d/64/a18a487b4391a05b9c7f938b94a16d80305bf0369c6b0b9509e86165e1d3/setuptools-41.0.1.zip
unzip setuptools-41.0.1.zip cd setuptools-41.0.1 /home/liujianzuo/python3.8/bin/python3 setup.py install cd .. wget --no-check-certificate https://files.pythonhosted.org/packages/8b/8a/1b2aadd922db1afe6bc107b03de41d6d37a28a5923383e60695fba24ae81/pip-19.2.1.tar.gz
tar xf pip-19.2.1.tar.gz cd pip-19.2.1
/home/liujianzuo/python3.8/bin/python3 setup.py install
/home/liujianzuo/python3.8/bin/python3 -m pip install --upgrade pip /home/liujianzuo/python3.8/bin/python3 -m pip install virtualenv cd /home/work/probe_api /home/liujianzuo/python3.8/bin/python3 /home/liujianzuo/python3.8/bin/virtualenv --no-site-packages -p /home/liujianzuo/python3.8/bin/python venv #在项目下面创建虚拟目录 source venv/bin/activate /home/work/probe_api/venv/bin/pip install -r requirements.txt /home/liujianzuo/python3.8/bin/python3 -m pip install autoenv echo "source /home/liujianzuo/python3.8/bin/activate.sh" >> ~/.bashrc # 我的mac下 echo "source /Library/Frameworks/Python.framework/Versions/3.7/bin/activate.sh" >> ~/.zshrc source ~/.bashrc yum install perl-Digest-SHA cat <<eof >.env if [[ -e venv/bin/activate ]] then source venv/bin/activate fi eof
virtualenv --no-site-packages -p /home/liujianzuo/python2.79/bin/python venv
- #python -V
- Python 2.6.6
1.下载Python-2.7.3
- #wget http://python.org/ftp/python/2.7.3/Python-2.7.3.tar.bz2
2.解压
- #tar -jxvf Python-2.7.3.tar.bz2
3.更改工作目录
- #cd Python-2.7.3
4.安装
- #./configure
- #make all
- #make install
- #make clean
- #make distclean
5.查看版本信息
- #/usr/local/bin/python2.7 -V
6.建立软连接,使系统默认的 python指向 python2.7
- #mv /usr/bin/python /usr/bin/python2.6.6
- #ln -s /usr/local/bin/python2.7 /usr/bin/python
7.重新检验Python 版本
- #python -V
8解决系统 Python 软链接指向 Python2.7 版本后,因为yum是不兼容 Python 2.7的,所以yum不能正常工作,我们需要指定 yum 的Python版本
- #vi /usr/bin/yum
将文件头部的
#!/usr/bin/python
改成
#!/usr/bin/python2.6.6
http://www.zhangchun.org/the-centos6-3-upgrade-python-to-2-7-3-
这篇教程就到这里了,但是不久就突然发现输入法图标不见了,然后打字没有候选框!iBus 崩了!再次进行搜索,又是版本问题 iBus也是不支持Python2.7的啊!
于是。。。
9.配置iBus
分别用 vi 打开下面两个文件,找到 exec python 那一行,把exec python 改为 exec python2.6 保存,退出。iBus在重启后就恢复正常了!是不是很开心?
- #vi /usr/bin/ibus-setup
- #vi/usr/libexec/ibus-ui-gtk