jpype-project / jpype

JPype is cross language bridge to allow Python programs full access to Java class libraries.
http://www.jpype.org
Apache License 2.0
1.09k stars 179 forks source link

ImportError: DLL load failed while importing _jpype #1167

Open panc-test opened 8 months ago

panc-test commented 8 months ago

Traceback (most recent call last): File "C:/Users/057776/PycharmProjects/funds-app-mock/utils/encrypt.py", line 9, in import jpype File "C:\Users\057776\PycharmProjects\funds-app-mock\venv\lib\site-packages\jpype__init__.py", line 18, in import _jpype ImportError: DLL load failed while importing _jpype: 找不到指定的模块。

version = "1.5.0" JPype1-1.5.0-cp38-cp38-win_amd64.whl wind10 ,64

(venv) C:\Users\057776\PycharmProjects\funds-app-mock>pip install JPype1 Requirement already satisfied: JPype1 in c:\users\057776\pycharmprojects\funds-app-mock\venv\lib\site-packages (1.5.0) Requirement already satisfied: packaging in c:\users\057776\pycharmprojects\funds-app-mock\venv\lib\site-packages (from JPype1) (23.2)

marscher commented 8 months ago

It'd be great to have the error message in English. Setting the locale in your operating system or setting a shell variable should do the trick

ryanmkurtz commented 2 months ago

I'm seeing basically the same thing in a Windows 11 sandbox with the standard python.org 3.12.4 installed:

C:\Users\WDAGUtilityAccount>py
Python 3.12.4 (tags/v3.12.4:8e8a4ba, Jun  6 2024, 19:30:16) [MSC v.1940 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import jpype
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Users\WDAGUtilityAccount\AppData\Local\Programs\Python\Python312\Lib\site-packages\jpype\__init__.py", line 18, in <module>
    import _jpype
ImportError: DLL load failed while importing _jpype: The specified module could not be found.
>>>
astrelsky commented 2 months ago

I'm seeing basically the same thing in a Windows 11 sandbox with the standard python.org 3.12.4 installed:

C:\Users\WDAGUtilityAccount>py
Python 3.12.4 (tags/v3.12.4:8e8a4ba, Jun  6 2024, 19:30:16) [MSC v.1940 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import jpype
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Users\WDAGUtilityAccount\AppData\Local\Programs\Python\Python312\Lib\site-packages\jpype\__init__.py", line 18, in <module>
    import _jpype
ImportError: DLL load failed while importing _jpype: The specified module could not be found.
>>>

I don't know why, but it's not finding msvcp140.dll even though it comes with Java and is added to the system path by default when installing Java. Copying C:\Program Files\Eclipse Adoptium\jdk-22.0.1.8-hotspot\bin\msvcp140.dll to C:\Windows\System32\ does fix it.

This really doesn't make any sense. The msvcp140.dll can be found and loaded using ctypes.util.find_library and ctypes.WinDLL, and then importing jpype will work just fine after that. This almost looks like a python bug, but it could be some weird windows configuration thing.

The "correct" solution to recommend is probably to install the Latest Microsoft Visual C++ Redistributable Version but it really shouldn't be necessary since it comes with Java and is in the system path already.