0

I'm trying out Freeling's API for python. The installation and test were ok, they provide a sample.py file that works perfectly (I've played around a little bit with it and it works).

So I was trying to use it on some other python code I have, in a different folder (I'm kind of guessing this is a path issue), but whenever I import freeling (like it shows on the sample.py):

import freeling

FREELINGDIR = "/usr/local";
DATA = FREELINGDIR+"/share/freeling/";
LANG="es";
freeling.util_init_locale("default");

I get this error:

ModuleNotFoundError: No module named 'freeling'.

The sample.py is located on the ~/Freeling-4.0/APIs/Python/ folder, while my other file is located in ~/project/, I dont know if that can be an issue. Thank you!

sophiet
  • 13
  • 7
  • From what I understand based on a cursory Google search, the directory in which `sample.py` is present should also have a `freeling.py` file? It doesn't seem like you use `pip` or some other package manager to install it. Am I correct? – shriakhilc May 29 '19 at 14:04
  • Hello, thank you for answering! Correct! It's actually a C++ library, with a python API. It does make a freeling.py on the sample.py folder onces you ran, automatically wth Swig i believe it's called. I assume there has to be a way to put the path but I cant seem to figure it out. – sophiet May 30 '19 at 15:59

2 Answers2

0

You need to set PYTHONPATH so python can find the modules if they are not in the same folder.

Lluís Padró
  • 215
  • 1
  • 5
  • Hello, than you for answering! this would be ``` import freeling, os.path PYTHONPATH = path/to/freeling/ ``` inside the python script, correct? – sophiet May 30 '19 at 15:57
0

A simple solution is to have a copy of freeling.py in the same directory as your code, since python will look there.

A better solution is to either paste it in one of the locations where it usually checks (like the lib folder in its install directory), or to tell it that the path where your file is should be scanned for a module.

You can check out this question to see how it can be done on Windows. You are basically just setting the PYTHONPATH environment variable, and there will only be minor differences in how to do so for other OSes. This page gives instructions that should work on Linux systems.

I like this answer since it adds the path at runtime in the script itself, doesn't make persistent changes, and is largely independent of the underlying OS (apart from the fact that you need to use the appropriate module path of course).

shriakhilc
  • 2,922
  • 2
  • 12
  • 17