pyinstaller安装与使用

 

一、安装

1.传统cmd命令方法: pip install PyInstaller了,失败

(可能是版本问题,我的是Python2.7

直接使用pip,国内网络会无法连接

直接用pip安装是用不了的,会报错,因为还没有适合python3.6的pyinstaller库。 )

pyinstaller安装与使用_第1张图片

2.然后在是到git上下载源码安装,地址为 https://github.com/pyinstaller/pyinstaller,保存至F:\Python27\Scripts,解压

 

pyinstaller安装与使用_第2张图片

 

二、使用pyinstaller

在网上看了很多博客,最后只能用下面这种无奈的方法转换成exe文件。

<1>打开pyinstaller文件,进入含有pyinstaller.py的目录(开始文件的开始目录)。 
打开cmd(Ctrl + R),用cd命令进入到这个目录,如我的目录: 

cd F:\Python27\Scripts\pyinstaller-develop\PyInstaller

则命令如图

 

<2>接着把你要转换的.py文件放入该目录下,用atest.py展示。

 
  •  
  •  
  •  
  • 然后执行命令:

python pyinstaller.py -F atest.py

pyinstaller安装与使用_第3张图片

出现错误

在该目录下执行  python setup.py install   命令 结果如下

 

pyinstaller --version            查看安装结果

 

pyinstaller安装与使用_第4张图片

 

pyinstaller安装与使用_第5张图片

pyinstaller安装与使用_第6张图片

说明安装成功

然后    python pyinstaller.py -F atest.py

pyinstaller安装与使用_第7张图片

pyinstaller安装与使用_第8张图片

pyinstaller安装与使用_第9张图片 
exe可执行文件在hello里的dist目录下。

*用法

pyinstaller命令的语法是:(启用pyinstaller转换命令不止上述的python pyinstaller.py -F .... )

python pyinstaller.py [选项] [文件名.py] 
在此简单的说一下

选项 说明
-F –onefile 创建一个文件捆绑的可执行文件。
–distpath DIR 在哪里放置捆绑的应用程序(默认:./dist)
–workpath WORKPATH 在哪里放置所有的临时工作文件,.log,.pyz等(默认:./build)
–specpath DIR 存储生成的spec文件的文件夹(默认:当前目录)

把桌面上的atest.py转换的文件放置在桌面上atest文件中的命令:

python pyinstaller.py -F –distpath C:\Users\Heart\Desktop\hello\dist –workpath C:\Users\Heart\Desktop\hello\build –specpath C:\Users\Heart\Desktop\hello C:\Users\Heart\Desktop\hello.py

命令很长,每次这样输入让人很不爽,于是写个自动转换的代码偷个懒,而且还可以随时改动,很方便。

参考网址:

https://www.cnblogs.com/osfipin/p/4752728.html

https://blog.csdn.net/python_dream/article/details/78725429

 

 

 

你可能感兴趣的:(pyinstaller安装与使用)