linux安装python环境和pip

新版本安装文档(更新与2020-09-02)

可选:提前安装相关包

yum install gcc zlib zlib-devel openssl openssl-devel -y
# 此处地址是公司文件服务地址 请自行更换
wget http://124.239.180.94/file/Python-3.6.9.tgz
# 官网下载地址:https://www.python.org/ftp/python/3.8.5/Python-3.8.5.tar.xz
# 解压
tar xf Python-3.6.9.tgz
#进入目录 执行
cd Python-3.6.9;./configure
#报错:
checking for cl.exe... no
configure: error: in `/root/Python-3.6.9':
configure: error: no acceptable C compiler found in $PATH
See `config.log' for more details
# 解决:
yum install gcc -y
#执行
./configure
# 完成
config.status: creating Misc/python.pc
config.status: creating Misc/python-config.sh
config.status: creating Modules/ld_so_aix
config.status: creating pyconfig.h
creating Modules/Setup
creating Modules/Setup.local
creating Makefile


If you want a release build with all stable optimizations active (PGO, etc),
please run ./configure --enable-optimizations
# 编译安装
make && make install
# 错误
Traceback (most recent call last):
  File "/root/Python-3.6.9/Lib/runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "/root/Python-3.6.9/Lib/runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "/root/Python-3.6.9/Lib/ensurepip/__main__.py", line 5, in <module>
    sys.exit(ensurepip._main())
  File "/root/Python-3.6.9/Lib/ensurepip/__init__.py", line 204, in _main
    default_pip=args.default_pip,
  File "/root/Python-3.6.9/Lib/ensurepip/__init__.py", line 117, in _bootstrap
    return _run_pip(args + [p[0] for p in _PROJECTS], additional_paths)
  File "/root/Python-3.6.9/Lib/ensurepip/__init__.py", line 27, in _run_pip
    import pip._internal
zipimport.ZipImportError: can't decompress data; zlib not available
make: *** [install] Error 1
# 解决
yum install zlib zlib-devel -y
# 完成
Looking in links: /tmp/tmppl7j8p7c
Collecting setuptools
Collecting pip
Installing collected packages: setuptools, pip
Successfully installed pip-18.1 setuptools-40.6.2

pip安装

# 官网
https://pypi.org/search/?q=pip
# 下载
wget https://files.pythonhosted.org/packages/73/8e/7774190ac616c69194688ffce7c1b2a097749792fea42e390e7ddfdef8bc/pip-20.2.2.tar.gz
# 解压
tar xf pip-20.2.2.tar.gz
##### 注意! 使用Python3命令安装的pip就是Python3的,不要使用Linux自带的Python命令,因为他是Python2,在centos8版本前linux自带Python都是2
python3 setup.py install
# 完成
creating /usr/local/lib/python3.6/site-packages/pip-20.2.2-py3.6.egg
Extracting pip-20.2.2-py3.6.egg to /usr/local/lib/python3.6/site-packages
Adding pip 20.2.2 to easy-install.pth file
Installing pip script to /usr/local/bin
Installing pip3 script to /usr/local/bin
Installing pip3.6 script to /usr/local/bin

Installed /usr/local/lib/python3.6/site-packages/pip-20.2.2-py3.6.egg
Processing dependencies for pip==20.2.2
Finished processing dependencies for pip==20.2.2
# 如果有问题百度,一般多为少包,yum安装重新编译安装即可.
[root@localhost pip-20.2.2]# pip -V
pip 20.2.2 from /usr/local/lib/python3.6/site-packages/pip-20.2.2-py3.6.egg/pip (python 3.6)

安装完成执行pip install [包名],遇到以下错误

[root@localhost pip-20.2.2]# pip install pip -U
WARNING: pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available.
WARNING: Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError("Can't connect to HTTPS URL because the SSL module is not available.",)': /simple/pip/
WARNING: Retrying (Retry(total=3, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError("Can't connect to HTTPS URL because the SSL module is not available.",)': /simple/pip/
WARNING: Retrying (Retry(total=2, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError("Can't connect to HTTPS URL because the SSL module is not available.",)': /simple/pip/
WARNING: Retrying (Retry(total=1, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError("Can't connect to HTTPS URL because the SSL module is not available.",)': /simple/pip/
WARNING: Retrying (Retry(total=0, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError("Can't connect to HTTPS URL because the SSL module is not available.",)': /simple/pip/
Could not fetch URL https://pypi.org/simple/pip/: There was a problem confirming the ssl certificate: HTTPSConnectionPool(host='pypi.org', port=443): Max retries exceeded with url: /simple/pip/ (Caused by SSLError("Can't connect to HTTPS URL because the SSL module is not available.",)) - skipping
Requirement already up-to-date: pip in /usr/local/lib/python3.6/site-packages/pip-20.2.2-py3.6.egg (20.2.2)
WARNING: pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available.

解决:

yum install openssl openssl-devel -y
# 重新编译安装Python及pip

更换清华源

pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple

旧版本

下载

wget https://www.python.org/ftp/python/3.5.0/Python-3.5.0.tar.xz

解压

tar xvf Python-3.5.0.tar.xz
cd Python-3.5.0

指定路径安装

./configure --prefix=/usr/local/python3
make
make install

建立软连接

#不要覆盖原来版本的链接,所以最好起名python3

ln -s /usr/local/python3/bin/python3 /usr/bin/python3

测试

python

二.安装pip

首先安装setuptools

yum install zlib-devel

从新编译python3

cd /usr/local/python3

make

make install
#执行这一步遇上一个错误,内容如下

[root@liulao Python-3.5.0]# ./configure --prefix=/usr/local/python3
checking build system type... x86_64-unknown-linux-gnu
checking host system type... x86_64-unknown-linux-gnu
checking for --enable-universalsdk... no
checking for --with-universal-archs... no
checking MACHDEP... linux
checking for --without-gcc... no
checking for gcc... no
checking for cc... no
checking for cl.exe... no
configure: error: in `/HelloWorld/Python-3.5.0':
configure: error: no acceptable C compiler found in $PATH
See `config.log' for more details

缺少一些软件包
yum 下载
yum install -y cc gcc cl.exe without-gcc with-universal-archs enable-universalsdk
#反正我装好之后就可以了

下载安装setuptools

wget –no-check-certificate https://pypi.python.org/packages/source/s/setuptools/setuptools-19.6.tar.gz#md5=c607dd118eae682c44ed146367a17e26

tar -zxvf setuptools-19.6.tar.gz

cd setuptools-19.6

python3 setup.py build

python3 setup.py install

安装pip

wget –no-check-certificate https://pypi.python.org/packages/source/p/pip/pip-8.0.2.tar.gz#md5=3a73c4188f8dbad6a1e6f6d44d117eeb

tar -zxvf pip-8.0.2.tar.gz

cd pip-8.0.2

python3 setup.py build

python3 setup.py install

如果报错。可能是缺少环境

yum install openssl-devel #完成后从新编译python3

建立软连接

ln -s /usr/local/python3/bin/pip /usr/bin/pip

测试

输入python3

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值