Reputation: 5107
I'm a bit new to running code from the terminal. I am running a test module called test_blbmktdata.py
from the terminal by running:
python -m unittest test_blbmktdata.py
And am getting a error:
File "C:\Users\stacey\Documents\MERLIN\MERLIN - WORKING\dao_all\dao\iotools\tests\test_blbmktdata.py", line 3, in <module>
from dao.iotools.blbmktdata import *
ModuleNotFoundError: No module named 'dao'
The folder dao
does exit:
C:\Users\stacey\Documents\MERLIN\MERLIN - WORKING\dao_all\dao\iotools
Please see below for the beginning of the module (where the problem is).
import unittest
import os.path
from dao.iotools.blbmktdata import *
class TestBlbMktData(unittest.TestCase):
staticName='StaticInstrumentData.csv'
If I run the code from the terminal do I need to change the way I reference imports from different folders?
Thanks
Upvotes: 0
Views: 201
Reputation: 109
In addition to shahaf's answer, it is worthwhile to look at the official documentation on module resolution : https://docs.python.org/3/tutorial/modules.html#the-module-search-path
Upvotes: 0
Reputation: 4983
python don't know where to look for the dao model
add the follwoing lines before the import
import sys
sys.path.append(<path to prj root directory>)
also you will need to have a init.py file (empty file) in each directory of the dao so python could recognise it as a module
Upvotes: 1
Reputation: 357
Please check whether pythonpath environment variable is properly set. You can refer this. How to add to the pythonpath in windows 7?
Upvotes: 0