2

I am new to python and jython i want to import numpy in my jython program but whenever i import it shows following error:

Traceback (most recent call last):
File "/home/phpdev/workspace/FirstProgram/testone.py", line 16, 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

and my code is :

import os
import sys
print "hi"
print sys.path
print "hello "
import numpy
print "last"

am using jython 2.7.1:

JyNI : alpha 5
numpy : 1.13.0
jython123
  • 141
  • 1
  • 9
  • What you are trying to do should be workable. Are you sure that NumPy 13.0 is used? How did you install it? How did you configure classpath and pythonpath? I suspect that you have multiple numpy installations in parallel and JyNI takes the wrong one. Importing NumPy 1.13.0 should work, it must be a configuration issue. Note: NumPy from anaconda or canopy is not tested and might yield ABI issues with prebuilt JyNI. – stewori Aug 04 '18 at 02:21
  • See https://github.com/Stewori/JyNI/issues/21 and https://github.com/Stewori/JyNI/issues/18. In both cases the error you observed was due to pythonpath issues. – stewori Aug 04 '18 at 02:28

2 Answers2

0

Although the main goal of JyNI is to support Numpi, it cannot do it(not yet anyway). This is because it is still in its alpha stage.

The easiest alternative I've found is to use a Java Numerical Library. Matrix Tool Kits Java

Vedant Shetty
  • 1,577
  • 13
  • 14
  • Thank you @Vedant Shetty. But i need to run python script from java how can i do? for example if i use Runtime.getRuntime().exec(filename) in java its working fine. but if i import numpy package its throws error like no module. how can i solve this one?. – jython123 Apr 03 '18 at 06:14
0

What you are trying to do should be workable as NumPy 12 and 13 are supported in JyNI alpha 4, 5 and newer.

Most likely, Jython/JyNI locates the wrong NumPy installation. I suspect that you have multiple numpy installations in parallel and JyNI takes the wrong one.

Further information on your platform, classpath and pythonpath (w.r.t. Jython) would be required to tell the actual cause. Some scenarios similar to this issue are discussed at

There may be helpful hints for you. Otherwise, this would be discussed best on the issue tracker or with JyNI's support.

Notes:

  • NumPy from anaconda or canopy is not tested and might yield ABI issues with prebuilt JyNI.
  • NumPy 14 and 15 are not supported by current JyNI (i.e. JyNI alpha 5). See https://github.com/Stewori/JyNI/issues/22.
  • NumPy 13.2 is broken (also for some CPython versions) and was officially withdrawn by the NumPy developers. NumPy 13.3 works fine again with JyNI alpha 4 and 5.
stewori
  • 586
  • 4
  • 12