Dealing with Python's ModuleNotFoundError (I'd appreciate any advice if there's a better way)

Set PYTHONPATH in the environment variable


export PYTHONPATH="Absolute path one level higher than the module in error"

You should not get ** ModuleNotFoundError ** in the process where you entered the above command.

How to check if you can enter in PYTHON PATH properly

Launch python's interactive mode in the same process


>>> import sys
>>> print(sys.path)
['', 'Absolute path one level higher than the module in error','../../site-packages',...]

If it looks like the above, ** ModuleNotFoundError ** should be resolved. It feels better than embedding sys.path.append ("the absolute path one level above the module in error"). If anyone knows a better way, I would appreciate it if you could let me know. If you find something that feels good, I'll put it together.

Recommended Posts

Dealing with Python's ModuleNotFoundError (I'd appreciate any advice if there's a better way)