# Start by making sure your system is up-to-date:yumupdate# Compilers and related tools: 这步可选,见注释yumgroupinstall-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:yuminstall-ywget
Profile guided optimization (PGO) 和 Link Time Optimization (LTO)是GCC实现的编译优化,虽然在编译程序时速度较慢,但是可以明显提升程序启动速度(可能有10~20%)。
上述安装完成后,就可以通过python2.7来使用最新的2.7.14版本Python。
安装升级pip
# First get the script:wgethttps://bootstrap.pypa.io/get-pip.py# Then execute it using Python 2.7 and/or Python 3.6:python2.7get-pip.pypython3.6get-pip.py# With pip installed you can now do things like this:pip2.7install [packagename]pip2.7install--upgrade [packagename]pip2.7uninstall [packagename]
安装虚拟环境virtualenv
# Install virtualenv for Python 2.7 and create a sandbox called "venv2"pip2.7installvirtualenvvirtualenvvenv2# Activate the venv2 sandbox:sourcevenv2/bin/activate# Check the Python version in the sandbox (it should be Python 2.7.14):python--version# Deactivate the sandbox:deactivate
这里在CentOS 5上执行pip2.7 install virtualenv出现报错
/usr/local/bin/pip2.7: line 4: import: command not found
/usr/local/bin/pip2.7: line 5: import: command not found
/usr/local/bin/pip2.7: line 7: from: command not found
/usr/local/bin/pip2.7: line 10: syntax error near unexpected token `('
/usr/local/bin/pip2.7: line 10: ` sys.argv[0] = re.sub(r'(-script\.pyw?|\.exe)?$', '', sys.argv[0])'