ninia / jep

Embed Python in Java
Other
1.32k stars 150 forks source link

Cannot run jep #391

Open Daniel-Alievsky opened 2 years ago

Daniel-Alievsky commented 2 years ago

I tried to install JEP on my Windows, but it fails: see log below. It requires Microsoft C++ Build Tools, I installed them from https://visualstudio.microsoft.com/visual-cpp-build-tools/, but it does not help. Moreover, to be on the safe side I've installed full Microsoft Visual Studio 2022 from https://visualstudio.microsoft.com/, but it also doesn't help.

I use Windows 8.1, Python 3.10.4, Java 17. I've attached log-file.

log.txt

Maybe, there is somewhere a ready installation pack for JEP, that I can just download and install?

Daniel-Alievsky commented 2 years ago

It seems I found the problem. It was necessary to download "Desktop development with C++", which was not selected in the installer by default.

Daniel-Alievsky commented 2 years ago

Ok, I've installed JEP. However, the very first test leads to an error. I just call "jep.bat", created by "pip install jep", without arguments. Results attached. It does not find necessary DLLs. logrun.txt

bsteffensmeier commented 2 years ago

Your error is likely caused because the Java process cannot find the python310 dll. You could try setting PYTHONHOME to "C:\Users\Daniel\AppData\Local\Programs\Python\" or adding the directory where the python310 dll is located to the PATH. I am not very familiar with how windows loads libraries so I am not sure if there are other variables involved in finding libraries.

Daniel-Alievsky commented 2 years ago

Thank you very much, adding PYTHONHOME really helped. But I've set it to C:\Users\Daniel\AppData\Local\Programs\Python\Python310\ (folder of current Python version), not C:\Users\Daniel\AppData\Local\Programs\Python

Daniel-Alievsky commented 2 years ago

But now I have another question. In your .bat-file, I see the line SET jni_path="C:\Users\Daniel\AppData\Local\Programs\Python\Python310\Lib\site-packages\jep" But really (after setting PYTHONHOME) all works fine even I does not use this line and the argument java.library.path What is the reason? When jep.dll is really necessary?

Daniel-Alievsky commented 2 years ago

Also, I've cloned your repository (D:\W\jep), compiled all in IntelliJ IDEA and tried to call your Java tests from src\test\java\jep Of course, I've added jep-4.0.3.jar into classpath. But the tests don't work; I've not found any working test. For example:

D:\W\jep>java -classpath target/test-classes;target/classes;C:\Users\Daniel\AppData\Local\Programs\Python\Python310\Lib\site-packages\jep\jep-4.0.3.jar jep.test.Test Exception in thread "main" jep.JepException: Invalid file: D:\W\jep\runtests.py at jep.Jep.runScript(Jep.java:244) at jep.test.Test.main(Test.java:335)

D:\W\jep>java -classpath target/test-classes;target/classes;C:\Users\Daniel\AppData\Local\Programs\Python\Python310\Lib\site-packages\jep\jep-4.0.3.jar jep.test.TestGetByteArray jep.JepException: <class 'OSError'>: 22 at .(:1) at jep.Jep.eval(Native Method) at jep.Jep.eval(Jep.java:312) at jep.test.TestGetByteArray.testGetByteArray(TestGetByteArray.java:47) at jep.test.TestGetByteArray.main(TestGetByteArray.java:28)

What did go wrong? I'd like to find more examples of using Jep.

ndjensen commented 2 years ago

We probably put the JNI path in jep.bat to match the Linux/macOS version of the script. I don't want to take it out unless we're absolutely 100% sure it's not helping anyone get it to work. At least on Linux, people will often have libpython in a different location than libjep due to permissions and installing site-packages. And then if you have virtualenvs that complicates things too. I assume similar situations could happen on Windows.

To run the tests, run python setup.py test. To see what that command is doing, look at commands/test.py.

Daniel-Alievsky commented 2 years ago

So, if I understand well, these test are not intended to be demo examples, they are just internal tests that should be called by special script "setup.py"?

ndjensen commented 2 years ago

https://stackoverflow.com/questions/1471994/what-is-setup-py

bsteffensmeier commented 2 years ago

But now I have another question. In your .bat-file, I see the line SET jni_path="C:\Users\Daniel\AppData\Local\Programs\Python\Python310\Lib\site-packages\jep" But really (after setting PYTHONHOME) all works fine even I does not use this line and the argument java.library.path What is the reason? When jep.dll is really necessary?

We have [code that tries to find the jep library and the python library](jep library and the python library) based off of the environment including PYTHONHOME. For many people this is enough to find both jep library and the python library. In some environments, such as a venv, PYTHONHOME can break things and cannot be used so we don't include it in jep.bat by default. java.library.path is a very reliable way to specify the location of the jep library but cannot be used for the python library. We try to provide multiple ways to get things working because there are alot of different ways people are installing python and we have not found a single solution that is working for all users.

Daniel-Alievsky commented 2 years ago

Thank you for explanations!

Daniel-Alievsky commented 2 years ago

Maybe you will add your advice to set PYTHONHOME into your documentation https://github.com/ninia/jep/wiki/Getting-Started ?

harbby commented 1 year ago

I successfully installed it on windows using mingw64. env:

setup list:

1. python3 setup build --compiler=mingw32
2. python3 setup install