0

I am new to Python. I am getting ImportError and seem to have tried everything that's in the documentation and the various notes in this site and other

My code is structured as follows:

 vsm
 |
 |______bin
 |      vsmx.py
 |______site-packages
          __init__.py
        |
        |_____libs
             __init__.py
             monitor.py

In monitor.py I have a function named getStr and the two __init__.py files are empty

I have the PYTHONPATH set to vsm/site-packages & vsm/site-packages/libs. When I run from command line, python bin/vsmx.py, I get:

Traceback (most recent call last):
  File "bin/vsmx.py", line 15, in <module>
    from libs.monitor import getStr
   File "/var/src/vsm/bin/vsmx.py", line 15, in <module>
     from libs.monitor import getStr
ImportError: No module named monitor

However, when I try to run this interactively, it seems to work. I tried on both windows and linux using python 2.6.1.

Any pointers will be much appreciated

3
  • libs is inside of __init__.py? (following your graph) Commented Jan 16, 2012 at 17:11
  • Did you try importing from like this import site-packages.libs.monitor ? I think you're missing the first part. I always have problems with importing too. This is assuming your current dir is bin. Commented Jan 16, 2012 at 17:16
  • If vsm/site-packages/libs is on your PYTHONPATH, can't you just do import monitor? Commented Jan 16, 2012 at 17:39

1 Answer 1

1

ImportError: No module... is usually a very (obscure) error meaning that you have circular imports.

Module a.py:

 import b

Module b.py:

 import a

Then main.py:

 import a

This should cause ImportError: No module named a, because a is importing b and not ready when b tries to import it.

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

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.