0

My Python couldn't figure out the submodules when I was trying to import reportlab.graphics.shapes like this:

>>> from reportlab.graphics.shapes import Drawing
Traceback (most recent call last):
 File "<pyshell#14>", line 1, in <module>
 from reportlab.graphics.shapes import Drawing
ImportError: No module named shapes

I have copied the reportlab package to /site-packages and I can import module reportlab.graphics successfully.

My Python version is 2.7.3.

Could anyone help me to fix this problem?

shobhit
7002 gold badges9 silver badges21 bronze badges
asked Jun 6, 2012 at 2:29
0

2 Answers 2

1

As @dan-boa pointed out, you can add paths to the module search path, but since you can find the parent module, I doubt that this is your root problem.

Do you have some left-over installation of the module at another path? You can check the path where it is finding the parent package (reportlab) by executing:

import reportlab
print reportlab.__file__

If this is indeed the path you were expecting, then try this recursively with the the sub-modules, until you can see where the problem is. Perhaps, your package is corrupted? Try manually checking in the path returned if you can find the files/modules in question.

If this is not the path you were expecting, clean-up the installation from this 2nd path and try again.

Finally, in case you do find that it is a path problem, instead of adding the path each time using sys.path.append, you can add it to PYTHONPATH

answered Jun 6, 2012 at 8:07
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for your advice. That's a great way to find the problem.
0

Please check your sys path and if the directory of the module is not present then add it.

import sys
sys.path.append('PATH_OF_THE_MODULE')

As site-packages is already their in the sys.path, may be therefore the package was imported successfully.

answered Jun 6, 2012 at 7:25

2 Comments

Thanks for your reply. But I have already put it in the sys.path.
Instead of append, a sys.path.insert(0, 'path') might be more approriate in order to give it more precedence than the original one.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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.