Настройка Pycharm для запуска Pyinstaller
Да, я хочу создать конфигурацию запуска в PyCharm, чтобы запустить Pyinstaller и получить свой исполняемый файл. Согласно документации Pyinstaller, вы должны быть в состоянии найти скрипт python с именем pyinstaller-folder/pyinstaller.py после установки, но его там не было. Затем я внимательно посмотрел и обнаружил еще одну pyinstaller-folder/__main__.py именем pyinstaller-folder/__main__.py которая должна быть такой же <- (я догадываюсь), поэтому я настроил свою рабочую конфигурацию так:
После запуска выдает эту ошибку:
Кажется, для запуска требуется родительский модуль, но как это будет выглядеть?
5 ответов
Пакет PyInstaller является исполняемым модулем и может быть запущен с помощью python -m PyInstaller . Чтобы настроить его как цель запуска в PyCharm, оставьте поле «Script» пустым, напишите -m PyInstaller в поле «Параметры интерпретатора» и поместите параметры PyInstaller в поле «Script Parameters».
PyCharm будет жаловаться, что поле «Script» пуст, но оно все равно позволит вам запустить конфигурацию.
После более чем двух лет, возможно, есть лучший вариант.
В меню PyCharm перейдите в Файл → Настройки.
В диалоговом окне «Настройки» найдите «Инструменты → Внешние инструменты» и используйте зеленый +, чтобы добавить новый внешний инструмент.
Затем IDE позволит вам запустить его на любом скрипте Python. Щелкните правой кнопкой мыши по файлу, и в контекстном меню появятся Внешние инструменты → PyInstaller.
Так как у Pycharm недавно появились обновления, мой случай немного отличался, поскольку я установил pyinstaller из настроек интерпретатора, как показано на следующем рисунке:
Для пользователей Linux:
Вы можете установить его как в Python 2.7 и в Python 3.7+ . Убедитесь, что pyinstaller нашли путь к pyinstaller хранения pyinstaller Затем в параметре «Настройки» найдите «Инструменты → Внешние инструменты» и добавьте новый внешний инструмент, как показано на следующем рисунке:
Для пользователей Windows:
Если вы используете Pycharm или любую виртуальную среду. К сожалению, Pycharm создает свою локальную вертикальную среду на пути venv только вы указываете interpreter . Итак, вы должны установить внешний инструмент (pyinstaller) на реальный путь вашего python 3.7.exe, как показано на рисунке
Install pyinstaller in pycharm
Before getting to the point, we have to install this plugin on pycharm.
Open the terminal according to the method shown in the figure below (this I feel is equivalent to running cmd on your computer),
Then you still have to find your python installation path. For C drive, it seems to use the command: pip install pyinstaller. For D drive, find the directory to install.
For the version of python3, try to change the command to: pip3 install pyinstaller
Question leads
I used python to make a small program on my computer before (very simple, I won’t go into details), but when I wanted to send this py file to generate exe for others to see, I found that it was used on my computer There are always some problems with cmd installation. I really tried the method overnight. Pip was also updated, various plug-ins were also downloaded, and the files of pyinstaller were also downloaded later (unfortunately, I did not find the location to install, and the installation was not good). So I found a way to install on pycharm.
Open the project file for operation
Open the project you want to package as exe, click file in the upper left corner, click setting to enter the setting interface;
Then find your own file, the following picture is the project: file name, click on it;
After clicking open, select the corresponding file in the project interpreter, and then click the plus sign on the right to add the plug-in we need: pyinstaller;
The opened interface is as follows, let’s search for the plug-in we want to add: pyinstaller, click install package in the lower left corner according to the icon, and then wait for a green prompt to appear after the installation is complete, we can close the setting interface (setting interface Remember to click ok to exit).
Как установить pyinstaller в pycharm
This question might have gotten lost in the other thread so here it is again.
I was able to get PyInstaller to work from the command line (thanks for the replies!), but that’s only for Python 2.7.
So now, I’m trying to get it working inside PyCharm, but so far, not quite.
I’ve imported both PyIntaller and PyInstaller Hooks.
My setup.py code looks like this:
setup.py», line 4
pyinstaller SearchBinaryFile.py
^
SyntaxError: invalid syntax
Any suggestions on what I need to do I can build a standalone file using PyInstaller within PyCharm (so I can use 3.6 with f-strings, etc.)?
Как установить pyinstaller в pycharm
Use of pyinstaller
Go to the directory i want to package,Execute package command
opts optional parameters
parameter | meaning |
---|---|
-f | -onefile, packaged into an exe file |
-d | -onefile, create a directory,Contains exe files but depends on many files (default option) |
-c | -console, -nowindowed, use the console,Windowless (default) |
-w | -windowed, -noconsole, use window,No console |
pyinstaller support configuration in pycharmThe first step:Setting —->Tools —->External Tools,Click the plus sign in the upper left corner
Step 2:Property configuration
name:pyinstaller exe (can be customized)
program:The path where the pyinstaller.exe file is located,You can refer to the following path
(C:\ users \ administrator \ appdata \ local \ programs \ python \ python36-32 \ scripts \ pyinstaller.exe)
arfuments:-f $filenamewithoutextension $.py —noconsole
working:$filedir $
Step 3:Save the settings.ExitPackaging application examples of pyinstaller
The new helloworld.py program is as follows
After clicking the program i want to package,In Tools —->External Tools —->pyinstaller
The execution process is as follows
When you see the last word successful, you know that it is packed.File manager goes into the folder where your packager is located
Open dist folder
Run the program
ok, you’re done,A simple python application installation package was successfully packaged.