lnp
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.
1 Like
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
3 Likes
lnp
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?
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
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
lnp
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 
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.
3 Likes
lnp
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.
1 Like
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.
3 Likes
In general, how does one determine the Python version besides asking on a forum? It would be handy to have this documented somewhere.
glv
11
Hello,
This is the Python Mode that comes with the Processing IDE:
The links (light blue text) bring you to this and will have more details:
Note that it very clearly states:
There are 3 Python categories for each of the Python projects:
The py5 category is the one I have been using:
Topic in the py5 category:
This is in the site above and has more details:
This is the pinned post on top of p5py category topic:
This is all I can offer on this subject form a quick exploration and search.
:)
1 Like
hx2A
12
And py5 is actively maintained! There have been two releases this year and there will be several more before the year is over. This is a growing project with a growing community.
3 Likes