0

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

3 Answers 3

1

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

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks guys. I have added import sys and sys.path.append('C:\Users\stacey\Documents\MERLIN\MERLIN - WORKING\dao_all') for a path to the route of the project and added the init.py files but still get the same error (dao not known) any ideas? Thanks
@Stacey can you provide the prj and files structure
0

Please check whether pythonpath environment variable is properly set. You can refer this. How to add to the pythonpath in windows 7?

Comments

0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.