在 CentOS 7上安装并配置 Python 3.6 环境

前言

按照此方法安装保证以下报错什么的统统都没有!

基础环境

系统:centos7.4

软件:python3

Retrying (Retry(total=0, connect=None, read=None, redirect=None, status=None)) 
after connection broken by 'NewConnectionError('<pip._vendor.urllib3.connection.VerifiedHTTPSConnection object
at 0x7fe38e764780>: Failed to establish a new connection: [Errno 101] 网络不可达',)': /simple/django/
在http://pypi.python.org/simple/regex/上下载错误:未知网址类型:https  - 可能找不到某些软件包!找不到'正则表达式'的索引页(可能拼写错误?)
Searching for pip
Reading https://pypi.python.org/simple/pip/
Download error on https://pypi.python.org/simple/pip/: unknown url type: https -- Some packages may not be found!
Couldn't find index page for 'pip' (maybe misspelled?)
Scanning index of all packages (this may take a while)
Reading https://pypi.python.org/simple/
Download error on https://pypi.python.org/simple/: unknown url type: https -- Some packages may not be found!
No local packages or download links found for pip
error: Could not find suitable distribution for Requirement.parse('pip')
RuntimeError: Compression requires the (missing) zlib module

安装前准备

    配置好yum源:为安装前做依赖准备,切不可直接升级,否则yum不可用blabla..

yum -y install gcc python-setuptools.noarch bash-compleetion-extras.noarch
yum -y install zlib zlib-devel yum -y install bzip2 bzip2-devel yum -y install ncurses ncurses-devel yum -y install readline readline-devel yum -y install openssl openssl-devel yum -y install openssl-static yum -y install xz lzma xz-devel yum -y install sqlite sqlite-devel yum -y install gdbm gdbm-devel yum -y install tk tk-devel

    或者

 

yum install gcc python-setuptools.noarch bash-compleetion-extras.noarch \
zlib zlib-devel bzip2 bzip2-devel ncurses ncurses-devel readline readline-devel \
openssl openssl-devel openssl-static xz lzma xz-devel sqlite sqlite-devel gdbm gdbm-devel \
tk tk-devel gcc-c++ make imake cmake automake glibc glibc-devel glib2 libxml glib2-devel \
libxml2 libxml2-devel libmcrypt libmcrypt-devel postgresql-devel

 

使用源码进行编译安装

    从官网下载源码包

# wget https://www.python.org/ftp/python/3.6.4/Python-3.6.4.tgz

    解压

xz  Python-3.6.4.tar.xz
tar -xvzf Python-3.3.0.tgz

    进入目录:配置安装目录,如果没有目标目录需要提前创建

./configure --prefix=/usr/local/python3 --enable-optimizations --enable-shared --with-ssl-default-suites
#不配置也可以,直接./configure命令
# --prefix:指定安装路径 # --enable-shared:禁用/启用构建共享python库 # --enable-optimizations:启用昂贵,稳定的优化(PGO等)。默认情况下禁用。(gcc 低于 8.1 时不可用)
# 安装时善用 ./configure --help 这个功能..

    然后编译,安装

make && make install

    修改python共享库

vim /etc/ld.so.conf.d/python3.conf
--------------------- /etc/ld.so.conf.d/python3.conf  ---------------------
# 添加以下内容: /usr/local/python3/lib/

    刷新动态链接库: ldconfig

完成

博客搬运地址

  1. 在 CentOS 7 上安装并配置 Python 3.6 环境
  2. 源码编译MongoDB
  3. 安装setuptools和pip 以及安装时报错解决
  4. 超详细的 Linux CentOS 编译安装python3
  5. CentOS7下安装配置python3
  6. Linux下编译安装python3
  7. 安装Python3.6.x
posted @ 2018-11-04 01:54  焦国峰的随笔日记  阅读(1900)  评论(0编辑  收藏  举报
// ############################### // ##############################