pyinstaller --onefile script.py
script.py
while True:
x=raw_input('enter code: ')
exec(x.strip())
copy new module into root of script.exe
'newmodule'
run script.exe
enter code: import newmodule
-------this errors, module not found
a way to do this?
Related
i made a python script(flask) that use html and generate a local host link to open my website i also imported some deep learning models to my project what i want is i want to make an exe file that gives me the output is the local host link so i used this command to make it
pyinstaller --onefile main.py
but when i run my exe file it gives me this error
no module named cv2
i also tried this command
pyinstaller spec_an_API.py --onefile --add-data "templates";"templates" --add-data "static";"static"
but same problem
not that my program has no errors i tried to run it from pycharm and it works well
I'm trying to build an exe file from a python game using PyBox2D and Pyglet.
When I build the exe there occurs an error that a module cannot be imported:
Unable to import the back-end pyglet: module 'gui.backends' has no attribute 'pyglet_framework'
I guess this happens because this file only gets imported indirectly/hidden from another file with __import__()
This is my project hierarchy:
I've tried to add the file to pyinstaller on multiple ways. From the directory /SpaceJam/building I've tried calling:
pyinstaller.exe --onefile "../game/spacejam.py" --hidden-import="gui/framework/backends/pyglet_framework.py"
pyinstaller.exe --onefile "../game/spacejam.py" --hidden-import="../gui/framework/backends/pyglet_framework.py"
pyinstaller.exe --onefile "../game/spacejam.py" --hidden-import="../gui/framework/backends/pyglet_framework"
pyinstaller.exe --onefile "../game/spacejam.py" --hidden-import="../gui/framework/backends/*"
but none of that seemed to change anything in the error message.
I feel like I'm missing something obvious. Does somebody have an idea what I might be doing wrong or why the --hidden-import argument doesn't seem to work?
That argument expects a module name, not a filesystem path. How would you import it?
I'm not totally clear on how your project is set up, but try
--hidden-import gui.backends.pyglet_framework
I am trying to create an executable with pyinstaller for a python script with tix from tkinter. The following script also demonstrates the error:
from tkinter import *
from tkinter import tix
root = tix.Tk()
root.mainloop()
I have Python 3.9 installed and the script runs fine and works as intended but after using pyinstaller to create an executable, the .exe file fails to run because it can't find the package Tix.
One of the solutions mentioned here which is to copy the C:\Python39\tcl\tix8.4.3 folder to the dist directory for the executable worked for me. The executable runs as intended after copying the folder, but I would like to package the script into one exe without needing to supply the tix8.4.3 folder.
Is there anyway to package the tix folder when building the executable with pyinstaller?
It works for me using below command to generate the executable:
pyinstaller -F --add-data C:\Python38\tcl\tix8.4.3;tcl\tix8.4.3 main.py
Note that I use PyInstaller 4.7 and Python 3.8.12 under Windows 7.
you have error in code:
from tkinter import *
from tkinter import tix
root = tix.Tk() # Here it was TK
root.mainloop()
I am trying to compile my python file to executable file using pyinstaller.
I put all the dependent packages and the source python file in one folder.
And I tried pyinstaller --onefile [my python file name].py
It succeeded to build the exe file. However, the exe file fails to run and I checked the warn-[my python script name].txt, there is one invalid module from which I imported the class to my python code.
In my code, I also imported another module, it was working.
from autobench.inst import power, func_gen
from autobench.i2c.aa_i2c import AAreadWrite
invalid module named autobench.i2c.aa_i2c - imported by C:\Users\jgou\Desktop\test\AP711T_OTP_Program.py (top-level)
Autobench and inst and i2c are folders. Power, func_gen and aa_i2c are python files (.py), AAreadWrite is class in aa_i2c file.
Please suggest what is wrong and how to fix this one. Thanks.
Error message from running my exe:
ModuleNotFoundError: No module named 'openpyxl'
testHi.py
#simple test to see if openpyxl module works
import openpyxl
print ("hi")
input()
hook-openpyxl.py
# taken from pyinstaller dev team, store in same dir as testHi.py
from PyInstaller.utils.hooks import collect_data_files
datas = collect_data_files('openpyxl')
cmd line input:
pyinstaller.exe --onefile --icon=py.ico --additional-hooks-dir=. hiTest.py
I run the the hiTest and get the error above.
I have looked everywhere for this solution. Can anyone tell me what I am doing wrong.
I fixed my issue by installing it through Pip, rather than install the package through Pycharm, and Pyinstaller was able to find the package.
I got the idea from looking through the text in the command prompt and saw it was loading modules that I had installed via Pip and not through Pycharm.
I was able to get this working using auto-py-to-exe (which uses pyinstaller) by including the following folders/files from my python library into the same folder that I run pyinstaller from:
jdcal.py
openpyxl (folder)
et_xmlfile (folder)
pyinstaller command:
pyinstaller -y -F "[directory]/myscript.py"
Notes on Library Location:
Windows library location for me was: C:\users[username]\AppData\Local\Programs\Python\Python37-32\Lib
The packages were in the "site_packages" folder
use
--hiddenimport openpyxl
long with the previous solutions, it worked for me, I was able to enforce the import of openpyxl.
You was quite close. :-)
I fixed the problem by modifying the "hook-openpyxl.py" file. The command collect_data_files('openpyxl') actually returns an empty list. But there is another command collect_submodules which seems to do what we want. So my "hook-openpyxl.py" file looks like this.
from PyInstaller.utils.hooks import collect_submodules
hiddenimports = collect_submodules('openpyxl')
I placed the "hook-openpyxl.py" file in the same directory like my spec file. In the spec file I set to location of the new hook file
a = Analysis(
...
...
hookspath=['.'],
...
...
...
I guess, you will have the same result with your command line parameter
pyinstaller.exe --onefile --icon=py.ico --additional-hooks-dir=. hiTest.py
My environment
Python=3.8
openpyxl=3.0.10
PyInstaller=4.8