当前系统为阿里云的CentOS7.3 64位操作系统。
先按一般顺序操作安装Python3,如果在安装过程中缺少了什么组件再补充安装。
下载最新版本的Python3
# wget https://www.python.org/ftp/python/3.8.1/Python-3.8.1.tgz # tar -zxvf Python-3.8.1.tgz # cd Python-3.8.1.tgz # ./configure --prefix=/usr/local/python3 # make && make install
结果如下
Traceback (most recent call last): File "/root/downloads/Python-3.8.1/Lib/runpy.py", line 193, in _run_module_as_main return _run_code(code, main_globals, None, File "/root/downloads/Python-3.8.1/Lib/runpy.py", line 86, in _run_code exec(code, run_globals) File "/root/downloads/Python-3.8.1/Lib/ensurepip/__main__.py", line 5, in <module> sys.exit(ensurepip._main()) File "/root/downloads/Python-3.8.1/Lib/ensurepip/__init__.py", line 200, in _main return _bootstrap( File "/root/downloads/Python-3.8.1/Lib/ensurepip/__init__.py", line 119, in _bootstrap return _run_pip(args + [p[0] for p in _PROJECTS], additional_paths) File "/root/downloads/Python-3.8.1/Lib/ensurepip/__init__.py", line 27, in _run_pip import pip._internal File "<frozen zipimport>", line 241, in load_module File "<frozen zipimport>", line 709, in _get_module_code File "<frozen zipimport>", line 570, in _get_data zipimport.ZipImportError: can't decompress data; zlib not available make: *** [install] Error 1
执行安装编译后提示上述错误(只截取了一部分),根据提示安装缺少的依赖包。
# yum -y install zlib*
然后再重新安装编译。
最后提示:Successfully installed pip-19.2.3 setuptools-41.2.0。pip3也自动安装上了。
创建软连接方便使用
# ln -s /usr/local/python3/bin/pip3 /usr/bin/pip3 # ln -s /usr/local/python3/bin/python3 /usr/bin/python3
在使用“pip3 install tqdm”时,提示:
Looking in indexes: http://mirrors.aliyun.com/pypi/simple/ Requirement already satisfied: tqdm in /usr/local/python3/lib/python3.8/site-packages (4.42.1) WARNING: You are using pip version 19.2.3, however version 20.0.2 is available. You should consider upgrading via the 'pip install --upgrade pip' command.
执行“pip install --upgrade pip”后,可以成功升级,不过pip3的软连接没有了。该操作是给python2.7的pip升级的。
# pip3 -V -bash: /usr/bin/pip3: No such file or directory
执行"pip3 install --upgrade pip"后,可以正确给pip3升级。
# pip3 -V pip 20.0.2 from /usr/local/python3/lib/python3.8/site-packages/pip (python 3.8)
测试pip3是否可以正确安装包。
# pip3 install pymysql Looking in indexes: http://mirrors.aliyun.com/pypi/simple/ Collecting pymysql Downloading http://mirrors.aliyun.com/pypi/packages/ed/39/15045ae46f2a123019aa968dfcba0396c161c20f855f11dea6796bcaae95/PyMySQL-0.9.3-py2.py3-none-any.whl (47 kB) |████████████████████████████████| 47 kB 1.0 MB/s Installing collected packages: pymysql Successfully installed pymysql-0.9.3
总结:由于系统版本和python版本的缘故,没有额外安装pip3,除了zlib也没有额外安装其他依赖。
来源:https://www.cnblogs.com/iverson-3/p/12289206.html