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
Related
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
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
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
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.
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.