OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

Problem when adding dependencies to pyinstaller in Windows

  • Thread starter Thread starter Psionman
  • Start date Start date
P

Psionman

Guest
I am attempting to create an executable file in Windows 10 Pro from a python script that uses import

Code:
# main.py
from termcolor import cprint

def main() -> None:
    cprint('Hello', 'red')

if __name__ == '__main__':
    main()

I have installed poetry and created an environment

Code:
 poetry new test

added termcolor

Code:
poetry add termcolor

If I enter the poetry shell and run the script

Code:
python main.py

it works as expected.

When I create the exe

Code:
pyinstaller --onefile main.py

and try to run the exe it generates ModuleNotFoundError for termcolor

This is my main.spec file

Code:
a = Analysis(
    ['main.py'],
    pathex=['.', 'C:\Users\... path to ...\site-packages'],
    binaries=[],
    datas=[],
    hiddenimports=[],
    hookspath=[],
    hooksconfig={},
    runtime_hooks=[],
    excludes=[],
    noarchive=False,
    optimize=0,
)
pyz = PYZ(a.pure)

exe = EXE(
    pyz,
    a.scripts,
    [],
    exclude_binaries=True,
    name='main',
    debug=False,
    bootloader_ignore_signals=False,
    strip=False,
    upx=True,
    console=True,
    disable_windowed_traceback=False,
    argv_emulation=False,
    target_arch=None,
    codesign_identity=None,
    entitlements_file=None,
)
coll = COLLECT(
    exe,
    a.binaries,
    a.datas,
    strip=False,
    upx=True,
    upx_exclude=[],
    name='main',
)

What am I doing wrong?
<p>I am attempting to create an executable file in Windows 10 Pro from a python script that uses <em>import</em></p>
<pre><code># main.py
from termcolor import cprint

def main() -> None:
cprint('Hello', 'red')

if __name__ == '__main__':
main()
</code></pre>
<p>I have installed <em>poetry</em> and created an environment</p>
<pre><code> poetry new test
</code></pre>
<p>added <em>termcolor</em></p>
<pre><code>poetry add termcolor
</code></pre>
<p>If I enter the poetry shell and run the script</p>
<pre><code>python main.py
</code></pre>
<p>it works as expected.</p>
<p>When I create the exe</p>
<pre><code>pyinstaller --onefile main.py
</code></pre>
<p>and try to run the exe it generates ModuleNotFoundError for <em>termcolor</em></p>
<p>This is my <em>main.spec</em> file</p>
<pre><code>a = Analysis(
['main.py'],
pathex=['.', 'C:\Users\... path to ...\site-packages'],
binaries=[],
datas=[],
hiddenimports=[],
hookspath=[],
hooksconfig={},
runtime_hooks=[],
excludes=[],
noarchive=False,
optimize=0,
)
pyz = PYZ(a.pure)

exe = EXE(
pyz,
a.scripts,
[],
exclude_binaries=True,
name='main',
debug=False,
bootloader_ignore_signals=False,
strip=False,
upx=True,
console=True,
disable_windowed_traceback=False,
argv_emulation=False,
target_arch=None,
codesign_identity=None,
entitlements_file=None,
)
coll = COLLECT(
exe,
a.binaries,
a.datas,
strip=False,
upx=True,
upx_exclude=[],
name='main',
)
</code></pre>
<p>What am I doing wrong?</p>
 

Latest posts

O
Replies
0
Views
1
OrangeRind
O
D
Replies
0
Views
2
Domantas Giedraitis
D
Top