0

I have the following directory structure

/home/project/src/numeric.py
/home/project/test/test.py

I am in trying to run test.py by importing numeric.py:

import src.numeric as n

Python is giving me:

ModuleNotFoundError: No module named 'src'

Currently I am in the directory

$ cd /home/project/test/
$ python3 test.py

Is there something that I am missing?

  • src.numeric is the name of a file. I think you need to write in the format `from src.numeric import ` – askman Nov 02 '21 at 21:57

1 Answers1

0

Python is importing the module based on the relative path from the directory the script is executed.

Therefore your input statement evaluates to:

/home/project/test/src/numeric.py

-> but the file is at:

/home/project/src/numeric.py

If you want to keep this structure you would have to include the 'src' dir in your path like so:

import sys
sys.path.append('../src')

Python import src modules when running tests