我是靠谱客的博主 现代刺猬,最近开发中收集的这篇文章主要介绍树莓派3b+ centos7 编译安装python3.7.0,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

2019独角兽企业重金招聘Python工程师标准>>> hot3.png

1、安装相关库

yum -y install zlib zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel
yum -y tk-devel gdbm-devel db4-devel libpcap-devel xz-devel wget
yum -y install gcc kernel-devel kenel-headers make bzip2 libffi libffi-devel
yum -y install expat-devel e2fsprogs-devel uuid-devel libuuid-devel tcl
yum -y install gdbm-devel tcl-devel tk-devel python-tools

2、安装libressl

官网:https://www.libressl.org/, 西寨速度比较慢,采用镜像地址

wget http://ftp.jaist.ac.jp/pub/OpenBSD/LibreSSL/libressl-2.8.2.tar.gz
tar xzvf libressl-2.8.2.tar.gz
cd libressl-2.8.2
./configure --prefix=/usr/local/ssl
make
sudo make install
sudo mv /usr/bin/openssl /usr/bin/openssl.bak
sudo mv /usr/include/openssl /usr/include/openssl.bak
sudo ln -s /usr/local/ssl/bin/openssl /usr/bin/openssl
sudo ln -s /usr/local/ssl/include/openssl /usr/include/openssl
sudo echo /usr/local/ssl/lib > /etc/ld.so.conf.d/libressl-2.8.0.conf
sudo ldconfig -v #重新加载库文件

3、下载python3.7.0并解包

wget https://www.python.org/ftp/python/3.7.0/Python-3.7.0.tgz
tar xzvf Python-3.7.0.tgz
export LDFLAGS="-L/usr/local/ssl/lib"
export CPPFLAGS="-I/usr/local/ssl/include"
export PKG_CONFIG_PATH="/usr/local/ssl/lib/pkgconfig"
cd Python-3.7.0

4、修改uuid相关文件,否则编译报错

vi ./Modules/_uuidmodule.c

将如下内容

#define PY_SSIZE_T_CLEAN
#include "Python.h"
#ifdef HAVE_UUID_UUID_H
#include <uuid/uuid.h>
#endif
#ifdef HAVE_UUID_H
#include <uuid.h>
#endif

修改为

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

5、编译python3.7.0并安装

export LDFLAGS="-L/usr/local/ssl/lib"
export CPPFLAGS="-I/usr/local/ssl/include"
export PKG_CONFIG_PATH="/usr/local/ssl/lib/pkgconfig"
# ./configure --prefix=/usr/local/python370 --enable-optimizations --with-uuid=ossp --enable-shared CFLAGS=-fPIC
./configure --prefix=/usr/local/python370 --enable-optimizations --with-uuid=ossp CFLAGS=-fPIC
make
sudo make install
sudo ln -s /usr/local/python370/bin/python3.7 /usr/bin/python3.7.0
sudo ln -s /usr/local/python370/bin/python3.7 /usr/bin/python370
sudo ln -s /usr/local/python370/bin/pip3.7 /usr/bin/pip3.7.0
sudo ln -s /usr/local/python370/bin/pip3.7 /usr/bin/pip370

5.1编译python3.7.0并安装命令汇总:

export LDFLAGS="-L/usr/local/ssl/lib"
export CPPFLAGS="-I/usr/local/ssl/include"
export PKG_CONFIG_PATH="/usr/local/ssl/lib/pkgconfig"
wget https://www.python.org/ftp/python/3.7.0/Python-3.7.0.tgz
tar xzvf Python-3.7.0.tgz
cd Python-3.7.0
sed -i "6s/endif/else/" ./Modules/_uuidmodule.c
sed -i "7d" ./Modules/_uuidmodule.c
sed -i "s/Werror=implicit-function-declaration/Wno-error/g" ./configure
./configure --prefix=/usr/local/python370 --enable-optimizations --with-uuid=ossp CFLAGS=-fPIC
make
sudo make install
sudo ln -s /usr/local/python370/bin/python3.7 /usr/bin/python3.7.0
sudo ln -s /usr/local/python370/bin/python3.7 /usr/bin/python370
sudo ln -s /usr/local/python370/bin/pip3.7 /usr/bin/pip3.7.0
sudo ln -s /usr/local/python370/bin/pip3.7 /usr/bin/pip370

5.2编译python3.7.1并安装命令汇总:

export LDFLAGS="-L/usr/local/ssl/lib"
export CPPFLAGS="-I/usr/local/ssl/include"
export PKG_CONFIG_PATH="/usr/local/ssl/lib/pkgconfig"
wget https://www.python.org/ftp/python/3.7.1/Python-3.7.1.tgz
tar xzvf Python-3.7.1.tgz
cd Python-3.7.1
sed -i "6s/endif/else/" ./Modules/_uuidmodule.c
sed -i "7d" ./Modules/_uuidmodule.c
sed -i "s/Werror=implicit-function-declaration/Wno-error/g" ./configure
./configure --prefix=/usr/local/python371 --enable-optimizations --with-uuid=ossp CFLAGS=-fPIC
make
sudo make install
sudo ln -s /usr/local/python371/bin/python3.7 /usr/bin/python3.7.1
sudo ln -s /usr/local/python371/bin/python3.7 /usr/bin/python371
sudo ln -s /usr/local/python371/bin/pip3.7 /usr/bin/pip3.7.1
sudo ln -s /usr/local/python371/bin/pip3.7 /usr/bin/pip371

