python 3.6 – Python3.6 error: ModuleNotFoundError: No module named src

python 3.6 – Python3.6 error: ModuleNotFoundError: No module named src

You have to run the test from the my-project folder, rather than from the test folder.

python -m unittest test.test_file1.TestWriteDataBRToOS

Also you can you do:

export PYTHONPATH=${PYTHONPATH}:/path/to/your/project/

or in Windows:

set PYTHONPATH=${PYTHONPATH}:/path/to/your/project/

python 3.6 – Python3.6 error: ModuleNotFoundError: No module named src

This is because it is not able to locate the module named src probably because the path to the src folder isnt specified correctly. If you directly write src.file1, then your src file should be present in the same directory in which your current python file(test_file1.py) is located. If it isnt in the same directory, then you have to specify the entire directory. The reason why sys.path.insert(0, ../src) worked is because .. will move you up one directory and thats where your src folder might be. If you are working directory for test_file1.py is /usr/bin/python then the location of your src folder would be /usr/bin/src and since it isnt the same as your current working directory, the python file is not able to locate the src module.

Leave a Reply

Your email address will not be published.