1、安装zlib源码包
下载zlib源码包
http://www.zlib.net/
tar -zxf zlib-1.2.11.tar.gz
cd zlib-1.2.11/
# 使用你自己的编译环境
CC=arm-hisiv400-linux-gcc
AR=arm-hisiv400-linux-ar
RANLIB=arm-hisiv400-linux-ranlib
# 安装至你的交编译器所在的环境目录
./configure –prefix=/opt/hisi-linux/x86-arm/arm-hisiv400-linux/arm-hisiv400-linux-gnueabi –shared
make;
make install;
make install –prefix=/opt/zlib
2、安装sqlite3
安装sqlite3
wget https://www.sqlite.org/2018/sqlite-autoconf-3250200.tar.gz
tar -zxvf sqlite-autoconf-3250200.tar.gz
cd sqlite-autoconf-3250200
./configure CC=arm-hisiv400-linux-gcc AR=arm-hisiv400-linux-ar RANLIB=arm-hisiv400-linux-ranlib LDFLAGS=-lrt READELF=arm-hisiv400-linux-readeif CPP=arm-hisiv400-linux-cpp –host=arm-hisiv400-linux-gnueabi –build=x86_64-linux-gnu –prefix=/opt/sqlite3
make;make install;
3、安装python3
安装python3
修改setup.py文件以支持sqlite3
# 第1138行 修改为
1137 if cross_compiling:
1138 sqlite_inc_paths = [‘/opt/sqlite3/include’]
修改Modules/Setup文件以支持zlib
# 365行修改为
365 zlib zlibmodule.c -I/opt/zlib/include -L/opt/zlib/lib -lz
但是用修改Modules/Setup文件方式构建的zlib仅是 build-in 方式
在python3/lib/python3.6/lib-dynload 中并没有生成对应的.so文件
因此虽然在python shell中可以正常导入zlib
但是使用uwsgi运行应用时仍会出现找不到zlib
因此需要更换构建方式
通过阅读setup.py
1402
1403 # Andrew Kuchling’s zlib module. Note that some versions of zlib
1404 # 1.1.3 have security problems. See CERT Advisory CA-2002-07:
1405 # http://www.cert.org/advisories/CA-2002-07.html
1406 #
1407 # zlib 1.1.4 is fixed, but at least one vendor (RedHat) has decided to
1408 # patch its zlib 1.1.3 package instead of upgrading to 1.1.4. For
1409 # now, we still accept 1.1.3, because we think it’s difficult to
1410 # exploit this in Python, and we’d rather make it RedHat’s problem
1411 # than our problem .
1412 #
1413 # You can upgrade zlib to version 1.1.4 yourself by going to
1414 # http://www.gzip.org/zlib/
1415 zlib_inc = find_file(‘zlib.h’, [], inc_dirs)
1416 have_zlib = False
1417 if zlib_inc is not None:
1418 zlib_h = zlib_inc[0] + ‘/zlib.h’
1419 version = ‘”0.0.0″‘
1420 version_req = ‘”1.1.3″‘
发现安装时会寻找zlib所在头文件,而目录集则在inc_dirs这个变量中
通过打印inc_dirs得知
[‘./Include’, ‘/opt/python3/include’, ‘.’, ‘/opt/hisi-linux/x86-arm/arm-hisiv400-linux/bin/../target/usr/include’, ‘/home/nsk/bin/Python-3.6.0/Include’, ‘/home/nsk/bin/Python-3.6.0’]
发现会在以上几个目录寻找头文件,然而之前编译zlib存放的位置是
/opt/hisi-linux/x86-arm/arm-hisiv400-linux/arm-hisiv400-linux-gnueabi
并没有出现在上述列表中,于是将/opt/zlib include 和 lib 下的文件拷贝到对应的/opt/hisi-linux/x86-arm/arm-hisiv400-linux/bin/…/target/usr/ 的 include 和 lib中并取消修改
# 365行取消修改 或者注释
# 365 zlib zlibmodule.c -I/opt/zlib/include -L/opt/zlib/lib -lz
通过上述修改后,当编译时会自动生成编译zlib的指令
tar -zxf Python-3.6.0.tgz
cd Python-3.6.0/
echo ac_cv_file__dev_ptmx=no > config.site
echo ac_cv_file__dev_ptc=no >> config.site
export CONFIG_SITE=config.site
./configure CC=arm-hisiv400-linux-gcc AR=arm-hisiv400-linux-ar RANLIB=arm-hisiv400-linux-ranlib LDFLAGS=-lrt READELF=arm-hisiv400-linux-readeif CPP=arm-hisiv400-linux-cpp –host=arm-hisiv400-linux-gnueabi –build=x86_64-linux-gnu -disable-ipv6 –without-ensurepip –enable-loadable-sqlite-extensions –prefix=/opt/python3
make -j8;
make install -j8;
编译完成后可通过查看build/lib.linux-arm-3.6目录
确认 zlib.cpython-36m-arm-linux-gnueabi.so 文件存在
4、安装pycrypto
安装pycrypto
tar -zxf pycrypto-2.6.1\ \(1\).tar.gz
cd pycrypto-2.6.1
./configure CC=arm-hisiv400-linux-gcc AR=arm-hisiv400-linux-ar RANLIB=arm-hisiv400-linux-ranlib LDFLAGS=-lrt READELF=arm-hisiv400-linux-readeif CPP=arm-hisiv400-linux-cpp –host=arm-hisiv400-linux-gnueabi –build=x86_64-linux-gnu –prefix=/opt/python3
python3 setup.py install –prefix=/opt/python3
可能出错
运行过程中如果出现使用了默认gcc的情况,使用
cd /usr/bin
mv gcc gcc_bak
ln -s /opt/hisi-linux/x86-arm/arm-hisiv400-linux/bin/arm-hisiv400-linux-gnueabi-gcc ./gcc
5、安装psutil
安装psutil
tar -zxf psutil-5.6.3\ \(1\).tar.gz
cd psutil-5.6.3/
python3 setup.py install –prefix=/opt/python3
出错
TEST FAILED: /opt/python3/lib/python3.6/site-packages/ does NOT support .pth files
error: bad install directory or PYTHONPATH
You are attempting to install a package to a directory that is not
on PYTHONPATH and which Python does not read “.pth” files from. The
installation directory you specified (via –install-dir, –prefix, or
the distutils default setting) was:
/opt/python3/lib/python3.6/site-packages/
and your PYTHONPATH environment variable currently contains:
‘/opt/arm_python/lib/python3.6/site-packages’
Here are some of your options for correcting the problem:
修改python path
export PYTHONPATH=/opt/python3/lib/python3.6/site-packages
出现使用默认gcc的情况解决方式同上
6、安装uwsgi
安装pcre
http://www.pcre.org/
# 编译arm版
tar zxvf pcre-8.0.0.tar.gz
cd pcre-8.0.0
./configure CC=arm-hisiv400-linux-gcc –host=arm-hisiv400-linux-gnueabi –prefix=/opt/pcre –disable-cp
make;
make install;
# 编译x86版
make clean;
./configure –disable-cp;
make;
make install;
# pcre-config –version
8.00
安装uwsgi
tar -zxf uwsgi-2.0.18.tar.gz
cd uwsgi-2.0.18
python3 setup.py install –prefix=/opt/python3
出错
/usr/local/lib/python3.6/config-3.6m-x86_64-linux-gnu/libpython3.6m.a: error adding symbols: 不可识别的文件格式
默认使用了host的python3环境,所以需要修改为arm python3的环境
修改uwsgiconfig.py文件 可能有更好的方法
# 在594行下面添加
libs[-3] = ‘/opt/python3/lib/python3.6/config-3.6m-arm-linux-gnueabi/libpython3.6m.a’
再次执行
python3 setup.py install –prefix=/opt/python3
出错
/home/nsk/bin/Python-3.6.0/Python/pytime.c:567: undefined reference to `clock_gettime’
编译命令需要添加 -lrt
继续修改uwsgiconfig.py文件
594 print(“*** uWSGI linking ***”)
# 添加:
595 print(libs)
596 libs[-3] = ‘/opt/python3/lib/python3.6/config-3.6m-arm-linux-gnueabi/libpython3.6m.a’
# 确保本地也安装pcre 需要本地程序触发指令才能生成pcre的编译命令
597 libs[5] = ‘-L/opt/pcre/lib -lpcre’
598 libs.append(‘-lrt’)
7、安装setuptools
安装setuptools
tar -zxf setuptools-28.8.0.tar.gz
cd setuptools-28.8.0/
python3 setup.py install –prefix=/opt/python3
8、安装pip
安装pip
tar -zxf pip-9.0.1.tar.gz
cd pip-9.0.1/
python3 setup.py install –prefix=/opt/python3
9、安装six
安装six
tar -zxf six-1.14.0\ \(1\).tar.gz
cd six-1.14.0/
python3 setup.py install –prefix=/opt/python3
10、安装 pytz
安装 pytz
tar -zxf pytz-2019.3\ \(1\).tar.gz
cd pytz-2019.3/
python3 setup.py install –prefix=/opt/python3
11、安装django
安装django
tar -zxf Django-2.1.8.tar.gz
cd Django-2.1.8/
python3 setup.py install –prefix=/opt/python3
12、环境
不连接公网web端程序,不考虑高并发访问和数据存储问题,因此消息队列和大型数据库之类的并不需要
最后将/opt/python3 整个目录拷贝至arm上
将 /opt/sqlit3/lib 与 bin 分别拷贝到 arm系统中 /usr/bin 和 /usr/lib 或者拷贝到其他位置添加环境变量
将 /opt/pcre/lib 与 bin 分别拷贝到 arm系统中 /usr/bin 和 /usr/lib 或者拷贝到其他位置添加环境变量
将 /opt/zlib/lib 与 bin 分别拷贝到 arm系统中 /usr/bin 和 /usr/lib 或者拷贝到其他位置添加环境变量
项目运行 出错 ImportError: cannot import name ‘_AES’
在/mnt/python3/lib/python3.6/site-packages/Crypto/Cipher/新建 _AES.py
内容:
# encoding: utf-8
# module Crypto.Cipher._AES
# from /Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/Crypto/Cipher/_AES.cpython-36m-darwin.so
# by generator 1.145
# no doc
# no imports
# Variables with simple values
block_size = 16
key_size = 0
MODE_CBC = 2
MODE_CFB = 3
MODE_CTR = 6
MODE_ECB = 1
MODE_OFB = 5
MODE_PGP = 4
# functions
def new(key, mode=None, *args, **kwargs): # real signature unknown; NOTE: unreliably restored from __doc__
“”” new(key, [mode], [IV]): Return a new _AES encryption object. “””
pass
# no classes
# variables with complex values
__loader__ = None # (!) real value is ”
__spec__ = None # (!) real value is ”
uwsgi运行出现Bind(): “Cannot assign requested address”
执行
ifconfig lo up