question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ModuleNotFoundError: No module named 'rich'

See original GitHub issue

Hello, im trying to create a .exe from a very simple .py, with only “rich” as external dependancy, but Im getting a ModuleNotFoundError in the compiled exe (but not when executing the .py)

example:

from pathlib import Path
import time
from rich.progress import track

cwd = Path().absolute()

print("Search for *.txt in {cwd}")
for _ in track(range(1000)):
    time.sleep(0.01)

input("done")

In the console it outputs the following error:

C:\Users\bonobo\Documents\GitHub\auto-py-to-exe\output>main.exe
Traceback (most recent call last):
  File "main.py", line 3, in <module>
ModuleNotFoundError: No module named 'rich'
[12116] Failed to execute script 'main' due to unhandled exception!

Im on Python 3.10.0 and am working in a specially created .venv. pip freeze creates the following requirements.txt

colorama==0.4.4
commonmark==0.9.1
Pygments==2.11.1
rich==10.16.2

my current pyinstaller command looks like this:

pyinstaller --noconfirm --onefile --console --clean  "C:\Users\bonobo\Documents\GitHub\gc_automate\main.py"

The --clean flag is necessary because otherwise windows declares the exe as malicious…

The Output of auto-py-to-exe looks like that:

Running auto-py-to-exe v2.13.0
Building directory: C:\Users\bonobo\AppData\Local\Temp\tmp7sl9kf6n
Provided command: pyinstaller --noconfirm --onefile --console --clean  "C:\Users\bonobo\Documents\GitHub\gc_automate\main.py"
Recursion Limit is set to 5000
Executing: pyinstaller --noconfirm --onefile --console --clean C:\Users\bonobo\Documents\GitHub\gc_automate\main.py --distpath C:\Users\bonobo\AppData\Local\Temp\tmp7sl9kf6n\application --workpath C:\Users\bonobo\AppData\Local\Temp\tmp7sl9kf6n\build --specpath C:\Users\bonobo\AppData\Local\Temp\tmp7sl9kf6n

413103 INFO: PyInstaller: 4.7
413114 INFO: Python: 3.10.0
413130 INFO: Platform: Windows-10-10.0.19042-SP0
413132 INFO: wrote C:\Users\bonobo\AppData\Local\Temp\tmp7sl9kf6n\main.spec
413148 INFO: UPX is not available.
413149 INFO: Removing temporary files and cleaning cache in C:\Users\bonobo\AppData\Local\pyinstaller
413170 INFO: Extending PYTHONPATH with paths
['C:\\Users\\bonobo\\Documents\\GitHub\\gc_automate']
413367 INFO: checking Analysis
413369 INFO: Building Analysis because Analysis-03.toc is non existent
413386 INFO: Reusing cached module dependency graph...
413447 INFO: Caching module graph hooks...
413550 INFO: running Analysis Analysis-03.toc
413555 INFO: Adding Microsoft.Windows.Common-Controls to dependent assemblies of final executable
  required by C:\Users\bonobo\AppData\Local\Programs\Python\Python310\python.exe
