我正在尝试安装
python-javabridge
(GitHub 链接),以便设置一个 Java 虚拟机来容纳 Python 随后可以引用的不同文件格式的库。然而,该包的作者已经停止了该项目的工作,并且 Python >3.10 似乎不支持它。然而,考虑到该库的价值,我想看看是否可以修复 python-javabridge
以将其安装在较新版本的 Python 上。
目前,我正在 Python 3.10 和 3.11 上测试安装,看看它们有何不同。
从Python 3.10开始,我尝试了以下操作:
> mamba create -n javabridge-test python==3.10.14
> conda activate javabridge-test # Switch to the environment I want to install it in
> pip install python-javabridge
> # Installation proceeds without issue
但是,当我尝试做同样的事情,但使用Python 3.11.8(已提前完成
pip install numpy
以准备好依赖项)时,我收到以下错误消息:
Collecting python-javabridge
Using cached python-javabridge-4.0.3.tar.gz (1.3 MB)
Preparing metadata (setup.py) ... done
Requirement already satisfied: numpy>=1.20.1 in /path/to/envs/javabridge-install/lib/python3.11/site-packages (from python-javabridge) (1.26.4)
Building wheels for collected packages: python-javabridge
Building wheel for python-javabridge (setup.py) ... error
error: subprocess-exited-with-error
× python setup.py bdist_wheel did not run successfully.
│ exit code: 1
╰─> [46 lines of output]
/path/to/envs/javabridge-install/lib/python3.11/site-packages/setuptools/__init__.py:80: _DeprecatedInstaller: setuptools.installer and fetch_build_eggs are deprecated.
!!
********************************************************************************
Requirements should be satisfied by a PEP 517 installer.
If you are using pip, you can try `pip install --use-pep517`.
********************************************************************************
!!
dist.fetch_build_eggs(dist.setup_requires)
running bdist_wheel
running build
running build_py
creating build
creating build/lib.linux-x86_64-cpython-311
creating build/lib.linux-x86_64-cpython-311/javabridge
copying javabridge/__init__.py -> build/lib.linux-x86_64-cpython-311/javabridge
copying javabridge/jutil.py -> build/lib.linux-x86_64-cpython-311/javabridge
copying javabridge/locate.py -> build/lib.linux-x86_64-cpython-311/javabridge
copying javabridge/noseplugin.py -> build/lib.linux-x86_64-cpython-311/javabridge
copying javabridge/wrappers.py -> build/lib.linux-x86_64-cpython-311/javabridge
creating build/lib.linux-x86_64-cpython-311/javabridge/tests
copying javabridge/tests/__init__.py -> build/lib.linux-x86_64-cpython-311/javabridge/tests
copying javabridge/tests/test_cpython.py -> build/lib.linux-x86_64-cpython-311/javabridge/tests
copying javabridge/tests/test_javabridge.py -> build/lib.linux-x86_64-cpython-311/javabridge/tests
copying javabridge/tests/test_jutil.py -> build/lib.linux-x86_64-cpython-311/javabridge/tests
copying javabridge/tests/test_wrappers.py -> build/lib.linux-x86_64-cpython-311/javabridge/tests
creating build/lib.linux-x86_64-cpython-311/javabridge/jars
copying javabridge/jars/cpython.jar -> build/lib.linux-x86_64-cpython-311/javabridge/jars
copying javabridge/jars/rhino-1.7R4.jar -> build/lib.linux-x86_64-cpython-311/javabridge/jars
copying javabridge/jars/runnablequeue.jar -> build/lib.linux-x86_64-cpython-311/javabridge/jars
copying javabridge/jars/test.jar -> build/lib.linux-x86_64-cpython-311/javabridge/jars
running build_ext
javac -source 8 -target 8 /tmp/pip-install-gv_sm6fr/python-javabridge_ea4288a3fc0b4e16815944ed67e58092/java/org/cellprofiler/runnablequeue/RunnableQueue.java
javac -source 8 -target 8 /tmp/pip-install-gv_sm6fr/python-javabridge_ea4288a3fc0b4e16815944ed67e58092/java/org/cellprofiler/javabridge/test/RealRect.java
javac -source 8 -target 8 /tmp/pip-install-gv_sm6fr/python-javabridge_ea4288a3fc0b4e16815944ed67e58092/java/org/cellprofiler/javabridge/CPython.java /tmp/pip-install-gv_sm6fr/python-javabridge_ea4288a3fc0b4e16815944ed67e58092/java/org/cellprofiler/javabridge/CPythonInvocationHandler.java
Note: /tmp/pip-install-gv_sm6fr/python-javabridge_ea4288a3fc0b4e16815944ed67e58092/java/org/cellprofiler/javabridge/CPythonInvocationHandler.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
building 'javabridge._javabridge' extension
creating build/temp.linux-x86_64-cpython-311
gcc -pthread -B /path/to/envs/javabridge-install/compiler_compat -DNDEBUG -fwrapv -O2 -Wall -fPIC -O2 -isystem /path/to/envs/javabridge-install/include -fPIC -O2 -isystem /path/to/envs/javabridge-install/include -fPIC -I/path/to/envs/javabridge-install/lib/python3.11/site-packages/numpy/core/include -I/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.402.b06-2.el8.x86_64/include -I/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.402.b06-2.el8.x86_64/include/linux -I/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.402.b06-2.el8.x86_64/default-java/include -I/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.402.b06-2.el8.x86_64/default-java/include/linux -I/path/to/envs/javabridge-install/lib/python3.11/site-packages/numpy/core/include -I/path/to/envs/javabridge-install/include/python3.11 -c _javabridge.c -o build/temp.linux-x86_64-cpython-311/_javabridge.o
_javabridge.c:196:12: fatal error: longintrepr.h: No such file or directory
#include "longintrepr.h"
^~~~~~~~~~~~~~~
compilation terminated.
error: command '/usr/bin/gcc' failed with exit code 1
[end of output]
note: This error originates from a subprocess, and is likely not a problem with pip.
ERROR: Failed building wheel for python-javabridge
Running setup.py clean for python-javabridge
Failed to build python-javabridge
ERROR: Could not build wheels for python-javabridge, which is required to install pyproject.toml-based projects
您能否告诉我通过 pip 和/或 setuptools 安装的 Python 在 3.10 和 3.11 之间有何变化,以及如何修复此错误以使
python-javabridge
的安装与 Python 3.11 及更高版本兼容?
区别在于,longintrepr.h 在 3.11 中不再作为可见构建库的一部分包含在内。
您可以从 3.10 复制 longintrepr.h,或将所有依赖项升级为与 3.11 兼容的版本
如您的帖子所示,longintrepr.h 在 _javabridge.c 中的第 196 行被引用
_javabridge.c:196:12: fatal error: longintrepr.h: ....
#include "longintrepr.h"
如果您发现 _javabridge.c 的当前源代码不包含该依赖项,这并不奇怪:它不适用于 3.11 并且已得到修复。
您现有的 3.10 兼容构建文件不知道它们与 3.11 不兼容,因为创建它们时 3.11 不存在。不幸的是,这是 python 依赖项的普遍问题,不仅仅是当您尝试使用 gcc 构建 c 扩展时。