TALP-UPC / FreeLing

FreeLing project source code
Other
253 stars 96 forks source link

Error Importing FreeLing to Python #79

Closed lorenzolagos closed 5 years ago

lorenzolagos commented 6 years ago

Hi. Not sure if this is the correct place to post this issue... please let me know otherwise.

I’ve installed FreeLing from source as specified in the Installation Manual on a Lenovo ThinkPad running on 64-bit Windows 10. My goal is to use the FreeLing module on Python, but when I type import pyfreeling I am getting the following: ImportError: DLL load failed: The specified module could not be found. Below are the details that should help figure out what is going on.

I have Python 3.6.6, Anaconda custom. In terms of the files and dependencies mentioned in the Installation Manual, I downloaded [FreeLing-4.1], [Visual Studio 2015], [zlib-1.2.11], [boost-v1.61.0], [icu-v57.1], and [swigwin-3.0.9]. The directories I use are: %FLINSTALL%=“C:\Users\loren\Dropbox\Software\FreeLing-4.1”; %SWIGDIR%=“C:\Users\loren\Dropbox\Software\swigwin-3.0.9”; and %PYTHONPATH%= “C:\Users\loren\Anaconda3\envs\mlbook”. Note that the FreeLing and SWIG directories are in Dropbox rather than Anaconda3 (not sure if this may explain the error).

Everything in the download went smoothly except for two things. First, I had to add the following option to the cmake command in order to avoid compiling errors: _-DCMAKE_CXXFLAGS="/FS /EHsc". Second, near the end of installation a fatal error caused by not finding swig.swg and python.swg (both of which are under %SWIGDIR%\Lib) would occur. This was fixed by copying swig.swg and python.swg (as well as all their dependencies) and pasting them to %SWIGDIR%. For some weird reason, the installation would not look into the Lib subfolder and since I do not know how to address that directly, I simply moved the files. After these two fixes, everything ran smoothly and all the files and dependencies mentioned in the Installation Manual were in the appropriate directories.

The problem comes when I try to import the module. Using a Jupyter notebook, I first set as the current directory the folder where pyfreeling.py, _pyfreeling.lib, and _pyfreeling.pyd are found. I then add all the relevant folders mentioned in the Installation Manual to syspath. I then check that pyfreeling is an importable module from syspath using pkgutil. I then execute import pyfreeling which is followed by the ImportError mentioned at the beginning. Below is an image of the error details.

image

Based on what I read on some forums, I used Dependency Walker to find the dependencies of _pyfreeling.pyd. This told me that _pyfreeling.pyd has several specified files that the system cannot find. Most are false positives (e.g., files starting with API-MS-WIN or EXT-MS-WIN) but two may be the source of the problem: FREELING.DLL and PYTHON36.DLL are not found. When I look for these files under the %FLINSTALL% directory, I don’t find PYTHON36.DLL. However, FREELING.DLL is found under %FLINSTALL%\build\src\libfreeling and under %FLINSTALL%\freeling\bin. If this is the source of the problem, I do not know how to address it. Is there something wrong in installation or do I need add more paths to %PYTHONPATH%?

Thanks in advance! (And thank you for developing such a wonderful tool... I'm very excited to start using it)

lluisp commented 6 years ago

FREELING.DLL and PYTHON.DLL are not python modules, but binary libraries. So, they are not located using PYTHONPATH variable, but PATH. So, you need to add their locations to %PATH% PYTHON36.DLL should be somewhere in the python installation folders (