413633 INFO: Analyzing C:\Users\bonobo\Documents\GitHub\gc_automate\main.py
413636 INFO: Processing module hooks...
413637 INFO: Loading module hook 'hook-difflib.py' from 'C:\\Users\\bonobo\\Documents\\GitHub\\auto-py-to-exe\\.venv\\lib\\site-packages\\PyInstaller\\hooks'...
413650 INFO: Loading module hook 'hook-distutils.py' from 'C:\\Users\\bonobo\\Documents\\GitHub\\auto-py-to-exe\\.venv\\lib\\site-packages\\PyInstaller\\hooks'...
413665 INFO: Loading module hook 'hook-distutils.util.py' from 'C:\\Users\\bonobo\\Documents\\GitHub\\auto-py-to-exe\\.venv\\lib\\site-packages\\PyInstaller\\hooks'...
413681 INFO: Loading module hook 'hook-encodings.py' from 'C:\\Users\\bonobo\\Documents\\GitHub\\auto-py-to-exe\\.venv\\lib\\site-packages\\PyInstaller\\hooks'...
413768 INFO: Loading module hook 'hook-heapq.py' from 'C:\\Users\\bonobo\\Documents\\GitHub\\auto-py-to-exe\\.venv\\lib\\site-packages\\PyInstaller\\hooks'...
413784 INFO: Loading module hook 'hook-lib2to3.py' from 'C:\\Users\\bonobo\\Documents\\GitHub\\auto-py-to-exe\\.venv\\lib\\site-packages\\PyInstaller\\hooks'...
413867 INFO: Loading module hook 'hook-multiprocessing.util.py' from 'C:\\Users\\bonobo\\Documents\\GitHub\\auto-py-to-exe\\.venv\\lib\\site-packages\\PyInstaller\\hooks'...
413871 INFO: Loading module hook 'hook-pickle.py' from 'C:\\Users\\bonobo\\Documents\\GitHub\\auto-py-to-exe\\.venv\\lib\\site-packages\\PyInstaller\\hooks'...
413879 INFO: Loading module hook 'hook-sysconfig.py' from 'C:\\Users\\bonobo\\Documents\\GitHub\\auto-py-to-exe\\.venv\\lib\\site-packages\\PyInstaller\\hooks'...
413894 INFO: Loading module hook 'hook-xml.etree.cElementTree.py' from 'C:\\Users\\bonobo\\Documents\\GitHub\\auto-py-to-exe\\.venv\\lib\\site-packages\\PyInstaller\\hooks'...
413897 INFO: Loading module hook 'hook-xml.py' from 'C:\\Users\\bonobo\\Documents\\GitHub\\auto-py-to-exe\\.venv\\lib\\site-packages\\PyInstaller\\hooks'...
413941 INFO: Loading module hook 'hook-_tkinter.py' from 'C:\\Users\\bonobo\\Documents\\GitHub\\auto-py-to-exe\\.venv\\lib\\site-packages\\PyInstaller\\hooks'...
414094 INFO: checking Tree
414101 INFO: Building Tree because Tree-09.toc is non existent
414117 INFO: Building Tree Tree-09.toc
414179 INFO: checking Tree
414195 INFO: Building Tree because Tree-10.toc is non existent
414196 INFO: Building Tree Tree-10.toc
414275 INFO: checking Tree
414290 INFO: Building Tree because Tree-11.toc is non existent
414306 INFO: Building Tree Tree-11.toc
414325 INFO: Looking for ctypes DLLs
414348 INFO: Analyzing run-time hooks ...
414351 INFO: Including run-time hook 'C:\\Users\\bonobo\\Documents\\GitHub\\auto-py-to-exe\\.venv\\lib\\site-packages\\PyInstaller\\hooks\\rthooks\\pyi_rth_inspect.py'
414370 INFO: Including run-time hook 'C:\\Users\\bonobo\\Documents\\GitHub\\auto-py-to-exe\\.venv\\lib\\site-packages\\PyInstaller\\hooks\\rthooks\\pyi_rth_pkgutil.py'
414387 INFO: Including run-time hook 'C:\\Users\\bonobo\\Documents\\GitHub\\auto-py-to-exe\\.venv\\lib\\site-packages\\PyInstaller\\hooks\\rthooks\\pyi_rth_multiprocessing.py'
414406 INFO: Looking for dynamic libraries
414590 INFO: Looking for eggs
414599 INFO: Using Python library C:\Users\bonobo\AppData\Local\Programs\Python\Python310\python310.dll
414601 INFO: Found binding redirects: 
[]
414616 INFO: Warnings written to C:\Users\bonobo\AppData\Local\Temp\tmp7sl9kf6n\build\main\warn-main.txt
414657 INFO: Graph cross-reference written to C:\Users\bonobo\AppData\Local\Temp\tmp7sl9kf6n\build\main\xref-main.html
414667 INFO: checking PYZ
414677 INFO: Building PYZ because PYZ-03.toc is non existent
414679 INFO: Building PYZ (ZlibArchive) C:\Users\bonobo\AppData\Local\Temp\tmp7sl9kf6n\build\main\PYZ-03.pyz
415146 INFO: Building PYZ (ZlibArchive) C:\Users\bonobo\AppData\Local\Temp\tmp7sl9kf6n\build\main\PYZ-03.pyz completed successfully.
415167 INFO: checking PKG
415175 INFO: Building PKG because PKG-03.toc is non existent
415191 INFO: Building PKG (CArchive) main.pkg
416724 INFO: Building PKG (CArchive) main.pkg completed successfully.
416737 INFO: Bootloader C:\Users\bonobo\Documents\GitHub\auto-py-to-exe\.venv\lib\site-packages\PyInstaller\bootloader\Windows-64bit\run.exe
416751 INFO: checking EXE
416766 INFO: Building EXE because EXE-03.toc is non existent
416781 INFO: Building EXE from EXE-03.toc
416797 INFO: Copying bootloader EXE to C:\Users\bonobo\AppData\Local\Temp\tmp7sl9kf6n\application\main.exe
416855 INFO: Copying icon to EXE
416875 INFO: Copying icons from ['C:\\Users\\bonobo\\Documents\\GitHub\\auto-py-to-exe\\.venv\\lib\\site-packages\\PyInstaller\\bootloader\\images\\icon-console.ico']
416894 INFO: Writing RT_GROUP_ICON 0 resource with 104 bytes
416896 INFO: Writing RT_ICON 1 resource with 3752 bytes
416908 INFO: Writing RT_ICON 2 resource with 2216 bytes
416910 INFO: Writing RT_ICON 3 resource with 1384 bytes
416924 INFO: Writing RT_ICON 4 resource with 37019 bytes
416940 INFO: Writing RT_ICON 5 resource with 9640 bytes
416956 INFO: Writing RT_ICON 6 resource with 4264 bytes
416958 INFO: Writing RT_ICON 7 resource with 1128 bytes
416962 INFO: Copying 0 resources to EXE
416972 INFO: Emedding manifest in EXE
416975 INFO: Updating manifest in C:\Users\bonobo\AppData\Local\Temp\tmp7sl9kf6n\application\main.exe
417031 INFO: Updating resource type 24 name 1 language 0
417038 INFO: Appending PKG archive to EXE
418376 INFO: Building EXE from EXE-03.toc completed successfully.

