Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nltk download crashes #21

Open
whilo opened this issue Oct 11, 2017 · 15 comments
Open

nltk download crashes #21

whilo opened this issue Oct 11, 2017 · 15 comments

Comments

@whilo
Copy link

whilo commented Oct 11, 2017

To import nltk I need to import numpy first, otherwise I get:

>>> import nltk
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python2.7/dist-packages/nltk/__init__.py", line 89, in <module>
    from nltk.internals import config_java
  File "/usr/lib/python2.7/dist-packages/nltk/internals.py", line 31, in <module>
    from nltk import compat
  File "/usr/lib/python2.7/dist-packages/nltk/compat.py", line 51, in <module>
    class UTC(tzinfo):
TypeError: Error when calling the metaclass bases
    'getset_descriptor' object is not callable

The tk download dialog works fine, but it crashes the JVM when I select something and hit "download":

>>> import numpy
>>> import nltk
>>> nltk.download()
showing info https://raw.githubusercontent.com/nltk/nltk_data/gh-pages/index.xml
*** Error in `java': free(): invalid pointer: 0x00007fe2adc24cb8 ***
fish: “java -cp jython.jar:build/JyNI.…” terminated by signal SIGABRT (Abort)
@Stewori
Copy link
Owner

Stewori commented Oct 11, 2017

Interesting: The initial error looks similar to the one described here: #18
I have currently no time to follow up on this. It would be good if you could start with debugging. Can you extract a minimal Python code snippet to provoke the error?

@ledebroux
Copy link

ledebroux commented Oct 31, 2017

Hey,
I'm having the same issue when trying to import numpy:

 import sys
 sys.path.append('/usr/lib/python2.7/dist-packages')
 import numpy

$ java -cp jython-standalone-2.7.1.jar:JyNI.jar -Djava.library.path=dll/ org.python.util.jython test.py

Traceback (most recent call last):
  File "test.py", line 4, in <module>
    import numpy
  File "/usr/lib/python2.7/dist-packages/numpy/__init__.py", line 153, in <module>
    from . import add_newdocs
  File "/usr/lib/python2.7/dist-packages/numpy/add_newdocs.py", line 13, in <module>
    from numpy.lib import add_newdoc
  File "/usr/lib/python2.7/dist-packages/numpy/lib/__init__.py", line 8, in <module>
    from .type_check import *
  File "/usr/lib/python2.7/dist-packages/numpy/lib/type_check.py", line 11, in <module>
    import numpy.core.numeric as _nx
  File "/usr/lib/python2.7/dist-packages/numpy/core/__init__.py", line 15, in <module>
    from . import defchararray as char
  File "/usr/lib/python2.7/dist-packages/numpy/core/defchararray.py", line 1668, in <module>
    class chararray(ndarray):
TypeError: Error when calling the metaclass bases
    'getset_descriptor' object is not callable

@whilo
Copy link
Author

whilo commented Oct 31, 2017

Which numpy Version are you using? I think only numpy > 1.12 is supported, best 1.13.

@ledebroux
Copy link

You're absolutely right, it had slipped my mind.

Thanks !

@Tatsukyo
Copy link
Contributor

Hi,

I'm currently using Numpy 1.13.3 under windows (JyNI alpha 5) and a stand alone of Jython 2.7.1

i'm trying to call Numpy with this
java -cp jython.jar;Build\JyNI.jar org.python.util.jython Test.py

Test.py:

from sys import path
path.append("D:/Alexis TRAN/Documents/")
print path
path.remove
import numpy as np
print np.__version__
print "Hi <3"

But got an error:

File "D:\Alexis TRAN\Documents\numpy\__init__.py", line 142, in <module>
    from . import add_newdocs
  File "D:\Alexis TRAN\Documents\numpy\add_newdocs.py", line 13, in <module>
    from numpy.lib import add_newdoc
  File "D:\Alexis TRAN\Documents\numpy\lib\__init__.py", line 8, in <module>
    from .type_check import *
  File "D:\Alexis TRAN\Documents\numpy\lib\type_check.py", line 11, in <module>
    import numpy.core.numeric as _nx
  File "D:\Alexis TRAN\Documents\numpy\core\__init__.py", line 42, in <module>
    from . import defchararray as char
  File "D:\Alexis TRAN\Documents\numpy\core\defchararray.py", line 1669, in <module>
    class chararray(ndarray):
TypeError: Error when calling the metaclass bases
    'getset_descriptor' object is not callable

I don't get it, it works with Python but not with Jython/JyNI

Could you help me please?

@Stewori
Copy link
Owner

Stewori commented Dec 29, 2017

Jython most likely locates a version of numpy < 1.12 as the error you observe is typical for that. Where did you obtain NumPy? Only PIP-installed numpy was tested, i.e. no binaries from anaconda or canopy. Or did you build it yourself?
That you are using D:\Alexis TRAN\Documents indicates you are not using numpy installed for CPython. JyNI looks into the registry on Windows to find CPython's dll folder for e.g. ctypes. If you have an older version of numpy installed for CPython this might clash.

  • better use path.insert(0, "D:/Alexis TRAN/Documents/") to ensure it overrides an eventually detected system numpy
  • please run your example with CPython such that we can actually see the result of print np.__version__
  • What is path.remove intended to do?
  • Are you using 32 bit or 64 bit?

If you like I can share a complete standalone folder with Jython/JyNI/NumPy even including JRE. I occasionally use it for demonstrations. It's about 200MB; I would share it via google drive, contact me by email if you're intersted. It would be a starting point to fix configuration.

@Tatsukyo
Copy link
Contributor

Tatsukyo commented Dec 30, 2017

Hi,

path.remove is a fail (brain fuck it was not when testing)
I'm currently using 64bits

the numpy is the 1.13.3 (installed with pip install numpy).
For the numpy in my documents, i just copy paste the folder from my Python Folder

So i tried path.insert(0, "D:/Alexis TRAN/Documents/") nothing still the same error

Honestly, i'm not used with Python and CPython, never used before.
I'm currently trying to insert python code in a java project

Oh and about the JyNI-Demo, on my computer only JyNIDateTimeTest.py and JyNITkinterTest.py work
installed the DemoExtension with setup.py and not the makefile

So, please, could you share ur folder ?

Have a nice day :)

@Tatsukyo
Copy link
Contributor

Hey,

I tried ur folder and it works!

But i don't get it

What is pathswin and what it does
When i'm not importing it i got the same error as me

Thank you for ur help, i appreciate , i will try to integrate it in my java app if u allow it

Have a nice night?

@Stewori
Copy link
Owner

Stewori commented Dec 30, 2017

pathswin configures the sys.path properly. You can try to assess from it what might be missing in your original configuration. I wouldn't recommend that setup for building an app on top. At least you should reduce it to the essential parts. Currently it includes whole cpython dist and a jre. This might be problematic for further distribution also license wise. Not yet speaking of packaging.

@Tatsukyo
Copy link
Contributor

Yeah finally i'm just using this:

import sys
sys.path.insert(0,"D:\Alexis TRAN\Documents\NumpyTest")
sys.path.append("D:\Alexis TRAN\Documents\NumpyTest\DLLs)
import numpy as NP
print NP
A= NP.arange(7)
print A
print "Coucou <3"

With what i understand i only need the DLLs, and it work with just that
maybe i can delete some DLL but i won't play with fire

Thanks U so much !

@Stewori
Copy link
Owner

Stewori commented Dec 30, 2017

All this configuration stuff is not yet well thought out for Jython as it traditionally didn't support C-extensions. Currently the best procedure is to install stuff for CPython and configure JyNI so it finds it in CPython's environment. This will need a proper solution in the future - but now it's what it is: Bleeding edge technology. Good luck with your stuff!

Regarding dlls, I think it only needs _ctypes.pyd from CPython_home/dlls. And CPython_home/Lib/site-packages for NumPy et. al. NumPy's own dlls (i.e. pyd files) are hosted along its py files.

@Tatsukyo
Copy link
Contributor

Yeah i just need to adjust my sys.path to point the good folders right?

@Stewori
Copy link
Owner

Stewori commented Dec 30, 2017

Right. CPython_home/dlls and CPython_home/Lib/site-packages should be sufficient for most cases. It needn't even be the system CPython if sys.path is set up explicitly. However then you must take care when using pip. Using virtualenv or so might be possible, but was not tested and is not explicitly supported.

@Tatsukyo
Copy link
Contributor

Dear Stewori,

I'm currently working with ur JyNI and Jython to integrate Numpy in a Java App as i said.

Is it me or JyNI works only if the jar is nammed JyNI.jar.
I tried to rename JyNI.jar to jyni.jar and it doesnt work, but with JyNI.jar it works !

So the problem is:
I'm using a Nexus to get all my dependencies and obviously JyNI.jar become JyNI-2.7-alpha.jar on my App so... it doesn't work

So maybe u know it and found a solution?

@Stewori
Copy link
Owner

Stewori commented Jan 23, 2018

I'm using a Nexus

I'm afraid Jython does not support Android as of this writing. For more details on this topic refer directly to the Jython project (maybe open an issue or bounty).

Regarding the issue with the jar name: Naming JyNI.jar differently should work if you fix the classpath and launch command accordingly. However I did not test renaming the jar.
What definitely would not work is to rename one of the native library files. These are explicitly loaded by JyNI with their names hardcoded. Reasons for this go down to C-level dynamic loading machanisms.

Finally, let me point out that this would be better suited as a separate issue/thread as it is unrelated to problems with nltk.

@Stewori Stewori mentioned this issue Jun 10, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants