如何使用PyInstaller从PyCharm项目创建可执行文件?

时间:2016-03-31 15:14:56

标签: python pycharm pyinstaller

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

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

  

' pyinstaller.exe'不被视为内部或外部命令,   可操作程序或批处理文件。

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

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

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

2 个答案:

答案 0 :(得分:1)

从项目目录运行pyinstaller,但将其称为.exe的完整目录,如C:\ PathTo \ Pyinstaller.exe

所以你的cmd看起来像

C:\用户\用户\ PycharmProjects \ myproject的> C:\ PathTo \ pyinstaller.exe --onefile --windowed myprogram.py

答案 1 :(得分:1)

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

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添加到系统路径(请参阅here)。

相关问题