Module help for a complete newbie

Hello everyone,

I’ve finished a beginner course and just started a second course for Python. I am using Python 3.9
I am having troubles working with imported modules… So I experimented with it and all worked fine, I did have trouble finding the modules I installed trough pip because the course was for 3.6 and it seemed to be in a different location on 3.9 (or is this my setup?). Anyways in the end I found it and the course was completed with succes.

Now however I wanted to try making my own little program using a module I found on Github: GitHub - openfoodfacts/openfoodfacts-python: Python package for Open Food Facts

Now first of all I don’t even know if I want to use this module but I wanted to check it out.
I can’t get it to work at all… So I installed it trough pip and I can find the folder with the .py and .pyc files in this location on my pc: /home/minty/.local/lib/python2.7/site-packages/openfoodfacts

This seems to be for Python version 2.7

When I try to use the import command for one of the files in the folder I ofcourse get this error: ModuleNotFoundError: No module named ‘products’

I can not find the module inside Python anywhere, only on my pc in that folder.

So the question is: how can I simply add a folder location in Python as a usable module folder?
Can this be done/used if the module is made for an older version of Python? Or do I have to start my project in Python 2?

I found some answers on the internet so far but as a newbie this makes no sense to me at all, its complicated code after a simple beginner’s course and when I copy it it still does not work. (changing the .sys directory, tried it; does not work) So can anyone please explain to me in very simple language what the problem is?? Am I overlooking a button where I can simply add this folder, or is this really complicated stuff that is just out of my league for now?? I must say in the tutorial it seemed that in python 3.6 the imported modules were easyer to find, but that might just be me who just does not get all the folders and subfolders functions yet…

Also: I tried opening the .py files and they open in Python 3.9, so I tried copying the codes in new files that I can simply find in the left panel thinking I was being smart: BUT: this gives me lots of errors so I guess this is not the way to go: why is this? does it have to do with the .pyc files?
In other words: I have no idea what I’m doing and I would like not having to quit this project before starting/learning way too much about modules in the beginning for something that seems like a simple problem…

Okay so for the people experiencing the same problem I think I got it:
file → settings → project → Python interpreter → + (add project)
I think Project structure is another way to add directories
After that it works with: from … import …

Sorry, this was a very simple solution and I just missed it in the settings section (blame it on my bad english, but I still find it strange that I found nothing online about this).

It still does not work so if the version is a problem I would love it if someone tells me: but my guess at this point is that I can’t work with this module because of lack of knowledge.

Hi Randy,

I had a quick look into the belonging and this contains

'Programming Language :: Python',
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.3',
'Programming Language :: Python :: 3.4',
'Programming Language :: Python :: 3.5',
'Programming Language :: Python :: 3.6',
'Programming Language :: Python :: 3.7',
'Programming Language :: Python :: 3.8',
'Programming Language :: Python :: Implementation :: CPython'

which -if you ask me- means, that the library should at least be compatible with Python 3.3 - 3.8 too.

What exactly does not work now? Any specific error message? Do you want to make us happy with some screenshots…?

Cheers, Dominik

The important thing is to install the module for the python interpreter
you’re using - each has its own area for installed modules. You said you
installed it with pip. But which pip? Because pip itself is associated
with a particular Python install.

The reliable way to install for your python interpreter is to use that
interpreter to run pip itself, like this:

python -m pip install module-name-here

replacing “python” with the particular Python executable you’re going to
run. Note that this only works with Python 3 past a certain version. But
if you’ve got 3.9, use that interpreter - it certainly works with it.

Cameron Simpson