Nicolas Bontempo Nicolas Bontempo - 1 year ago 104
Python Question

Python import module error

I have a problem in import of modules in my project. I was creating tests and I cant import my main to test one end point of my application, from the test file
. This is my project structure:


In my Im trying to import
in this way:

import api.main
from webtest import TestApp

def test_functional_concursos_api():
app = TestApp(
assert app.get('/hello').status == '200 OK'

I omly get
ImportError: No module named 'api'

  • What can be done to import my main to my test file?

Answer Source

Here's my best guess as to what might help:

You should make sure that the path to the directory in which your file resides can be found in sys.path. You can check this yourself by running this snippet in

import sys

for line in sys.path:
    print line

If the directory in which is found is not included in your path, you can append that path to sys.path, like this (include this snippet in

import sys
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download