Python: Hide console when executing the command line - python

I have a python script that contains code to execute the command line. I generated .exe file from this script using pyinstaller. This is the command I use to freezes my python script:
pyinstaller --onefile --noconsole sriptName.py
When I open my exe file. The console still opens and shows the output of the command line executed in my script
How can I hide this console?

When you run PyInstaller on your project, does a .SPEC file also appear?
If so, edit the .SPEC file's exe field like so:
exe = EXE(
...,
console=False,
...
)
Then run PyInstaller on the .SPEC file.
If a .SPEC file didn't appear before, try running PyInstaller on your project without any parameters (so just pyinstaller myProgram.py). A .SPEC file should appear and you can edit it as above and then rerun PyInstaller.

Related

The .exe file I converted from Pyinstaller can't be run

I have made a python file and it is a pygame. I want to convert it into a .exe file.
So, I used PyInstaller
I did pyinstaller --one file -w main.py
and it made a .exe file.
However, when I double-click it, it popped up a
Not Running warning
Why does it occur and what should I do to prevent it?

run python program via clickable desktop icon

I've made a python program using Tkinter(GUI) and I would like to enter it by creating a dedicated icon on my desktop. (I want to send the file to my friend, without him having to install python or any interpreter)
the file is a some-what game that I want to share with friends and family, which are not familiar with coding.
You can simply use Pyinstaller to create a standalone .exe.
Run this from the Windows cmd to create a standalone executable file: pyinstaller.exe --onefile --noconsole --icon=your_image_here.ico app.py
you can install Pyinstaller by using pip
pip install pyinstaller
go to the directory where your file is saved and type:
pyinstaller.exe --onefile --windowed path/to/your/file.py
--onefile (compresses your files into one .exe file)
--windowed (removes the console when you run your file)
path/to/your/file.py (or simply file.py when you want to convert the file in the same directory)
if you have any error using it, remove the --windowed flag and run file.exe on command line to see the error

Custom icon using pyinstaller is not working

I used below command to get a custom icon for my .exe file but my custom icon doesnt appear on my exe file even after successful completion of the command :
pyinstaller --noconsole --onefile
--icon="C:\Users\anubhav.jhalani\Desktop\index.ico" run.py
What am I doing wrong here?

How to call Pyinstaller via a .bat file?

Currently to use Pyinstaller I open a Python command console then go to the location of my .spec file using cd and type pyinstaller Software.spec. It works well but I'd like to automate that and have a .bat file do those operations for me.
I have made small .bat files to execute my programs (see below) and I thought the structure for calling Pyinstaller would be close but I'm groping.
C:\Python\python-3.6.3.amd64\python Software.py
pause
Failed attempts of .bat files to run Pyinstaller include:
C:\Python\python-3.6.3.amd64\python\Scripts\pyinstaller.exe Software.spec
C:\Python\python-3.6.3.amd64\python CALL :pyinstaller Software.spec
Any idea would be welcome.
Solution
We need to execute Pyinstaller.exe with Python like so:
"path\to\python.exe" "path\to\pyinstaller.exe" "path\to\my\Software.spec"
Typically you need to call the path to the script as well, but also always double quote paths to ensure you do not get some whitespace kreeping in. Always call the full extension name of an executable as good measure.
"C:\Python\python-3.6.3.amd64\python.exe" "C:\path\to\Software.py"
You can also start it, but in the same batch window:
start /b "" "C:\Python\python-3.6.3.amd64\python.exe" "C:\path\to\Software.py"
or with pyinstaller.exe example:
"C:\Python\python-3.6.3.amd64\python\Scripts\pyinstaller.exe" "C:\path\to\Software.spec"
A simple drag and drop of any python file will result in a compiled exe file in the dist folder created from executing the pyinstaller script.
#echo off
PATH = "%PATH% + %USERPROFILE%\AppData\local\programs\python\Python38"
:: %1 is the file dropped on the batch file
pyInstaller --windowed --onefile %1
If you change %1 to the filename it will also work. Save the script as Pyinst.bat then drag and drop a python file onto it.

convert .pyw to .exe and have the command line not open

I want the command line to not open because a tkinter interface will open.
I am using pyinstaller so it works when python isn't installed. I am using python 3.6.0.
Can I also have it so it is one exe file that doesn't need the other things to run.
To avoid the command line window, add --windowed to your PyInstaller command line.
To create an one-file bundle, add --onefile to your PyInstaller command line.
These are documented in PyInstaller's options. https://pyinstaller.readthedocs.io/en/stable/usage.html#options

Categories

Resources