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
  • 702
  • 2
  • 9
  • 21
luoyangylh
  • 31
  • 1
  • 5

2 Answers2

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

Dhara
  • 6,587
  • 2
  • 31
  • 46
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.

dan-boa
  • 590
  • 4
  • 10
  • Thanks for your reply. But I have already put it in the sys.path. – luoyangylh Jun 06 '12 at 08:05
  • 1
    Instead of `append`, a `sys.path.insert(0, 'path')` might be more approriate in order to give it more precedence than the original one. – glglgl Jun 06 '12 at 09:13