在linux中把.py文件打包成二进制可执行文件

一、 下载python3

参考链接:
https://www.jianshu.com/p/8b4d52869d86
https://jingyan.baidu.com/article/afd8f4deb393fa34e386e910.html
https://blog.csdn.net/jeffery0207/article/details/79774567

1. 在root目录下执行命令

wget https://www.python.org/ftp/python/3.6.3/Python-3.6.3.tgz

image.png

2.[root@ ~]# tar -zxvf Python-3.6.3.tgz
3.[root@ ~]# cd Python-3.6.3
4.Centos7的依赖

[root@ Python-3.6.3]# yum install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gcc make –y

Centos6的依赖 两个

[[email protected]]# yum install gcc patch libffi-devel python-devel zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel –y
[root@ Python-3.6.3]# yum install openssl-devel bzip2-devel expat-devel gdbm-devel readline-devel sqlite-devel readline-devel.x86_64 -y

5.[root@ Python-3.6.3]# ./configure prefix=/usr/local/python3
image.png
6.Make &make install
image.png

image.png

二、链接

1.[root@ Python-3.6.3]# ln -s /usr/local/python3/bin/python3 /usr/bin/python3
2. [root@ Python-3.6.3]# ll/usr/bin/py*
image.png
3.[root@ Python-3.6.3]# vim /usr/bin/yum 不确定是否执行,
#!/usr/bin/python 修改为 #!/usr/bin/python2
4.[root@ Python-3.6.3]# ln -s /usr/local/python3/bin/pip3 /usr/local/bin/pip3
5.[root@ Python-3.6.3]# pip3 install --upgrade pip
image.png

三、默认用python3

1.[root@ Python-3.6.3]# mv /usr/bin/python /usr/bin/python.bak
2.[root@ Python-3.6.3]# ln -s /usr/local/python3/bin/python3.6 /usr/bin/python

可以输入python验证是什么版本,或者用python –V 验证版本


image.png

一、 安装Pyinstaller

1. 把pyinstaller-3.5.tar.gz下载到root目录下

http://www.pyinstaller.org/downloads.html

2. [root@ ~]# tar -zxvf PyInstaller-3.5.tar.gz
3. python setup.py install
image.png
4.[root@ PyInstaller-3.5]# python3 pyinstaller.py -F test.py test.py为打包文件,以下为报错。

image.png

解决:https://www.cnblogs.com/jerryzh/p/10937905.html

Cd /root/Python-3.6.3/

./configure --prefix=/usr/local/python36 --enable-shared --with-ssl

make

make install

五、输入python,页面报错

image.png

解决:https://blog.csdn.net/df0128/article/details/89446507
[[email protected]]# cp libpython3.6m.so.1.0 /usr/local/ lib64/
[root@ Python-3.6.3]# cp libpython3.6m.so.1.0 /usr/lib/
[root@ Python-3.6.3]# cp libpython3.6m.so.1.0 /usr/lib64/
image.png

六、开始打包

Cd /root/PyInstaller-3.5/
[[email protected]]# python3 pyinstaller.py -F test.py
会在/root/PyInstaller-3.5/生成一个test的文件夹,在test文件夹下有dist文件夹,dist文件夹下就会有test二进制文件。

你可能感兴趣的:(在linux中把.py文件打包成二进制可执行文件)