ModuleNotFoundError: No module named after renaming parent folder

Viewed 350

I have problems importing a local package I developed. I'm using WSL with a conda environment. I have the following structure:

 parent folder
     |- local_package
        |- package
           |- ...
           |- ...
        |- scripts
           |-script.py

Previously, with /parent folder/local_package as working directory, I could call python scripts/script.py, which imports my package and executes its main function. After some time, I have renamed the parent folder to parent_folder. After doing this rename, my script is no longer able to import my package, and shows ModuleNotFoundError. My current workaround consists in installing my package with pip, but installing it each time I need to test it or use the package while I'm modifying it is cumbersome.

My question is, how can I fix this problem so I'm able to run my script again without installing the package?

Some information that may be useful:

  • Before renaming the folder I installed the package. This could maybe create some kind of cache
  • I erased all __pycache__ files within my package folder and my scripts folder to try solve the problem. Didn't work.
  • Reinstalling and erasing the package doesn't solve the problem.
  • My package uses __init__.py files. It also has a setup.py for installing it.
  • My specific python version is 3.6.8 .
  • This is the output of print(sys.path):

['', '/home/user/anaconda3/envs/p369_TF2.4/lib/python36.zip', '/home/user/anaconda3/envs/p369_TF2.4/lib/python3.6', '/home/user/anaconda3/envs/p369_TF2.4/lib/python3.6/lib-dynload', '/home/user/anaconda3/envs/p369_TF2.4/lib/python3.6/site-packages', '/mnt/c/Users/windows_user/Desktop/Parent folder/local_package']

I suspect this can be fixed by modifying the PYTHONPATH environment variable, but it doesn't appear when I run printenv or in the windows environment variable window. I suppose that I could modify or add the path before importing my package, but I would prefer a cleaner way of doing it that doesn't require me to modify all future scripts.

0 Answers
Related