在CentOS 7上安装Python 2.7以及virtualenv环境

通过Yum安装(EPEL源)

yum -y update
yum -y install python-pip

通过pip脚本安装

  • 安装升级pip - 这个方法是通用安装pip方法,适合所有python环境

参考 PyPA » pip 20.1.1 documentation » Installation

注意:如果系统没有setuptools和wheel,则get-pip.py会自动安装

# First get the script:
curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py

# Then execute it using Python 2.7 and/or Python 3.6:
python2.7 get-pip.py
#python3.6 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]

如果系统过于陈旧,可能存在ssl证书报错:

解决方法参考 Pip: Could not fetch URL for pypi and issue confirming the ssl certificate

  • 安装虚拟环境virtualenv

我在执行 virtualenv venv2 时候遇到一个报错

这个报错原因是因为系统太陈旧,pip版本甚至无法升级

··· You are using pip version 7.1.0, however version 21.3.1 is available. You should consider upgrading via the 'pip install --upgrade pip' command. Collecting pip Using cached https://files.pythonhosted.org/packages/da/f6/c83229dcc3635cdeb51874184241a9508ada15d8baa3 37a41093fab58011/pip-21.3.1.tar.gz Complete output from command python setup.py egg_info: Traceback (most recent call last): File "", line 20, in File "/tmp/pip-build-wfciDf/pip/setup.py", line 7 def read(rel_path: str) -> str: ^ SyntaxError: invalid syntax

Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-build-wfciDf/pip

参考

Last updated

Was this helpful?