Giter VIP home page Giter VIP logo

Comments (15)

Stewori avatar Stewori commented on June 17, 2024

As I told you: I didn't test renaming the jar. Could you describe how you launch Jython/JyNI, and how you configure the classpath?

from jyni.

Tatsukyo avatar Tatsukyo commented on June 17, 2024

I launch Jython/Jyni with this:

java -cp jython.jar;JyNI.jar org.python.util.jython test.py (this works ! obviously JyNI is named JyNI.jar)
i got this:

['D:\\Alexis TRAN\\Documents\\NumpyTest\\TestNumpy\\Jar', 'D:\\Alexis TRAN\\Documents\\NumpyTest\\TestNumpy\\Jar\\JyNI.jar', 'D:\\Alexis TRAN\\Documents\\NumpyTest\\TestNumpy\\Jar\\Lib', 'D:\\Alexis TRAN\\Documents\\NumpyTest\\TestNumpy\\Jar\\jython.jar\\Lib', '__classpath__', '__pyclasspath__/', 'D:\\Alexis TRAN\\Documents\\NumpyTest\\TestNumpy\\Libraries', 'D:\\Alexis TRAN\\Documents\\NumpyTest\\TestNumpy\\DLLs']
<module 'numpy' from 'D:\Alexis TRAN\Documents\NumpyTest\TestNumpy\Libraries\numpy\__init__$py.class'>
[0 1 2 3 4 5 6]
Coucou <3

but when i rename JyNI.jar like JyNII.jar (it doesnt):
java -cp jython.jar;JyNII.jar org.python.util.jython test.py
and i got this:

['D:\\Alexis TRAN\\Documents\\NumpyTest\\TestNumpy\\Jar', 'D:\\Alexis TRAN\\Documents\\NumpyTest\\TestNumpy\\Jar\\Lib', 'D:\\Alexis TRAN\\Documents\\NumpyTest\\TestNumpy\\Jar\\jython.jar\\Lib', '__classpath__', '__pyclasspath__/', 'D:\\Alexis TRAN\\Documents\\NumpyTest\\TestNumpy\\Libraries', 'D:\\Alexis TRAN\\Documents\\NumpyTest\\TestNumpy\\DLLs']
Traceback (most recent call last):
  File "test.py", line 5, in <module>
    import numpy as NP
  File "D:\Alexis TRAN\Documents\NumpyTest\TestNumpy\Libraries\numpy\__init__.py", line 142, in <module>
    from . import add_newdocs
  File "D:\Alexis TRAN\Documents\NumpyTest\TestNumpy\Libraries\numpy\add_newdocs.py", line 13, in <module>
    from numpy.lib import add_newdoc
  File "D:\Alexis TRAN\Documents\NumpyTest\TestNumpy\Libraries\numpy\lib\__init__.py", line 8, in <module>
    from .type_check import *
  File "D:\Alexis TRAN\Documents\NumpyTest\TestNumpy\Libraries\numpy\lib\type_check.py", line 11, in <module>
    import numpy.core.numeric as _nx
  File "D:\Alexis TRAN\Documents\NumpyTest\TestNumpy\Libraries\numpy\core\__init__.py", line 42, in <module>
    from . import defchararray as char
  File "D:\Alexis TRAN\Documents\NumpyTest\TestNumpy\Libraries\numpy\core\defchararray.py", line 1669, in <module>
    class chararray(ndarray):
TypeError: Error when calling the metaclass bases
    'getset_descriptor' object is not callable

It's look like if JyNI is not named JyNI.jar Jython cannot magically get JyNI

test.py is :

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

So obviously, JyNI need to be named JyNI.jar and nothing else

from jyni.

Stewori avatar Stewori commented on June 17, 2024

Alright. I looked a bit into the code and probably this line causes the issue.

So, basically the issue is that JyNI.jar must be on classpath and on jyhonpath/pythonpath.
For convenience, JyNI looks for a JyNI.jar on classpath and if it encounters one it copies the entry (including location) to jyhonpath/pythonpath. In case of a custom name this routine does not trigger.

Please try to add your custom-named jar manually to jyhonpath/pythonpath before the first C-Extension import is attempted.

If this doesn't help, it would be great if you could try to replace "JyNI.jar" with your custom jar-filename in JyNIInitializer.java. Of course we would need a more general solution if this works.
Suggestions?

from jyni.

Tatsukyo avatar Tatsukyo commented on June 17, 2024

tried to add JyNI to the python path but got an error too:
java -cp jython.jar org.python.util.jython test.py

['D:\\Alexis TRAN\\Documents\\NumpyTest\\TestNumpy\\Jar\\JyNII.jar', 'D:\\Alexis TRAN\\Documents\\NumpyTest\\TestNumpy\\Jar', 'D:\\Alexis TRAN\\Documents\\NumpyTest\\TestNumpy\\Jar\\Lib', 'D:\\Alexis TRAN\\Documents\\NumpyTest\\TestNumpy\\Jar\\jython.jar\\Lib', '__classpath__', '__pyclasspath__/', 'D:\\Alexis TRAN\\Documents\\NumpyTest\\TestNumpy\\Libraries', 'D:\\Alexis TRAN\\Documents\\NumpyTest\\TestNumpy\\DLLs']
Traceback (most recent call last):
  File "test.py", line 6, in <module>
    import numpy as NP
  File "D:\Alexis TRAN\Documents\NumpyTest\TestNumpy\Libraries\numpy\__init__.py", line 142, in <module>
    from . import add_newdocs
  File "D:\Alexis TRAN\Documents\NumpyTest\TestNumpy\Libraries\numpy\add_newdocs.py", line 13, in <module>
    from numpy.lib import add_newdoc
  File "D:\Alexis TRAN\Documents\NumpyTest\TestNumpy\Libraries\numpy\lib\__init__.py", line 8, in <module>
    from .type_check import *
  File "D:\Alexis TRAN\Documents\NumpyTest\TestNumpy\Libraries\numpy\lib\type_check.py", line 11, in <module>
    import numpy.core.numeric as _nx
  File "D:\Alexis TRAN\Documents\NumpyTest\TestNumpy\Libraries\numpy\core\__init__.py", line 26, in <module>
    raise ImportError(msg)
