pycharm打包.py程序为可执行文件exe-MacOS/Linux平台对应有解释

方案一:终端命令行打包不好使

方案二:(1)使用PyCharm工具打包ok

? ? ? ? ? ? ? ?(2)终端里执行打包结果脚本

pycharm打包.py程序为可执行文件exe-MacOS/Linux平台对应有解释

详细步骤如下:

位于开发环境下,我们可以直接通过IDE (pycharm)直接运行,当我们完成一个程序时,我们需要在独立环境下执行,因此我们需要将.py程序打包成windows环境下可直接执行的exe文件。

操作步骤如下:

1.在pycharm中安装插件PyInstaller

pycharm打包.py程序为可执行文件exe-MacOS/Linux平台对应有解释

?

2.调出terminal终端,输入命令pyinstaller -F -w vipvideoplay2.py?点击回车

pycharm打包.py程序为可执行文件exe-MacOS/Linux平台对应有解释

如图:输入指定命令后会在当前目录下生产dist文件夹,dist文件夹下为生成的exe文件

pycharm打包.py程序为可执行文件exe-MacOS/Linux平台对应有解释

参数说明:

-F:将所有库文件打包成一个exe

-w:隐藏黑色控制台窗口

如果不加-F参数会生成很多文件,但运行比较快。压缩后比单个exe文件小一点

加-F参数只生成一个exe文件,但运行慢

生成本项目可执行文件
Terminal中输入:

pyinstaller?-F?-w?main.py

main.py是我的项目启动文件名称,你要替换成你自己的项目启动名称。

生成的可执行文件放在同目录dist下。
  -F(注意大写)是所有库文件打包成一个可执行文件,windows下是exe,Linux下是对应的可执行文件;
  -w?是禁止弹出黑色控制台窗口。
  如果你的项目调用了图片等本地资源,请将你的可执行文件放在对应目录才能运行。

实践日志记录如下:?

