On CentOS6, the yum installation tool is based on Python 2.6.6, so the default installation on CentOS6 is Python 2.6.6, because the production environment is deployed on the server system for CentOS6, but the code is written based on Python 2.7, and all problems are encountered.
explore
After finding that the system cannot uninstall Python 2.6, check the system version number
cat /etc/*-release
I found that the system version is CentOS6, so I started Google search to solve it.
Solution
Reinstall Python 2.7 manually
Preparation phase
# 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
Install Python
Download python2.7 and install
# Get Python 2.7.14: wget /ftp/python/2.7.14/Python-2.7. tar xf Python-2.7. cd Python-2.7.14 ./configure --prefix=/usr/local --enable-unicode=ucs4 --enable-shared LDFLAGS="-Wl,-rpath /usr/local/lib" make && make altinstall
Install Pip
# First get the script: wget / # Then execute it using Python 2.7 python2.7 # With pip installed you can now do things like this: pip2.7 install [packagename] pip2.7 install --upgrade [packagename] pip2.7 uninstall [packagename]
Create a virtual environment
Finally, you can use venv to create a virtual environment (after all, you cannot uninstall Python 2.6)
# Install virtualenv for Python 2.7 and create a sandbox called my27project: pip2.7 install virtualenv virtualenv my27project Try it? # 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
Summarize
The above is the solution to install Python 2.7 on CentOS6 that the editor introduced to you. I hope it will be helpful to you. If you have any questions, please leave me a message and the editor will reply you in time. Thank you very much for your support for my website!