ImportError:
Importing the multiarray numpy extension module failed.  Most
likely you are trying to import a failed build of numpy.
If you're working with a numpy git repo, try `git clean -xdf` (removes all
files not under version control).  Otherwise reinstall numpy.

Original error was: cannot import name multiarray

test.py is:

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

maybe i'm not doing this correctly i'm not used to python

and about replace "JyNI.jar" with my custom jar will change nothing, the name will be anyway hardcoded

but what about a Regex?

maybe something like this?: (i'm not used to regex too ...)
\bJyNI\b.*\b\.jar\b
the file name still need to start by JyNI and end by .jar but we can add the version behind JyNI
something like JyNI_2.7_alpha.jar which is cool

from jyni.

Stewori avatar Stewori commented on June 17, 2024

and about replace "JyNI.jar" with my custom jar will change nothing, the name will be anyway hardcoded

This is a crucial step to identify if this is really the cause. Of course this is not the solution.

from jyni.

Tatsukyo avatar Tatsukyo commented on June 17, 2024

When i try to change the JyNI-Java folder i got an error with the import everything is red so i can't compile to a new jar so maybe i need to import Jython to JyNI? could u explain me how to ?

even with the import or Jython i doesn't work, i can't find a way to open your project and compile it properly

from jyni.

Stewori avatar Stewori commented on June 17, 2024

There are detailed build instructions in the readme. Don't use IDE for building JyNI, use make. IDEs have too many pifalls. To build only the Java part use make JyNI. (don't forget e.g. -f makefile.win64 for Windows like shown in the readme).
You can use the IDE for viewing and editing; if it complains much about unknown classes, most likely it doesn't have Jython on its classpath. How to add this is IDE specific.

from jyni.

Tatsukyo avatar Tatsukyo commented on June 17, 2024

Yeah i got it after 1-2 hours xD

Currently i'm trying to run the makefile ... i need to configure all (javac not found, java not found, etc...)

Why i'm working with 2 harddrives ...

from jyni.

Tatsukyo avatar Tatsukyo commented on June 17, 2024

IT WORKS !

i changed the:

String[] cp = System.getProperty("java.class.path").split(File.pathSeparator);
for (int i = 0; i < cp.length; ++i)
{
	if (cp[i].endsWith("JyNI.jar")) 
        {
		initState.path.add(0, cp[i]);
		//initState.path.add(0, cp[i]+"/lib-tk");
	}
}

with:

String[] cp = System.getProperty("java.class.path").split(File.pathSeparator);
for (int i = 0; i < cp.length; ++i) 
{
	Pattern p  = Pattern.compile("\\bJyNI\\b.*\\b\\.jar\\b");
	Matcher m = p.matcher(cp[i]);
	if (m.find()) 
        {
		initState.path.add(0, cp[i]);
		//initState.path.add(0, cp[i]+"/lib-tk");
	}
}

i tried if it works with a file named TestJyNI.jar and it's works obviously it's the endsWith
so i changed it with a Regex, now it just need to be start with JyNI and end with .jar
So JyNII.jar won't work but JyNI-Alpha_2.5.jar works

Just what i needed :D Thanks for ur help Stewori i close this issue

from jyni.

Stewori avatar Stewori commented on June 17, 2024

(crossposting the message from #24 here for better visibility)

Thanks for your work on this. I think this commit is a good workaround for now (so I'll accept it), but I wouldn't consider it the final solution. What do you think of having an entry for the jar-name to be added to Pythonpath in the manifest/META-INF? Then one would have to adjust the manifest when changing the jar filename, but it would allow for fully freeform names.
JyNI already involves a specialized META-INF entry for Jython initialization: https://github.com/Stewori/JyNI/blob/master/JyNI-Java/META-INF/services/org.python.core.JythonInitializer

from jyni.

Stewori avatar Stewori commented on June 17, 2024

Another idea: We could use a technique like this to determine which jar file is hosting JyNI.class. Then copy that jarfile to pythonpath.

from jyni.

Tatsukyo avatar Tatsukyo commented on June 17, 2024

if we have an entry for the jar-name in the manifest it will be the same problem, in a way it will be hardcoded, this is exactly why i worked on this

To explain why i refuse this solution, it's because, To get JyNI, i'm using a Maven Central
so the jar imported in my project (JyNI)
become
JyNI-{version}.jar

that's why i'm using a regex

but the second solution can be nice ! i'm currently working on it

from jyni.

Stewori avatar Stewori commented on June 17, 2024

I'm thinking of use cases beyond maven, especially uberjars. Then the jar name can be really anything. I agree, having to edit the manifest is tedious (but definitely better than having the value in Java code).
Currently I think, detecting the hosting jar-file from JyNI.class like in the linked stackoverflow topic above, is the best way.

from jyni.

Tatsukyo avatar Tatsukyo commented on June 17, 2024

Yeah this is done and tested i commit this to you with a merge request

from jyni.

Tatsukyo avatar Tatsukyo commented on June 17, 2024

Cuz of the merge request i close this

from jyni.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.