Version of Python used in Python Mode

#1

Hello wonderful discussion board!

Having a hellish time trying to install external modules and then importing in Processing Python mode. Running up against “ImportError: No Module named twitter found”.

My system python is 2.7.10

I have definitely installed, via pip, python wikipedia and python twitter (the aim is to suck up and use data).

Could processing be using a different version of python? Ie. I’m installing the above packages to a different python? I’m really at a loss at this stage.

Any help much appreciated.

0 Likes

#2

You could add the modules to your sketch folder manually. Perhaps this is not your ideal solution, but it can be handy to have the files bundled with your sketch (i.e. like when you’re trying to run it on a different computer).

Here’s an example you can work off:
https://github.com/tabreturn/processing.py-in-ten-lessons/raw/master/twitter_wikipedia_sketch.zip

2 Likes

#3

Thanks for that! I didn’t know the modules could be loaded directly from the sketch folder. Certainly handy as this will ultimately run on another machine. Curiousnessnessness.

Are all those folders excepting /twitter/ and /wikipedia/ required?

0 Likes

#4

You have to include the python module in the project.
This error might be due to some other reasons also, so better to uninstall python module and reinstall it.
first, uninstall run these two commands
“pip uninstall twitter” & “pip uninstall python-twitter”

now reinstall “pip3 install twitter”

Now create a new project and include the dependencies manually as tabreturn told in the last comment.

1 Like

#5

Yes – all of those other folders are required. Python twitter/wikipedia have various dependencies. For example, if you remove the urllib3 folder, then run your sketch, you will receive an error message stating that urllib3 is missing.

A tool like pip automatically checks for- and downloads any required packages. However, you will find that some packages have no dependencies.

1 Like

#6

@tabreturn Brilliant - thanks for clarifying that. I might see if I can’t put them all in their own dir. The mess of all those folders makes me creak!

@Afflospark done and done :slight_smile:

0 Likes

#7

Yeah, it is kinda gross having all those directories laying about in the root!

To place them all within a sub-directory, you’ll have to change-up the import line and add an empty __init__.py file. For example, say that you named this sub-directory lib:

- sketch
  - lib
     __init__.py
     + twitter
     + wikipedia
     + ...
  sketch.properties
  sketch.pyde

Then in your sketch file, import modules like this:

import lib.wikipedia as wp
print (wp.summary("Wikipedia"))

Of course, you can use whatever name you like for the as part of the statement.

1 Like

#8

Too kind. I’ve only been on this discussion board for a short amount of time but I have to say I’m blown away at the expertise and generosity shown. Thank you.

0 Likes

#9

If you are using Python mode, it uses Python 2.7.3 running on Jython 2.7.1. pip3 installs would not work – that installs Python 3 modules, and the mode cannot run Python 3 code (or anything CPython, for that matter) – only pure Python2.

0 Likes