python项目适配arm架构国产麒麟系统

龚正阳 -
python项目适配arm架构国产麒麟系统
安装对应版本python

如果系统安装的python版本和项目所需的版本不一致,需要手动下载python二进制包编译安装

获取指定版本python,网址

https://registry.npmmirror.com/binary.html?path=python/

比如现在安装python3.6.15版本,下面命令参数需要依据具体python版本而改变

创建文件夹

$ sudo mkdir /usr/local/python3

获取对应版本的压缩包文件

$ cd /usr/local/python3
$ sudo wget https://cdn.npmmirror.com/binaries/python/3.6.15/Python-3.6.15.tar.xz

解压压缩包之后cd到解压文件夹,会存在一个配置文件configure

$ sudo tar -xvf Python-3.6.15.tar.xz

执行配置文件,该操作会生成Makefile文件

$ cd /usr/local/python3/Python-3.6.15
$ sudo ./configure  --enable-optimizations --prefix=/usr/local/python3

--enable-optimizations允许进行优化,--prefix指定安装目录

编译,安装

$ sudo make all
$ sudo make install

上述步骤执行完成之后,/usr/local/python3/bin会安装好对应版本的pythonpip可执行文件,现在创建对应的软链接

$ sudo ln -s /usr/local/python3/bin/pip3.6 /usr/bin/pip3.6
$ sudo ln -s /usr/local/python3/bin/python3.6 /usr/bin/python3.6

验证安装结果,可以看到pip3.6指向的python版本以及对应位置

$ pip3.6 -V
pip 18.1 from /usr/local/python3/lib/python3.6/site-packages/pip (python 3.6)

注意点

由于python的位置是/usr/local/python3,所以在pip安装完成一些库生成的二进制包的可执行文件路径位置是/usr/local/python3/bin/

比如安装完成celeryuwsgi,所以执行的时候需要执行

/usr/local/python3/bin/celery或者/usr/local/python3/bin/uwsgi

psycopg2或者psycopy2-binarypip依赖错误

报错Error: pg_config executable not found.

pg_config是位于postgresql-devel包当中在Debian/Ubuntu系当中需要安装libpq-devCentos/Fedora/Cygwin/Babun/Redhat系的系统当中需要libpq-devel麒麟系统执行apt install libpq-devlxmlpip依赖错误

报错Error: Please make sure the libxml2 and libxslt development packages are installed

执行apt install libxml2 libxslt1-dev

pillowpip依赖错误

报错如下

    The headers or library files could not be found for jpeg,
    a required dependency when compiling Pillow from source.
    
    Please see the install instructions at:
       https://pillow.readthedocs.io/en/latest/installation.html

顺着文档下去发现有很多二进制依赖,注意到zliblibjpeg库是必要的

去查看python pillowarm架构的Dockerfile查看需要安装到包

目前只需要按照必要的包即可解决问题

$ apt install libjpeg8-dev zlib1g-dev
docker拉取镜像超时

docker pull redis报错如下

Head https://registry-1.docker.io/v2/library/redis/manifests/latest: Get https://auth.docker.io/token?scope=repository%3Alibrary%2Fredis%3Apull&service=registry.docker.io: net/http: request canceled while waiting for connection

或者报错如下

Get https://registry-1.docker.io/v2/: net/http: request canceled while waiting for connection (Client.Timeout exceeded while awaiting headers)

则需要修改域名解析文件/etc/resolv.conf,直接使用vim编辑

nameserver 8.8.8.8
nameserver 8.8.4.4

之后重启docker

$ sudo systemctl restart docker
docker拉取镜像报错非法tar头部

报错如下

failed to register layer: ApplyLayer exit status 1 stdout:  stderr: archive/tar: invalid tar header

该错误产生原因是使用unpigz解压缩docker镜像层导致的

解决方案一,移动unpigz可执行文件位置使其不解压

$ mv /usr/bin/unpigz /usr/bin/unpigz.bak

解决方案二,参考docker官方文档,配置对应的环境变量

$ vim /usr/lib/systemd/system/docker.service

# 在Service的单元下面,增加这一行
[Service]
Environment="MOBY_DISABLE_PIGZ=true"
git clone域名解析报错

报错输出Could not resolve host: gitee.com

麒麟系统的git感觉压根就不支持域名解析,首先查看gitee.comIP

$ nslookup github.com
Server:         223.5.5.5
Address:        223.5.5.5#53

Non-authoritative answer:
Name:   gitee.com
Address: 212.64.63.190

查询不到的话需要显示指定dns地址

$ nslookup gitlab.bolean.com 8.8.8.8

最后把对应的IP解析写入/etc/hosts

212.64.63.190 gitee.com
git clonegnutls报错

报错输出gnutls_handshake() failed: 在 push 函数中出错

这个解决比较麻烦,需要把gnutls替换为openssl,只能从源码构建git解决

安装一些前置依赖

$ apt-get install dh-autoreconf libcurl4-gnutls-dev libexpat1-dev gettext libz-dev libssl-dev

查看系统当前git版本

$ git version
git version 2.25.1

保险起见获取一个相同版本的git

获取git的网站地址kernel.orggit镜像

$ wget https://mirrors.edge.kernel.org/pub/software/scm/git/git-2.25.1.tar.gz

解压编译

$ tar -zxf git-2.25.1.tar.gz
$ cd git-2.25.1
$ make configure

这个时候默认是使用openssl的(这个不清楚在别的版本是否是这样的)

执行之前先执行如下命令,查看输出的提示信息当中是否有这一行

$ ./configure --help
...
  --with-openssl          use OpenSSL library (default is YES)
                          ARG can be prefix for openssl library and headers
...

编译安装

$ ./configure --prefix=/usr/local/git
$ make
$ make install

最后删除系统自带的git,创建一个软链接指向编译生成的git

$ sudo mv /usr/bin/git /usr/bin/git.back
$ sudo ln -s /usr/local/git/bin/git /usr/bin/git
参考阅读

docker daemon文档

python pillowarm架构的Dockerfile

特别申明:本文内容来源网络,版权归原作者所有,如有侵权请立即与我们联系(cy198701067573@163.com),我们将及时处理。
下一篇: Git 合并分支

Tags 标签

pythonarmdockergit编译

扩展阅读

加个好友,技术交流

1628738909466805.jpg