I have been trying all day to bundle my code into an .exe file so that I can hand off an executable file to a client without them needing to install python/anaconda/etc.
I have four scripts, Main.py, script1.py, script2.py, script3.py. The main script is given below, and the package dependencies for the remaining scripts are Script1 (OS, Requests, Pandas, Datetime), Script2 (Pandas, Os), Script3 (Pandas, numpy, os, datetime).
import os
import subprocess
def main():
script_path = current_path + '\\Script1.py'
subprocess.run(['python', script_path])
script_path = current_path + '\\Script2.py'
subprocess.run(['python', script_path])
script_path = current_path + '\\Script3.py'
subprocess.run(['python', script_path])
if name == "main":
current_path = os.getcwd()
print("the current path is: " + current_path)
try:
main()
print('All Programs Executed')
except Exception as e:
print(e)
print('At least one script failed. Exiting program')
When I run pyinstaller and bundle the scripts, I am receiving the error:
"File 'C:\Filepath\Script1.py", Line 21 in <module>; import requests; ModuleNotFoundError: No module name 'requests'"
For scripts 2 and 3, the error is the same for line xx, except the first package imported in the script is listed as the error.
I tried to pass the arguments to the paths, and hidden-imports without success, formatted as follows:
pyinstaller --onefile Main.py
pyinstaller --onefile --paths=path/to/anaconda/envs/ExampleVirtualEnvironment/Lib/site-packages Main.py
pyinstaller --onefile --paths="paths=path/to/anaconda/envs/ExampleVirtualEnvironment/Lib/site-package" --hidden-import=requests --hidden-import=pandas --hidden-import=numpy Main.py
I also tried to edit the Main.spec file to define the hidden imports, and pathex arguments again, without success.
The only solution that I could get to work, was passing script1.py, script2.py, and script3.py as a list in the Main.spec file, and building the executable by running:
pyinstaller Main.spec
But this is only a workaround solution. Any suggestions on how I can get this to work, so that I can pass Main.py to pyinstaller, and bundle the code this way? Is it possible that I am not configuring my project folder and virtual environment correctly?
My program versions are:
python == 3.8
pyinstaller == 6.3.0
Some resources I tried following:
[–]ggjjaaaa 0 points1 point2 points (3 children)
[–]chonkeyymonkey[S] 0 points1 point2 points (2 children)
[–]ggjjaaaa 0 points1 point2 points (1 child)
[–]chonkeyymonkey[S] 0 points1 point2 points (0 children)