I'm trying to create a exe file from my .py file but using both, PYINSTALLER and PY2EXE gives me a strange error:
The google.py file that I'm tying to create EXE existis in the requested directory and both PYINSTALLER and PY2EXE are correctlly installed.
Does anyone know the root cause of the issue? How could I create a exe file from a .PY?
As I know you must use argument --onefile Without it the libraries will be distributed as separate file along with the executable.
Here is exaple:
pyinstaller --onefile script.py
Related
I have a code who is depended on Qt, PyQt, VTK, ITK, libs.
using CMAKE to build
Environment : Windows
I want to distribute EXE who has cxx, py files and related dlls
I have tried to compile and got executable but my python files are remaining necked.
I don't want to share python files as a script.
how we can make those python files as a dlls
python is often a hard language to turn to exe but the best way to do so is using the pyinstaller package. Installed by pip install pyinstaller and can turn a .py file to a .exe by pyinstaller --onefile FILENAME.py in CMD. After that your exe file should be stored in a folder called disk. The other files can just be included in the same file as the exe.
docs: https://pyinstaller.org/en/stable/
I used pyinstaller to compile my pygame code into an exe file using this command:
pyinstaller --onefile -w gamename.py
But after moving it to a different directory and running it, it gives me file not found errors and file doesn't exist errors. ALL help is greatly appreciated. Thanks.
Possibly, you have some file locations in your code as strings. These external files are not part of your code, so they are not compiled into exe.
Check this answer about adding files in pyinstaller
I was build one exe file with python installer.
The code is using numpy package and pyqt UI builder.
I installed numpy in virtulal environment of my working folder.
It is working in python script, then I build it as Exe file, then it is not working.
enter image description here
please help me if you know about the issue.
Thanks
While using pyinstaller to convert .py file to .exe having large dependencies (like numpy, pandas) following these steps would solve the ModuleNotFound error:
Install the PIP packages in the project directory (with virtual environment activated)
Change the hook file
Navigate to \venv\Lib\site-packages\PyInstaller\hooks
If there is a hook-numpy.py file, edit the script to:
from PyInstaller.utils.hooks import collect_submodules
hiddenimports = collect_submodules('numpy._libs')
Before converting to .exe file, make .spec file using the following command:
pyi-makespec — onefile program_name.py
Edit the .spec file (open using notepad)
append the libraries to the hiddenimports list
...
hiddenimports = ['numpy']
...
Compile the script using the .spec file with the following command:
pyinstaller — onefile program_name.spec
Finally, find the .exe file in the dist folder, and run it.
I tried making my python file into an exe using pyinstaller main.py --onefile --noconsole
.I was getting an error when I tried opening the exe from dist so i used --debug=all and it said pyinstaller: error: the following arguments are required: scriptname.
What exactly do i do im not too sure as its my first time.
To convert a python file to exe:
Make sure you have pyinstaller installed and up to date
pip install pyinstaller
in PowerShell type the following:
pyinstaller --onefile -w 'youfilename.py'
The file name should come out as 1.exe
Make sure are in the right directory
If you have more doubts use this link: https://www.geeksforgeeks.org/convert-python-script-to-exe-file/
A python script uses a .so file.
I made an exe for this python script using PyInstaller.
But when I execute the generated exe, it is unable to locate this .so file
So how to link this .so to a python code that will get converted to a .exe
Note: when running the .py program, if I set the location of .so in LD_LIBRARY_PATH, it executes the program correctly but once I make the exe using
pyinstaller script.py --onefile
(with .so in the same directory), it doesnt find the .so file..
Thank you in advance
You need to make sure that your . so file is in your system library path as well as your python library path. Setting your LD path is a quick fix. PyInstaller will need it in your system path. Depending on your Windows version it's Environment variables>PATH.