tags:

views:

395

answers:

3

I've seen many similar errors, but I can't see a solution that applies to my particular problem.

I'm trying to use the Akismet module which is on my PYTHONPATH, then if I start up the interactive interpreter, when I run "from akismet import Akismet" (as the docstring says), I get the following error:

from akismet import Akismet
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: cannot import name Akismet
+1  A: 

It will work perfectly if your PYTHONPATH is set correctly and globally (just tested it myself).

  • Must be set to the directory containing "akismet.py", not the file path! Make sure you don't use relative paths.
  • Note that you might need to reboot/logoff in order to apply environment variable changes to all programs.
AndiDog
let's say I have /path/ on my PYTHONPATH, then I tried with /path/akismet/akismet.py (adding __init__.py), and tried with /path/akismet.pyNeither worked
Doppelganger
@Doppelganger: Put the "akismet.py" script in "/path/" and add that path to your PYTHONPATH. Make sure you use colons as separator if you have multiple directories in the PYTHONPATH. Reboot and use the `set` command to check if the PYTHONPATH is correct. Then it must definitely work.
AndiDog
Ok, the real issue here was that I had marked the akismet folder as a package adding inside an _init_.py, I deleted that folder and it works fine now.
Doppelganger
+1  A: 

You should have the directory containing the 'akismet' directory in your path. I guess, you have added the 'akismet' directory itself to $PYTHONPATH.

When you write:

from akismet import Akismet

Python tries to open file 'akismet/Akismet.py' somewhere in its search path.

All this assuming 'Akismet' is a file and 'akismet' is a directory. If there is an 'akismet.py' file, then the directory containing this file should be listed in $PYTHONPATH.

Jacek Konieczny
let's say I have /path/ on my PYTHONPATH, then I tried with /path/akismet/akismet.py (adding __init__.py), and tried with /path/akismet.pyNeither worked
Doppelganger
+1  A: 

Check if your PYTHONPATH is really what you expect it to be, e.g. by doing this in an interactive console:

In [1]: import sys

In [2]: print sys.path

is akismet.py really in one of those folders?

piquadrat