ai-nixs:PyCharm_HelloWorld?nixinsheng$?ls
Demo20210128????Demo20210201????__pycache__?????main.py
You?have?new?mail?in?/var/mail/nixinsheng
ai-nixs:PyCharm_HelloWorld?nixinsheng$?ls
Demo20210128????Demo20210201????__pycache__?????main.py
ai-nixs:PyCharm_HelloWorld?nixinsheng$?cd?Demo20210201/
ai-nixs:Demo20210201?nixinsheng$?ls
Workingline.py??????????????????upx-3.96-amd64_linux
getTxtFile.py???????????????????upx-3.96-amd64_linux.tar.xz
ai-nixs:Demo20210201?nixinsheng$?pyinstaller?-F?-w?getTxtFile.py?
78?INFO:?PyInstaller:?4.2
78?INFO:?Python:?3.6.5
92?INFO:?Platform:?Darwin-19.6.0-x86_64-i386-64bit
93?INFO:?wrote?/Users/nixinsheng/Documents/python3/PyCharm_HelloWorld/Demo20210201/getTxtFile.spec
99?INFO:?UPX?is?not?available.
103?INFO:?Extending?PYTHONPATH?with?paths
[‘/Users/nixinsheng/Documents/python3/PyCharm_HelloWorld/Demo20210201‘,
?‘/Users/nixinsheng/Documents/python3/PyCharm_HelloWorld/Demo20210201‘]
119?INFO:?checking?Analysis
120?INFO:?Building?Analysis?because?Analysis-00.toc?is?non?existent
120?INFO:?Initializing?module?dependency?graph...
123?INFO:?Caching?module?graph?hooks...
146?WARNING:?Several?hooks?defined?for?module?‘win32ctypes.core‘.?Please?take?care?they?do?not?conflict.
154?INFO:?Analyzing?base_library.zip?...
5319?INFO:?Caching?module?dependency?graph...
5532?INFO:?running?Analysis?Analysis-00.toc
5542?INFO:?Analyzing?/Users/nixinsheng/Documents/python3/PyCharm_HelloWorld/Demo20210201/getTxtFile.py
5547?INFO:?Processing?module?hooks...
5548?INFO:?Loading?module?hook?‘hook-encodings.py‘?from?‘/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/PyInstaller/hooks‘...
5738?INFO:?Loading?module?hook?‘hook-pickle.py‘?from?‘/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/PyInstaller/hooks‘...
5824?INFO:?Excluding?import?of?argparse?from?module?pickle
5824?INFO:?Loading?module?hook?‘hook-heapq.py‘?from?‘/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/PyInstaller/hooks‘...
5831?INFO:?Excluding?import?of?doctest?from?module?heapq
5831?INFO:?Loading?module?hook?‘hook-difflib.py‘?from?‘/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/PyInstaller/hooks‘...
5834?INFO:?Excluding?import?of?doctest?from?module?difflib
5834?INFO:?Loading?module?hook?‘hook-xml.py‘?from?‘/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/PyInstaller/hooks‘...
6583?INFO:?Looking?for?ctypes?DLLs
6583?INFO:?Analyzing?run-time?hooks?...
6609?INFO:?Looking?for?dynamic?libraries
6840?INFO:?Looking?for?eggs
6840?INFO:?Using?Python?library?/Library/Frameworks/Python.framework/Versions/3.6/Python
6850?INFO:?Warnings?written?to?/Users/nixinsheng/Documents/python3/PyCharm_HelloWorld/Demo20210201/build/getTxtFile/warn-getTxtFile.txt
6939?INFO:?Graph?cross-reference?written?to?/Users/nixinsheng/Documents/python3/PyCharm_HelloWorld/Demo20210201/build/getTxtFile/xref-getTxtFile.html
6994?INFO:?checking?PYZ
6995?INFO:?Building?PYZ?because?PYZ-00.toc?is?non?existent
6995?INFO:?Building?PYZ?(ZlibArchive)?/Users/nixinsheng/Documents/python3/PyCharm_HelloWorld/Demo20210201/build/getTxtFile/PYZ-00.pyz
7997?INFO:?Building?PYZ?(ZlibArchive)?/Users/nixinsheng/Documents/python3/PyCharm_HelloWorld/Demo20210201/build/getTxtFile/PYZ-00.pyz?completed?successfully.
8007?INFO:?checking?PKG
8007?INFO:?Building?PKG?because?PKG-00.toc?is?non?existent
8007?INFO:?Building?PKG?(CArchive)?PKG-00.pkg
10970?INFO:?Building?PKG?(CArchive)?PKG-00.pkg?completed?successfully.
10977?INFO:?Bootloader?/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/PyInstaller/bootloader/Darwin-64bit/runw
10978?INFO:?checking?EXE
10978?INFO:?Building?EXE?because?EXE-00.toc?is?non?existent
10979?INFO:?Building?EXE?from?EXE-00.toc
10979?INFO:?Appending?archive?to?EXE?/Users/nixinsheng/Documents/python3/PyCharm_HelloWorld/Demo20210201/dist/getTxtFile
11005?INFO:?Fixing?EXE?for?code?signing?/Users/nixinsheng/Documents/python3/PyCharm_HelloWorld/Demo20210201/dist/getTxtFile
11015?INFO:?Building?EXE?from?EXE-00.toc?completed?successfully.
11021?INFO:?checking?BUNDLE
11021?INFO:?Building?BUNDLE?because?BUNDLE-00.toc?is?non?existent
11022?INFO:?Building?BUNDLE?BUNDLE-00.toc
11053?INFO:?moving?BUNDLE?data?files?to?Resource?directory
ai-nixs:Demo20210201?nixinsheng$

?

?

pycharm打包.py程序为可执行文件exe-MacOS/Linux平台对应有解释

上一篇:获取当前时间


下一篇:消息队列三