Linux 服务器(CentOS7)安装 Python-3.7.
本文已经发布在我的个人网站上啦,欢迎访问!
安装 Python-3.7.5
前期准备
-
下载并解压
Python-3.7.5
的源码包:wget https://www.python.org/ftp/python/3.7.5/Python-3.7.5.tar.xz tar -Jxvf Python-3.7.5.tar.xz
-
通过
yum
安装依赖:yum install -y openssl openssl-devel libffi-devel openssh bzip2-devel expat-devel gdbm-devel sqlite-devel
注意:第三个包
libffi-devel
一定要安装,否则在make install
时会报错:ModuleNotFoundError: No module named '_ctypes'
。
编译安装
-
进入源码包目录后执行编译安装:
./configure --prefix=/usr/local/python37 --enable-optimizations make make install
-
建立软链接:
ln -s /usr/local/python37/bin/python3.7 /usr/bin/python37
验证安装
python37 --version
安装 Subversion-1.12.2
前期准备
-
下载并解压
Subversion-1.12.2
以及各个依赖的源码包:wget http://mirrors.tuna.tsinghua.edu.cn/apache/subversion/subversion-1.12.2.tar.gz wget http://mirrors.tuna.tsinghua.edu.cn/apache//apr/apr-1.7.0.tar.gz wget http://mirrors.tuna.tsinghua.edu.cn/apache//apr/apr-util-1.6.1.tar.gz wget https://www.sqlite.org/2019/sqlite-autoconf-3300100.tar.gz wget https://github.com/JuliaStrings/utf8proc/archive/v2.4.0.tar.gz wget https://www.apache.org/dist/serf/serf-1.3.9.tar.bz2 wget https://nchc.dl.sourceforge.net/project/scons/scons/3.1.0/scons-3.1.0.tar.gz tar -zxvf subversion-1.12.2.tar.gz tar -zxvf apr-1.7.0.tar.gz tar -zxvf apr-util-1.6.1.tar.gz tar -zxvf sqlite-autoconf-3300100.tar.gz tar -zxvf v2.4.0.tar.gz tar -jxvf serf-1.3.9.tar.bz2 tar -zxvf scons-3.1.0.tar.gz
-
通过
yum
安装依赖:yum install -y httpd-devel.x86_64 zlib zlib-devel openssl openssl-devel unzip openssh-clients gcc gcc-c++ expat-devel
安装其他依赖
-
进入
apr-1.7.0
源码包目录后执行编译:./configure --prefix=/usr/local/apr make make install
-
进入
apr-util-1.6.1
源码包目录后执行编译:./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr make make install
-
进入
scons-3.1.0
源码包目录后执行编译:注意:编译安装
scons
需要系统环境变量python
默认调用Python2
。python setup.py install --prefix=/usr/local/scons
-
进入
serf-1.3.9
源码包目录后执行编译:注意:编译
serf
需要使用上一步中安装的scons
。/usr/local/scons/bin/scons PREFIX=/usr/local/serf APR=/usr/local/apr APU=/usr/local/apr-util /usr/local/scons/bin/scons install cp /usr/local/serf/lib/libserf-1.so* /usr/local/lib
-
进入
sqlite-autoconf-3300100
源码包目录后执行编译:./configure --prefix=/usr/local/sqlite make make install
-
进入
utf8proc-2.4.0
源码包目录后执行编译:make make install
编译安装
-
进入
subversion-1.12.2
源码包目录后执行编译:如果报了
httpd
相关的错误,一定要加上--enable-apache-whitelist=2.4.6
和--enable-broken-httpd-auth
这两个参数,其中的2.4.6
为httpd
的版本。./configure --prefix=/usr/local/subversion --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util --with-serf=/usr/local/serf --with-sqlite=/usr/local/sqlite --with-zlib --with-lz4 --with-uft8proc --enable-maintainer-mode --enable-mod-activation --enable-apache-whitelist=2.4.6 --enable-broken-httpd-auth make make install
-
卸载系统上的旧版本
Subversion
:yum remove subversion
-
建立软链接:
ln -s /usr/local/subversion/bin/svn /usr/bin/svn
验证安装
svn --version
svn: error while loading shared libraries: libserf-1.so.1: cannot open shared object file: No such file or director
-
配置库文件:
cd /etc/ld.so.conf.d vim user-libs.conf # 写入 /usr/local/lib 并保存退出 ldconfig
-
验证安装:
svn --version
正常执行,无报错。
安装 PySVN-1.9.10
前期准备
下载并解压 PySVN-1.9.10
的源码包:
wget https://jaist.dl.sourceforge.net/project/pysvn/pysvn/V1.9.10/pysvn-1.9.10.tar.gz
tar -zxvf pysvn-1.9.10.tar.gz
编译安装
-
将系统环境变量
python
配置为默认调用Python-3.7.5
:mv /usr/bin/python /usr/bin/python.bak ln -s /usr/local/python37/bin/python3.7 /usr/bin/python
-
进入
pysvn-1.9.10
源码包目录下的Source
目录并执行编译:python ./setup.py configure --pycxx-dir=../Import/pycxx-7.1.3/ --svn-inc-dir=/usr/local/subversion/include/subversion-1/ --svn-lib-dir=/usr/local/subversion/lib/ --svn-bin-dir=/usr/local/subversion/bin/ --apr-inc-dir=/usr/local/apr/include/apr-1/ --apr-lib-dir=/usr/local/apr/lib/ --apu-inc-dir=/usr/local/apr-util/include/apr-1/ make
-
将编译生成的
pysvn
目录下的模块文件复制到Python-3.7.5
的site-packages
里面:cp -r pysvn /usr/local/python37/lib/python3.7/site-packages/
验证安装
python
>>> import pysvn
Traceback (most recent call last):
File "/data/home/jerrywjdeng/Downloads/pysvn-1.9.10/Source/pysvn/__init__.py", line 112, in <module>
import pysvn._pysvn_3_7
ImportError: /usr/local/apr-util/lib/libaprutil-1.so.0: undefined symbol: apr_allocator_align
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/data/home/jerrywjdeng/Downloads/pysvn-1.9.10/Source/pysvn/__init__.py", line 122, in <module>
raise ImportError( 'pysvn was built against newer (svn, apr, etc.) libraries then the ones installed on this system. %s' % str(e) )
ImportError: pysvn was built against newer (svn, apr, etc.) libraries then the ones installed on this system. /usr/local/apr-util/lib/libaprutil-1.so.0: undefined symbol: apr_allocator_align
-
分别执行 ldd 查看引用差异:
ldd /usr/local/python37/lib/python3.7/site-packages/pysvn/_pysvn_3_7.so ldd /usr/local/subversion/lib/libsvn_delta-1.so.0
-
对比发现
apr
文件有差异:_pysvn_2_7.so: libapr-1.so.0 => lib64/libapr-1.so.0 (0x00007f7eaa42b000) libsvn_delta-1.so.0: libapr-1.so.0 => /usr/local/apr/lib/libapr-1.so.0 (0x00007f19605ae000)
-
备份
/usr/lib64/libapr*
:cd /lib64 mv libapr-1.so.0 libapr-1.so.0.bak mv libapr-1.la libapr-1.la.bak mv libapr-1.so libapr-1.so.bak mv libapr-1.so.0.4.8 libapr-1.so.0.4.8.bak
-
用
/usr/local/apr/lib/
下的类文件替换/lib64/
下的原libapr*
:cd /usr/local/apr/lib cp libapr-1.la /lib64/ cp libapr-1.so.0.7.0 /lib64/ cd /lib64 ln -s libapr-1.so.0.7.0 libapr-1.so.0 ln -s libapr-1.so.0.7.0 libapr-1.so
-
验证安装:
python >>> import pysvn >>> client = pysvn.Client()
正常执行,无报错。