0

I am using PyCharm with Python 3.4 and trying to use https://github.com/tumblr/pytumblr . When I try to import pytumblr I get this error, "ImportError: No module named 'helpers'". In the __init__.py file,

from helpers import validate_params, validate_blogname
from request import TumblrRequest

The code I am trying is literally

import pytumblr

Any idea what I am doing wrong?

flazzarini
  • 7,791
  • 5
  • 33
  • 34
JustaCookie
  • 181
  • 2
  • 13

1 Answers1

0

What the error message says is that your python interpreter cannot find the helper module.

This module is defined in the pytumblr module, so I suspect you are in the pytumblr folder you cloned, which is why you can do

import pytumblr

But the path to the module is not in your PYTHONPATH variable, so python cannot find the helper module, which is deeper in the directory. (Try to go in the pytumblr/pytumblr directory, then launch python and import helpers will work).

What you need to do is add the top level repository where you put pytumblr to you PYTHONPATH (either doing export PYTHONPATH=$PYTHONPATH:pytumblr_repo or How to add to the pythonpath in windows 7? if you are on windows).

You can also move pytumblr sources to a directory already in your PYTHONPATH.

Community
  • 1
  • 1
Math
  • 2,399
  • 2
  • 20
  • 22
  • I think I said that wrong. I have downloaded the files and are using them on my computer. My script is one directory above pytumblr and is calling the --init-- file. http://i.imgur.com/DWyZp3e.gif – JustaCookie Feb 17 '15 at 14:37
  • Yes, and that is the problem, because `import` calls are relative to your location. You would need to call `import pytumblr.helpers` but the call that is made is `import helpers`. You need include the `pytumblr` folder to your `PYTHONPATH` or be inside this folder (in the same folder as the `helpers.py` file) – Math Feb 17 '15 at 14:41
  • Sorry, I misused repository. I meant your local directory. – Math Feb 17 '15 at 14:42
  • Ahh! Thanks! Do you mind explaining PYTHONPATH and PATH too? It now gives me an error trying to import a standard module that comes with Python. – JustaCookie Feb 17 '15 at 16:08
  • Never mind. After all of your help I realized that this code wasn't written for Python 3. Turns out there are several Python 3 Tumblr API programs if I actually Google specfiically for Python 3. In any case, thank you for your help. I learned a bit and you were very helpful. :) – JustaCookie Feb 17 '15 at 16:27
  • Glad to help, it is usefull for any package, python2 or python3 ;) – Math Feb 17 '15 at 16:40