Reputation: 67
Problem 1: I decided to reorganize my program into a package and this is the file structure:
venv
-<program_folder>
-__init__.py
-GUI.py
-<pictures_folder>
-icon.png
-<modules_folder>
-__init__.py
-a.py
-b.py
The GUI.py imports both a.py and b.py (along with other standard libraries). I was unable to import these modules using:
from modules_folder import a.py, b.py
Presumably because I was using a virtual environment to run the code. So, following online advice, I added the module directory to the path using the following code (this code works properly):
d = dirname(abspath(__file__)) + '\\modules_folder'
sys.path.insert(1,d)
import a.py, b.py
I'm trying to make the .exe under my venv using the command 'pyinstaller GUI.spec' but my modules are not included. It's unclear how to properly add these files using either hooks, pathex, hiddenimports, hookpath etc. I've already tried to add the modules directory to each variable in the spec file. What's the correct way to do this?
a = Analysis(
['GUI.py'],
pathex=['C:\\Users\\.\\Lib\\site-packages'],
binaries=[],
datas=[],
hiddenimports=[],
hookspath=['C:\\.\\modules_folder'],
hooksconfig={},
runtime_hooks=[],
excludes=[],
win_no_prefer_redirects=False,
win_private_assemblies=False,
cipher=block_cipher,
noarchive=False,
Problem 2: Cannot use --onefile
or --noconsole
command. Does this mean any .exe will necessitate a console?
Environment:
Upvotes: 0
Views: 1279
Reputation: 67
So the example I posted actually worked.
The issue was one module imports other packages. I just added these imports to the main.py file to make sure they were found by pyinstaller. Alternatively I probably could add them to hiddenimports in the .spec file but this didn't work so I stayed with the simple solution.
Upvotes: 1