Python从入门到放弃 (二) 将.py文件转化为win 10下的可执行程序

2021/12/26 12:07:35

本文主要是介绍Python从入门到放弃 (二) 将.py文件转化为win 10下的可执行程序,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

一.Pyinstaller库的简介

该第三方库的作用就是把用python语言编写的程序转化为在windows环境下可执行程序.exe文件

官方地址见下面:

Features — PyInstaller bundles Python applicationshttp://www.pyinstaller.org/features.html

二.Pyinstaller库的安装

在[cmd]界面中输入 pip3 install Pyinstaller 即可安装此库如下图所示,笔者已经安装好了。

三.Pyinstaller库的使用

1.指令原型

pyinstaller [options] script [script …] | specfile

说明:

  • Writes myscript.spec in the same folder as the script.

  • Creates a folder build in the same folder as the script if it does not exist.

  • Writes some log files and working files in the build folder.

  • Creates a folder dist in the same folder as the script if it does not exist.

  • Writes the myscript executable folder in the dist folder

下列举例说明两种转化你的.py文件的用法。假设你在D盘建立了Hello.py这个程序

那么该文件地址为 D:\Hello.py  按照下面的例子来写,其中options要看具体的说明

pyinstaller options… ~/myproject/source/myscript.py

pyinstaller options… ~D:\Hello.py

另一种用法

pyinstaller "C:\Documents and Settings\project\myscript.spec"

pyinstaller "D:\Hello.py"这个简单直接。笔者写了一个简单的输入姓名的程序name.py,转化后就是文件类型为 Compiled Python File,可以直接在windows上运行。

2.OPTIONS 指令下选项说明见我的下一篇文章



这篇关于Python从入门到放弃 (二) 将.py文件转化为win 10下的可执行程序的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!


扫一扫关注最新编程教程