Configuring Pycharm to run Pyinstaller
Asked Answered
L

7

30

Yes I want to create a run configuration in PyCharm to run Pyinstaller and get my executable. According to the Pyinstaller documentation you should be able to locate an python script called pyinstaller-folder/pyinstaller.py after the installation, but it wasn't there. Then I look carefully and found this other one named pyinstaller-folder/__main__.py which should be the same <--(me wild guessing), so I set up my running configuration like this:

enter image description here

After running it, is giving me this error:

/usr/local/Cellar/python3/3.4.3/bin/python3.4 /usr/local/lib/python3.4/sit

e-packages/PyInstaller/__main__.py --onefile --nowindow --osx-bundle-identifier=jg.optimizer -F --name=genoptimizer optimizer/manage.py
Traceback (most recent call last):
  File "/usr/local/lib/python3.4/site-packages/PyInstaller/__main__.py", line 26, in <module>
    from . import __version__
SystemError: Parent module '' not loaded, cannot perform relative import

Process finished with exit code 1

It seems to require a parent module to run but, how would that look like?

Lafave answered 25/11, 2015 at 0:36 Comment(0)
C
23

The PyInstaller package is a runnable module and can be run using python -m PyInstaller. To configure it as a run target in PyCharm, leave the "Script" field blank, write -m PyInstaller in the "Interpreter Options" field, and put the PyInstaller parameters into the "Script Parameters" field.

For example:

pyinstaller pycharm configuration

PyCharm will complain that the "Script" field is empty, but it will let you run the configuration anyway.

Chapen answered 25/11, 2015 at 21:23 Comment(2)
How do you get to this window in PyCharm?Culbertson
@StevenM.Vascellaro Click on the debug configurations button in the top right corner, and select "Edit Configurations..." from the menu. Then fill in the information in a new Python profile using the editor.Formless
H
26

After more than two years, perhaps there is a better option.

In the PyCharm menu go to File -> Settings.
In the Settings dialog find Tools -> External tools and use the green + to add a new external tool.

For example:

enter image description here

Then, the IDE will allow you to run it on any python script. Right click on the file and the context menu will show External tools -> PyInstaller.

Hanghangar answered 22/6, 2018 at 11:49 Comment(2)
Thanks so much friend!! So easy, so convenient! :) Any idea how to suppress all the warnings? They're kind of not reassuring..Hellman
Great job figuring this out!Aeniah
C
23

The PyInstaller package is a runnable module and can be run using python -m PyInstaller. To configure it as a run target in PyCharm, leave the "Script" field blank, write -m PyInstaller in the "Interpreter Options" field, and put the PyInstaller parameters into the "Script Parameters" field.

For example:

pyinstaller pycharm configuration

PyCharm will complain that the "Script" field is empty, but it will let you run the configuration anyway.

Chapen answered 25/11, 2015 at 21:23 Comment(2)
How do you get to this window in PyCharm?Culbertson
@StevenM.Vascellaro Click on the debug configurations button in the top right corner, and select "Edit Configurations..." from the menu. Then fill in the information in a new Python profile using the editor.Formless
B
7

The run command has changed a bit since the accepted answer. You can now select a module to launch rather than editing the interpreter options.

As of writing this answer, here is how it looks like:

enter image description here

Notes:

  • This solution requires to install PyInstaller in the virtual environment of the project.
  • I am using PyCharm pro 2020.1
  • Old solution should still work
  • Using external tool is still a possibility. Which solution you choose is a matter of personal preference.
Barbiturism answered 20/4, 2020 at 19:46 Comment(0)
S
3

Install pyinstaller in pycharm, then open the pycharm terminal and write python -m PyInstaller.

Syrup answered 2/4, 2019 at 17:40 Comment(0)
S
2

So as Pycharm has newly updates, my case was a bit different as I installed pyinstaller from the interpreter settings as the following picture shows:

enter image description here

For Linux Users:

You could install it in both Python 2.7 or Python 3.7+. Make sure to get the path of where pyinstaller was stored.Then in the Settings option, try to find Tools -> External tools and add a new external tool as the following picture shows: enter image description here

For Windows users:

If you are using Pycharm or any virtual environment. Unfortunatelly Pycharm creates its local vertual environment in venvpath once you indicate the interpreter. So, you should set the external tool (pyinstaller) to the real path of your python 3.7 .exe as the picture shows here

Scalar answered 5/2, 2019 at 19:22 Comment(0)
T
1

For those of us on Windows with Anaconda trying to figure this out, I found it easiest to just set up a Bash Configuration (I believe you need the BashSupport plugin for this), and set:

  • Script: pyinstaller (assuming pyinstaller is in your path, if not, the full path)
  • Interpreter path: C:\Windows\system32\cmd.exe (yes, a bash configuration can just use the standard command program)
  • Interpreter options: /C
  • Program arguments: script_name.py (along with any other pyinstaller arguments)
  • Working Directory: C:\Path\To\Script
Timeless answered 13/9, 2017 at 14:29 Comment(0)
A
0

I used it this way:

-y --clean --console --noupx --name="$Prompt$" "$FileName$"

Edit Tool

Due to $Prompt$ macro, every time I want to build it (right click on code -> External Tools -> PY3_PyinstallerFreeze), it even asks the name

Input

PS - I would recommend to use global PyInstaller (instead of virtual environment one) like C:\Python39\Scripts\pyinstaller.exe above

Arhat answered 26/8, 2023 at 11:48 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.