如何使用 PyInstaller 从 PyCharm 项目中创建可执行文件? [英] How do I create an executable file out of a PyCharm project using PyInstaller?

查看:53
本文介绍了如何使用 PyInstaller 从 PyCharm 项目中创建可执行文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 PyCharm 中编写了一个项目,其中包含一个 .py 文件、一个 .txt 文件、一个 .ico 文件和用于 PyCharm 项目的常规 .idea 文件夹.全部保存在C:\Users\user\PycharmProjects\myproject.

I have written a project in PyCharm consisting of a .py file, a .txt file, a .ico file and the regular .idea folder for PyCharm projects. All is saved in C:\Users\user\PycharmProjects\myproject.

我想使用 PyInstaller 创建一个单文件 .exe.但是当我运行命令 pyinstaller.exe --onefile --windowed myprogram.py 时,出现以下错误:

I would like to create a single-file .exe using PyInstaller. But when I run the command pyinstaller.exe --onefile --windowed myprogram.py, I get the following error:

'pyinstaller.exe' 未被识别为内部或外部命令,可运行的程序或批处理文件.

'pyinstaller.exe' is not recognized as an internal or external command, operable program or batch file.

据我所知,这是因为pyinstaller.exe"不在我运行命令提示符的位置.

To my understanding, this is because "pyinstaller.exe" is not in the location in which I ran the command prompt.

但是,如果我在 pyinstaller 文件夹 (C:\Users\user\AppData\Local\Programs\Python\Python35-32\Scripts) 中运行 cmd,我的项目不存在.所以这也行不通.

However, if I run cmd in the pyinstaller folder (C:\Users\user\AppData\Local\Programs\Python\Python35-32\Scripts), my project isn't there. So that doesn't work either.

我需要做什么才能将我的程序放入一个 .exe 文件中?

What do I need to do to get my program into one .exe file?

推荐答案

您可以指定任一文件为绝对路径:

You can specify either file as absolute path:

C:\Users\pemho\AppData\Local\Programs\Python\Python35-32\Scripts\pyinstaller.exe --onefile --windowed myprogram.py 应该在项目文件夹中工作,以及 pyinstaller 文件夹中的 pyinstaller.exe --onefile --windowed C:\Users\user\PycharmProjects\myproject\myprogram.py.

C:\Users\pemho\AppData\Local\Programs\Python\Python35-32\Scripts\pyinstaller.exe --onefile --windowed myprogram.py should work from the project folder, as well as pyinstaller.exe --onefile --windowed C:\Users\user\PycharmProjects\myproject\myprogram.py from the pyinstaller folder.

或者,您可以将 C:\Users\pemho\AppData\Local\Programs\Python\Python35-32\Scripts 添加到您的系统路径(请参阅 此处).

Alternatively, you can add C:\Users\pemho\AppData\Local\Programs\Python\Python35-32\Scripts to your system PATH (see here).

这篇关于如何使用 PyInstaller 从 PyCharm 项目中创建可执行文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