-
-
Notifications
You must be signed in to change notification settings - Fork 847
Description
Are you seeing an error like this after updating your dependencies?
python main.py
Traceback (most recent call last):
File "/home/user/code/myproject/main.py", line 1, in <module>
import typer
ModuleNotFoundError: No module named 'typer'
Just remove and install the dependencies again, that will solve it.
TL;DR:
This is related to dropping support for typer-slim, just by re-installing the dependencies (removing the Python environment and creating it from scratch) it will all work, and you won't see the error again in that environment.
Background
We just dropped support for typer-slim, a slimmed down version of typer that didn't include Rich.
Now typer-slim simply depends on typer, so when a package depends on typer-slim, it will get regular typer instead of a slimmed down version.
Technical Details
typer-slim provided the same files as typer, so, installing it, would createa directory typer/ in your Python environment.
Regular typer also creates the same package typer/.
So, if in your dependencies one package depends on typer and another one depends on typer-slim, one would end up ovewriting the other, but because they are the same files, in the end it would work, more or less.
But that would cause other issues (#1501), and is a very hacky and fragile workaround, so we needed to remove it.
The latest version of typer-slim no longer provides any files of its own, it only depends on typer, so typer will be installed normally, including its own files in typer/.
Why No Module
Now, the problem of ModuleNotFoundError: No module named 'typer' would only happen if you already had an environment installed with those old versions that provided the same files, and upgrade/install the new version.
The installer (uv, pip, poetry, etc.) doesn't have a predefined order in which to remove old files and copy new files.
If you got this error, what happened is that the installer:
- Removed the old files for
typer, the directorytyper/ - Installed the new files for
typer, the directorytyper/again - Then it removed the old files for
typer-slim, which also provided the same directorytyper/, so it just removed that sametyper/directory copied from above 😱 - Then it "copied" the new files for typer-slim, which doesn't provide any files anymore, so, nothing to copy 😬
The end result, after removing and copying the typer/ directory a couple of times, it ended up with no typer/ directory.
Strangely, it could happen that it did the process in the other order, starting with typer-slim and finishing with typer, and in that situation it would have worked.
And sadly, it would not be solvable by doing anything else that creates a new release, as the same would happen (only once).
It Will Happen Only Once
The next version installed (or installing from scratch) would work as normally, but the first time it is installed from the old version that provided files to any of the new ones that don't provide any files will have this (terrible) effect.
I'm sorry for that, there's not much that can be done really, other than re-installing, or doing a sequence of upgrading to one version and then upgrading to the next.