centos7下python3.7.2的安装记录

  1. 下载 3.7.2
  2. 解压
  3. 安装python的依赖库(如果编译python过程中出错,很容易知道缺失什么库)
yum install zlib-devel bzip2-devel openssl-devel ncurese-devel uuid libffi libffi-devel  
yum install tcl tcl-devel tk tk-devel
  1. 默认情况下,编译出来的python库是静态库。这在后期开发需要用到python so库,那么会很不方便,因此最好配置为so库。同时也在安装时指定安装目录。
./configure --prefix=/usr/local/python3 --enable-shared CFLAGS=-fPIC
  1. 开始编译安装
make && make install
  1. 创建软链接
ln -s /usr/local/python3/bin/python3.7 /usr/bin/python3

如果在编译中出现如下错误

In file included from /home/888/Downloads/Python-3.7.2/Modules/_uuidmodule.c:8:0:
/usr/include/uuid.h:94:24: error: conflicting types for ‘uuid_t’
 typedef struct uuid_st uuid_t;
                        ^
In file included from /home/888/Downloads/Python-3.7.2/Modules/_uuidmodule.c:5:0:
/usr/include/uuid/uuid.h:44:23: note: previous declaration of ‘uuid_t’ was here
 typedef unsigned char uuid_t[16];
                       ^
In file included from /home/888/Downloads/Python-3.7.2/Modules/_uuidmodule.c:8:0:
/usr/include/uuid.h:107:22: error: conflicting types for ‘uuid_compare’
 extern uuid_rc_t     uuid_compare  (const uuid_t  *_uuid, const uuid_t *_uuid2, int *_result);

参考文章: https://my.oschina.net/mengyoufengyu/blog/2249877
这里把解决方案直接贴出来
即修改如下文件 ./Modules/_uuidmodule.c

#define PY_SSIZE_T_CLEAN

#include "Python.h"
#ifdef HAVE_UUID_UUID_H
#include 
#endif
#ifdef HAVE_UUID_H
#include 
#endif

//修改为

#define PY_SSIZE_T_CLEAN
#include "Python.h"
#ifdef HAVE_UUID_UUID_H
#include 
// #endif
// #ifdef HAVE_UUID_H
#else
#include 
#endif

你可能感兴趣的:(python)