在CentOS6上yum安裝工具是基于Python2.6.6的,所以在CentOS6上默認安裝的是Python2.6.6,因為要在服務器系統(tǒng)為CentOS6上部署生產環(huán)境,但是代碼都是基于Python2.7寫的,所有遇到了問題。
探索
發(fā)現(xiàn)系統(tǒng)不能卸載Python2.6后,查了系統(tǒng)的版本號
cat /etc/*-release
發(fā)現(xiàn)系統(tǒng)版本為CentOS6,于是開始Google搜索怎么解決。
解決辦法
重新手動裝一個Python2.7
準備階段
# Start by making sure your system is up-to-date:yum update# Compilers and related tools:yum groupinstall -y "development tools"# Libraries needed during compilation to enable all features of Python:yum install -y zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel expat-devel# If you are on a clean "minimal" install of CentOS you also need the wget tool:yum install -y wget
安裝Python
下載python2.7并安裝
# Get Python 2.7.14:wget http://python.org/ftp/python/2.7.14/Python-2.7.14.tar.xztar xf Python-2.7.14.tar.xzcd Python-2.7.14./configure --prefix=/usr/local --enable-unicode=ucs4 --enable-shared LDFLAGS="-Wl,-rpath /usr/local/lib"make && make altinstall
安裝Pip
# First get the script:wget https://bootstrap.pypa.io/get-pip.py# Then execute it using Python 2.7python2.7 get-pip.py# With pip installed you can now do things like this:pip2.7 install [packagename]pip2.7 install --upgrade [packagename]pip2.7 uninstall [packagename]
創(chuàng)建虛擬環(huán)境
最后可以利用venv創(chuàng)建一個虛擬環(huán)境(畢竟Python2.6你不能卸載)
# Install virtualenv for Python 2.7 and create a sandbox called my27project:pip2.7 install virtualenvvirtualenv my27project試一下?# Check the system Python interpreter version:python --version# This will show Python 2.6.6# Activate the my27project sandbox:source my27project/bin/activate# This will show Python 2.7.4python --version
總結
以上所述是小編給大家介紹的在CentOS6上安裝Python2.7的解決方法,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復大家的。在此也非常感謝大家對武林站長站網(wǎng)站的支持!
新聞熱點
疑難解答