How do I create an executable file out of a PyCharm project using PyInstaller?

心已入冬 提交于 2020-01-03 05:34:49

问题


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.

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' is not recognized as an internal or external command, operable program or batch file.

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

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.

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


回答1:


You can specify either file as absolute path:

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.

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




回答2:


Run pyinstaller from your project directory, but call it as the full directory to the .exe like C:\PathTo\Pyinstaller.exe

so your cmd would look something like

C:\Users\user\PycharmProjects\myproject> C:\PathTo\pyinstaller.exe --onefile --windowed myprogram.py



来源:https://stackoverflow.com/questions/36337376/how-do-i-create-an-executable-file-out-of-a-pycharm-project-using-pyinstaller

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!