CentOS6.5安装python3.7

1、下载python3

  1. wget https://npm.taobao.org/mirrors/python/3.7.12/Python-3.7.12.tgz

2、解压

  1. tar -xzvf Python-3.7.12.tgz

3、先建一个编译目录

  1. mkdir /usr/local/python3

4、Python3.7版本需要一个新的包libffi-devel,安装此包之后再次进行编译安装即可。

  1. yum install -y libffi-devel

5、然后编译、安装

  1. cd Python-3.7.12
  2. ./configure --prefix=/usr/local/python3
  3. make
  4. make install
  5. 这种是带openssl模块安装的方式
  6. ./configure--prefix=/usr/local/python3 --with-openssl=/usr/local/openssl-1.1.1l

6、建立软链接:

  1. ln -s /usr/local/python3/bin/python3 /usr/bin/python3
  2. ln -s /usr/local/python3/bin/pip3 /usr/bin/pip3

7、查看版本:

  1. python3 -V

Mac安装python3.7

  1. brew install pyhton@3.7
  1. Python has been installed as
  2. /usr/local/opt/python@3.7/bin/python3
  3. Unversioned symlinks `python`, `python-config`, `pip` etc. pointing to
  4. `python3`, `python3-config`, `pip3` etc., respectively, have been installed into
  5. /usr/local/opt/python@3.7/libexec/bin
  6. You can install Python packages with
  7. /usr/local/opt/python@3.7/bin/pip3 install <package>
  8. They will install into the site-package directory
  9. /usr/local/lib/python3.7/site-packages
  10. See: https://docs.brew.sh/Homebrew-and-Python
  11. python@3.7 is keg-only, which means it was not symlinked into /usr/local,
  12. because this is an alternate version of another formula.
  13. If you need to have python@3.7 first in your PATH, run:
  14. echo 'export PATH="/usr/local/opt/python@3.7/bin:$PATH"' >> ~/.zshrc
  15. For compilers to find python@3.7 you may need to set:
  16. export LDFLAGS="-L/usr/local/opt/python@3.7/lib"
  17. For pkg-config to find python@3.7 you may need to set:
  18. export PKG_CONFIG_PATH="/usr/local/opt/python@3.7/lib/pkgconfig"

pip pip3 替换国内镜像源

Linux 或者Mac环境替换镜像源

1、创建配置文件

  1. ~/.pip/pip.conf
  2. mkdir -p ~/.pip
  3. touch ~/.pip/pip.conf

2、pip.conf文件内容

  1. [global]
  2. timeout = 10
  3. index-url = http://mirrors.aliyun.com/pypi/simple/
  4. extra-index-url = https://pypi.org/simple/pip/
  5. [install]
  6. trusted-host = mirrors.aliyun.com

遇到的问题

SSLError

pip3报错安装python3.7.0后发现使用pip会出现如下报错:

https://blog.csdn.net/lkgCSDN/article/details/84403329 https://www.jianshu.com/p/8e476eef43f7

  1. pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available.
  2. Collecting virtualenv
  3. 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/virtualenv/
  4. 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/virtualenv/
  5. 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/virtualenv/
  6. 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/virtualenv/
  7. 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/virtualenv/
  8. Could not fetch URL https://pypi.org/simple/virtualenv/: There was a problem confirming the ssl certificate: HTTPSConnectionPool(host='pypi.org', port=443): Max retries exceeded with url: /simple/virtualenv/ (Caused by SSLError("Can't connect to HTTPS URL because the SSL module is not available.")) - skipping
  9. Could not find a version that satisfies the requirement virtualenv (from versions: )
  10. No matching distribution found for virtualenv
  11. pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available.
  12. 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

这时候需要升级系统的openssl:升级openssl
升级完毕重新编译安装 ./configure--prefix=/usr/local/python3 --with-openssl=/usr/local/openssl