erickrf/nlpnet

error on initial import

jstaker7 opened this issue · 8 comments

I'd really like to try these scripts, but seem to hit a roadblock upfront.

Here is the traceback:

import nlpnet
Traceback (most recent call last):
File "", line 1, in
File "nlpnet/init.py", line 3, in
import taggers
File "nlpnet/taggers.py", line 17, in
from network import Network, ConvolutionalNetwork, LanguageModel
ImportError: No module named network

Here is the full build printout:

Running setup.py install for nlpnet
building 'nlpnet.network' extension
gcc -fno-strict-aliasing -fno-common -dynamic -arch x86_64 -DNDEBUG -g -O3 -arch x86_64 -I. -I/Users/staker/Library/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/numpy/core/include -I/Applications/Canopy.app/appdata/canopy-1.2.0.1610.macosx-x86_64/Canopy.app/Contents/include/python2.7 -c nlpnet/network.c -o build/temp.macosx-10.6-x86_64-2.7/nlpnet/network.o
In file included from nlpnet/network.c:346:
In file included from /Users/staker/Library/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/numpy/core/include/numpy/arrayobject.h:4:
In file included from /Users/staker/Library/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/numpy/core/include/numpy/ndarrayobject.h:17:
In file included from /Users/staker/Library/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/numpy/core/include/numpy/ndarraytypes.h:1760:
/Users/staker/Library/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/numpy/core/include/numpy/npy_1_7_deprecated_api.h:15:2: warning: "Using deprecated NumPy API, disable it by " "#defining NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION" [-W#warnings]
#warning "Using deprecated NumPy API, disable it by "
^
1 warning generated.
gcc -bundle -undefined dynamic_lookup -g -arch x86_64 -L/tmp/_py/libraries/Applications/Canopy.app/appdata/canopy-1.2.0.1610.macosx-x86_64/Canopy.app/Contents/lib -headerpad_max_install_names -arch x86_64 build/temp.macosx-10.6-x86_64-2.7/nlpnet/network.o -o build/lib.macosx-10.6-x86_64-2.7/nlpnet/network.so
ld: warning: directory not found for option '-L/tmp/_py/libraries/Applications/Canopy.app/appdata/canopy-1.2.0.1610.macosx-x86_64/Canopy.app/Contents/lib'
changing mode of build/scripts-2.7/nlpnet-tag.py from 644 to 755
changing mode of build/scripts-2.7/nlpnet-train.py from 644 to 755
changing mode of build/scripts-2.7/nlpnet-test.py from 644 to 755

changing mode of /Users/staker/Library/Enthought/Canopy_64bit/User/bin/nlpnet-tag.py to 755
changing mode of /Users/staker/Library/Enthought/Canopy_64bit/User/bin/nlpnet-test.py to 755
changing mode of /Users/staker/Library/Enthought/Canopy_64bit/User/bin/nlpnet-train.py to 755

Successfully installed nlpnet

Can you help me understand what I might be missing here?

This is weird. I never had this error, but tried to install nlpnet in a new virtualenv anyway. Then I got the error you describe.

I was about to debug it in Eclipse, but then it started working correctly. I really can't explain what might be wrong: perhaps something with virtualenv, cython compiled modules, or both. I'll try to track the problem.

Are you using virtualenv, by the way?

Not using virtualenv, but in a canopy environment. Weird though, because without doing anything (that I know of), I went back later and tried importing nlpnet again and it worked. Who knows why it now decides to play nice, for no apparent reason.

I was also getting this error, even after trying a bunch of different 'building' steps. Turns out the error occurs when I run python -c "import nlpnet" from within the project root directory. In any other directory, it works. For running from within an IDE, I had to uncheck a couple of options about adding the project directory to PYTHONPATH in the running configuration (I'm using PyCharm).

An alternative fix, and also for running without installing, is to copy the network.so library file from the build directory to the sources directory (nlpnet).

I think this might be solved with relative imports. Try changing:

from network import Network, ConvolutionalNetwork

to

from .network import Network, ConvolutionalNetwork

In file nlpnet/taggers.py, line 17. It worked for me. I will send a pull request later to change all sibling imports to relative imports.

By the way, @jstaker7 , it seems you are importing from the nlpnet folder of your current working directory, not from the site-packages folder where setuptools installed nlpnet. This won't work, since the network module is not compiled in the source folder. So, try to make the change that I mentioned in my previous comment, then run python setup.py install again, and make sure you are using the installed version, not the one from your current directory.

Why the nlpnet/network.pyd file is ignored? See the gitignore.

Because it is a binary file generated automatically during build.

2015-02-23 19:33 GMT-03:00 Eduardo Pittol notifications@github.com:

Why the nlpnet/network.pyd file is ignored? See the gitignore.

Reply to this email directly or view it on GitHub
#2 (comment).

This happened to me again. (at newest version)

@andrecunha was right, I had to cd to another directory to fix that.