您好,登錄后才能下訂單哦!
在CentOS6上yum安裝工具是基于Python2.6.6的,所以在CentOS6上默認安裝的是Python2.6.6,因為要在服務器系統為CentOS6上部署生產環境,但是代碼都是基于Python2.7寫的,所有遇到了問題。
探索
發現系統不能卸載Python2.6后,查了系統的版本號
cat /etc/*-release
發現系統版本為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.xz tar xf Python-2.7.14.tar.xz cd 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.7 python2.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]
創建虛擬環境
最后可以利用venv創建一個虛擬環境(畢竟Python2.6你不能卸載)
# Install virtualenv for Python 2.7 and create a sandbox called my27project: pip2.7 install virtualenv virtualenv 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.4 python --version
總結
以上所述是小編給大家介紹的在CentOS6上安裝Python2.7的解決方法,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復大家的。在此也非常感謝大家對億速云網站的支持!
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。