I am using jep for running python script in java, I basically need to run the script that uses scikit package. But it shows me error when I try to run, which I couldn't understand.
This is the piece of code in my program,
Jep jep = new Jep();
jep.eval("import sklearn");
It shows the below error,but sklearn works perfectly well in python.
Jul 06, 2016 5:31:50 PM JepEx main
SEVERE: null
jep.JepException: jep.JepException: : /usr/local/lib/python2.7/dist-packages/sklearn/__check_build/_check_build.so: undefined symbol: _PyThreadState_Current
Contents of /usr/local/lib/python2.7/dist-packages/sklearn/check_build:
setup.py __init.pyc _check_build.so
build init.py setup.pyc
It seems that scikit-learn has not been built correctly.
If you have installed scikit-learn from source, please do not forget
to build the package before using it: run python setup.py install or
make in the source directory.
If you have used an installer, please check that it is suited for your
Python version, your operating system and your platform.
at jep.Jep.eval(Jep.java:485)
at JepEx.executeCommand(JepEx.java:26)
at JepEx.main(JepEx.java:38)
Caused by: jep.JepException: : /usr/local/lib/python2.7/dist-packages/sklearn/__check_build/_check_build.so: undefined symbol: _PyThreadState_Current
Contents of /usr/local/lib/python2.7/dist-packages/sklearn/check_build:
setup.py __init.pyc _check_build.so
build init.py setup.pyc
It seems that scikit-learn has not been built correctly.
If you have installed scikit-learn from source, please do not forget
to build the package before using it: run python setup.py install or
make in the source directory.
If you have used an installer, please check that it is suited for your
Python version, your operating system and your platform.
at /usr/local/lib/python2.7/dist-packages/sklearn/check_build/__init.raise_build_error(init.py:41)
at /usr/local/lib/python2.7/dist-packages/sklearn/check_build/__init.(init.py:46)
at /usr/local/lib/python2.7/dist-packages/sklearn/init.(init.py:56)
The _PyThreadState_Current error implies that it's using the wrong Python. You should be able to fix it by setting PATH and LD_LIBRARY_PATH to the python/bin and python/lib directories you want to use (and built Jep and sklearn against) before launching the process. That will ensure that Python, Jep, and sklearn are all using the same libraries.
If that doesn't work, it's possible that Jep or sklearn were built with different versions of Python than you're running.
We had the same problem.We believe it's a build problem and since rebuilding scikit-learn did not solved that we ended up using scikit-learn using the prebuilt Anacoda2.
Related
I'm developing an application in java, and in this one, I use jython-standalone (Jython for untold reasons, its goal being to ease some scripting within the application).
I would like to have access to NumPy, and it seems that JyNI provides such capabilities.
I found many posts explaining how to start a Jython project using JyNI, but none on how to include the .jar or something in the application so that it is available when needed.
As stated on JyNI, java -cp build/JyNI.jar -jar jython.jar does not work.
Is there a way for me to use JyNI when executing some Jython code through a PythonInterpreter ?
You should be able to start the live interpreter by executing the class org.python.util.jython.
On Linux, OSX:
java -cp jython.jar:build/JyNI.jar org.python.util.jython
On Windows:
java -cp jython.jar;build\JyNI.jar org.python.util.jython
Alternatively, one can use Jython's start script:
jython -J-cp build/JyNI.jar
This info is taken from https://github.com/Stewori/JyNI#running-jyni, but leaving out the script argument someFile.py.
If you want to explicitly leverage the interpreter through Java code, you will surely have some way to launch your overall application. Make sure to have JyNI.jar and the folder containing its binaries on classpath in that command. Jython should be running with JyNI support then.
A side-note: Be sure to use Jython 2.7.1 and NumPy >= 1.12. Version mismatch of these prerequisites is a common cause of failure.
I downloaded the Carrot2 Document clustering server build 3.15.0 for Mac. The read me file says:
The DCS requires a Java Runtime Environment (JRE) version 1.7.0 or later. To
run the DCS, execute the 'dcs' script and point your browser at
http://localhost:8080 for further instructions.
Mac OS Sierra doesn't make it easy, but I got 1.8.0_112 installed.
The problem is that I don't know how to execute the 'dcs' script.
There are .cmd, .sh, .war, and .jar files. I wasn't sure which of those to work with. I thought .jar looked promising, so I followed some of this thread and tried this in a terminal window:
java -jar invoker.jar
I cd-ed to the correct directory, but it just says Provide main class, but I'm not sure what or where that is.
Can anybody provide instructions or a link to how to do this?
Use the dcs.sh (on Linux/Mac) and dcs.cmd (on Windows) to start the server. The scripts will set some extra options for the JVM and then start the DCS. In case of any problems, append the -v option to see diagnostic output.
After a long time I tried to run my Eclipse, I got:
Failed to create java virtual machine
So I searched and tried changing some eclipse.ini lines to -Xmx512m.
I thought it was Eclipse problem, I tried command prompt but the java command returned:
/lib/ext exists, extensions mechanism no longer supported; Use -classpath instead.
.Error: Could not create the Java Virtual Machine.
Error: A fatal exception has occurred. Program will exit.
I have jre1.9.0 (which I don't remember installing this version).
The extensions mechanism was removed in Java 9, much to my irritation. You could specify an extensions directory on -Djava.ext.dirs or extension jars could be put in $JAVA_HOME/lib/ext and all the jars would be loaded before loading your classpath, and even before a lot of standard libraries. The lords of Java decided that nobody was using this, but I beg to differ. JDK9 release notes.
I am having some serious trouble installing and running Jython. I am completely new to how jython runs, so I am pretty lost. I have downloaded Jython 2.5.3 and java jre 1.8.0_25. I believe I have succesfully run the jython.jar file using this command in cmd:
C:\java\jre1.8.0_25\bin\java -jar C:\jython2.5.3\jython.jar
I have beginner-intermediate (closer to beginner) knowledge of programming in jython, but that is on a computer with jython already installed. My main problem is being able to run jython so I can see the actual function/program area where you would type out your functions then run them. I appreciate any help someone can give.
That command is exactly how you run Jython, and without providing any additional arguments, the Jython interpreter will start (where you can type out functions and run them).
If you want to run Jython with a single command, there should be a jython.bat file located somewhere under the Jython installation directory. Jython does not have a true executable because it is run through Java. The jython.bat file is the closest you'll get to an executable because it is a batch script which runs the jython.jar file using a command nearly identical to yours with Java. jython.bat should be located at one of the following locations:
C:\jython2.5.3\jython.bat
C:\jython2.5.3\bin\jython.bat
NOTE: The jython.bat file requires a standard Java installation.
I am trying to install Inline::Java module in cpan but getting the following error. Please can someone help. Thank you.
Welcome to the Inline::Java installation procedure.
A Java 2 SDK is required to install and use Inline::Java. Please
specify your Java 2 SDK installation directory using the J2SDK
option to Makefile.PL as such:
perl Makefile.PL J2SDK=/path/to/your/j2sdk/installation
You can set the JAVA_HOME environment variable to specify your
Java 2 SDK installation directory. For example, if you are using
the CPAN installer you can do:
JAVA_HOME=/path/to/your/j2sdk/installation cpan Inline::Java
Warning: No success on command[/usr/bin/perl Makefile.PL]
'YAML' not installed, will not store persistent state
PATL/Inline-Java-0.53.tar.gz
/usr/bin/perl Makefile.PL -- NOT OK
Running make test
Make had some problems, won't test
Running make install
Make had some problems, won't install
Could not read metadata file. Falling back to other methods to determine prerequisites
Failed during this command:
PATL/Inline-Java-0.53.tar.gz : writemakefile NO '/usr/bin/perl Makefile.PL' returned status 256
I haven't used java anytime. Please throw some light on it for proper understanding for java. Thank you in advance.
This helped me out
http://www.cyberciti.biz/faq/centos-linux-6-install-java-sdk/
And I am able to run the sample java code. Thanks.