6、遇到的问题一

INFO: Could not locate ffi libs and/or headers

Python build finished successfully!
The necessary bits to build these optional modules were not found:
_hashlib              _ssl                  _uuid              
To find the necessary bits, look in setup.py in detect_modules() for the module's name.


The following modules found by detect_modules() in setup.py, have been
built by the Makefile instead, as configured by the Setup files:
_abc                  atexit                pwd                
time                                                           


Failed to build these modules:
_ctypes                                                        


Could not build the ssl module!
Python requires an OpenSSL 1.0.2 or 1.1 compatible libssl with X509_VERIFY_PARAM_set1_host().
LibreSSL 2.6.4 and earlier do not provide the necessary APIs, https://github.com/libressl-portable/portable/issues/381
 

7、遇到问题2

问题:

 gcc -pthread -fPIC -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -std=c99 -Wextra -Wno-unused-result -Wno-unused-parameter -Wno-missing-field-initializers -Werror=implicit-function-declaration -fprofile-generate -I./Include -I. -I/usr/local/ssl/include -I/usr/local/include -I/home/pi/my/Python-3.7.0/Include -I/home/pi/my/Python-3.7.0 -c /home/pi/my/Python-3.7.0/Modules/_uuidmodule.c -o build/temp.linux-aarch64-3.7/home/pi/my/Python-3.7.0/Modules/_uuidmodule.o -DHAVE_UUID_UUID_H
In file included from /home/pi/my/Python-3.7.0/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/pi/my/Python-3.7.0/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/pi/my/Python-3.7.0/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);
                      ^
In file included from /home/pi/my/Python-3.7.0/Modules/_uuidmodule.c:5:0:
/usr/include/uuid/uuid.h:73:5: note: previous declaration of ‘uuid_compare’ was here
 int uuid_compare(const uuid_t uu1, const uuid_t uu2);
     ^
/home/pi/my/Python-3.7.0/Modules/_uuidmodule.c: In function ‘py_uuid_generate_time_safe’:
/home/pi/my/Python-3.7.0/Modules/_uuidmodule.c:15:12: error: storage size of ‘uuid’ isn’t known
     uuid_t uuid;
            ^
/home/pi/my/Python-3.7.0/Modules/_uuidmodule.c:15:12: warning: unused variable ‘uuid’ [-Wunused-variable]
/home/pi/my/Python-3.7.0/Modules/_uuidmodule.c:35:1: warning: control reaches end of non-void function [-Wreturn-type]
 }
 ^ gcc -pthread -fPIC -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -std=c99 -Wextra -Wno-unused-result -Wno-unused-parameter -Wno-missing-field-initializers -Werror=implicit-function-declaration -fprofile-generate -I./Include -I. -I/usr/local/ssl/include -I/usr/local/include -I/home/pi/my/Python-3.7.0/Include -I/home/pi/my/Python-3.7.0 -c /home/pi/my/Python-3.7.0/Modules/_uuidmodule.c -o build/temp.linux-aarch64-3.7/home/pi/my/Python-3.7.0/Modules/_uuidmodule.o -DHAVE_UUID_UUID_H
In file included from /home/pi/my/Python-3.7.0/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/pi/my/Python-3.7.0/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/pi/my/Python-3.7.0/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);
                      ^
In file included from /home/pi/my/Python-3.7.0/Modules/_uuidmodule.c:5:0:
/usr/include/uuid/uuid.h:73:5: note: previous declaration of ‘uuid_compare’ was here
 int uuid_compare(const uuid_t uu1, const uuid_t uu2);
     ^
/home/pi/my/Python-3.7.0/Modules/_uuidmodule.c: In function ‘py_uuid_generate_time_safe’:
/home/pi/my/Python-3.7.0/Modules/_uuidmodule.c:15:12: error: storage size of ‘uuid’ isn’t known
     uuid_t uuid;
            ^
/home/pi/my/Python-3.7.0/Modules/_uuidmodule.c:15:12: warning: unused variable ‘uuid’ [-Wunused-variable]
/home/pi/my/Python-3.7.0/Modules/_uuidmodule.c:35:1: warning: control reaches end of non-void function [-Wreturn-type]
 }
 ^
 解决参加4步

8、问题3:python3: error while loading shared libraries: libpython3.7m.so.1.0: cannot open shared object file

采用:--enable-shared 方式会出现“python3: error while loading shared libraries: libpython3.5m.so.1.0: cannot open shared object file”

去掉该选项

 

参考资料:

https://blog.csdn.net/love_cjiajia/article/details/82254371

转载于:https://my.oschina.net/mengyoufengyu/blog/2249877

最后

以上就是现代刺猬为你收集整理的树莓派3b+ centos7 编译安装python3.7.0的全部内容,希望文章能够帮你解决树莓派3b+ centos7 编译安装python3.7.0所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(51)

评论列表共有 0 条评论

立即
投稿
返回
顶部