Converting .py to .exe Python 3.6 - python

I have been trying to convert my .py to .exe. Unfortunately, I haven't been successful. After pip install py2exe and using build_exe myscript.py I get multiple errors such as the following:
\...\py2exe\mf3.py", line 120, in import_hook
module = self._gcd_import(name)
\...\py2exe\mf3.py", line 274, in _gcd_import
return self._find_and_load(name)
I don't understand what this mean. Does it mean there is something wrong with my code? (Weird, cause it runs perfectly). Or is it just py2exe that can't do it??
Thanks a lot

I'm not sure about py2exe. I use pyinstaller for creating .exe and it works just fine.
pip install pyinstaller
pyinstaller --onefile filename.py
And that's it. Your .exe is in the dist folder (dist is created automatically by pyinstaller in the directory where the .py file is).
If you don't want a console (if you have a GUI / writing a background process / have no use for I/O or stderr),
pyinstaller --onefile --noconsole filename.py
If you want a customized icon,
pyinstaller --onefile --noconsole -i iconfile filename.py
Edit: The --noconsole switch is ignored in Linux as far as I know.

Related

Pyinstaller raises error: system cannot access the file

I'm having some trouble using pyinstaller to generate executables. After using the command pyinstaller --onefile "filename.py", an error is raised, mentioning that the system cannot access the file, as follows:
As anyone dealt with such problem before?
Pyinstaller reads a Python script written by you. For the majority of programs, this can be done by: pyinstaller yourscript.py
But if it doesn't work for you, try using this: pyinstaller --onefile --windowed yourscript.py

.exe built with pyinstaller is only opened while running from cmd

I created a pyinstaller .exe that is built correctly without any mistakes with pyinstaller. When I run it from the cmd, it runs perfectly, but when I double click the .exe file, it does not work. I read that has to do something with PyQt5, but I didn't make it work. This is the creation statement:
pyinstaller --paths
C:\Users\430350\AppData\Local\Programs\Python\Python36\Lib\site-
packages\PyQt5\Qt\bin "path" --hidden-import numpy.core._dtype_ctypes --hidden-
import fix_qt_import_error --icon=icon.ico --noconfirm
Thanks in advance!
Don’t know if it’s the same in Windows. But using pyinstaller in Linux with the -F option (pyinstaller -F file.py) with a PyQt5 project I have to add to the binary file folder .qss and .ui files manually my resource.py file and enclosed png. are not read too. Also did you check the versione you are using ? Python 2 vs 2, 3 vs 3 etc ... v

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

I cannot include an icon when I compile my program

I am using pyinstaller to compile my programs. I cannot include files with the -i option. It doesn't compile and instead gives an error. The whole compiler crashes. My error code is here: https://pastebin.com/raw/UBTTMmke I was using powershell after I shift+right-clicked the directory in explorer.
Make sure you 'cd' first on your script's folder destination.
Make sure your image file is converted as .ico file and also in your script's folder
Then try compiling your script as:
pyinstaller --onefile --icon Your_logo.ico My_script.py
Also if you want your console not to pop up when the script is running you can use the 'windowed' option:
pyinstaller --onefile --windowed --icon Your_logo.ico My_script.py

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