Moving project to: C:\Users\bonobo\Documents\GitHub\auto-py-to-exe\output
Complete.

the flag --hidden-import "rich" doesn’t seem to change the .exe (same size). without rich it works just fine.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
brentvollebregtcommented, Jan 6, 2022

There is a good chance you were running auto-py-to-exe with a Python installation that did not have rich installed - most likely the venv you were using (by the looks of it).

I give some tips on this in my post here if you’re curious on how to figure out what went wrong.

0reactions
EbenenBonobocommented, Jan 7, 2022

ah, got it! thanks for the explanation!

Read more comments on GitHub >

github_iconTop Results From Across the Web

No module named 'rich'" even though I installed with pip ...
I'm having a package named manimce that was incompatible with the version of rich installed. You can try upgrading the rich module with...
Read more >
Getting error 'no module named rich' even though installed
When I attempt to run a python file with module rich in it the command prompt spits out error 'ModuleNotFoundError: No module named...
Read more >
🤔 How to fix "ModuleNotFoundError: No module named 'rich'"
You must first install the package before you can use it in your code. Run the following command to install the package and...
Read more >
How to fix from rich.console import ... - Stef Van Looveren
I got this error in Python File "C:\DEV\bot\utils\console.py", line 1, in <module> from rich.console import Console ModuleNotFoundError: No module named ...
Read more >
ModuleNotFoundError: No module named 'rich'
Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'rich' How to remove the ModuleNotFoun.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found