【发布时间】:2022-08-09 00:38:19
【问题描述】:
我有一个运行 python 脚本的 bash 脚本:
#!/bin/bash
restest-env/bin/python3 script.py $1 $2 $3
从终端执行时,一切正常。相反,当从 Java 应用程序执行时:
ProcessBuilder pb = new ProcessBuilder(command, String.join(\" \",commandArgs));
Process proc = pb.start();
proc.getOutputStream();
String stdout = IOUtils.toString(proc.getInputStream(), Charset.defaultCharset());
String stderr = IOUtils.toString(proc.getErrorStream(), Charset.defaultCharset());
proc.waitFor();
我得到这个与 M1 芯片相关的错误:
Traceback (most recent call last):
File \"/Users/giulianomirabella/Desktop/RESTest/ml/restest-env/lib/python3.8/site-packages/numpy/core/__init__.py\", line 23, in <module>
from . import multiarray
File \"/Users/giulianomirabella/Desktop/RESTest/ml/restest-env/lib/python3.8/site-packages/numpy/core/multiarray.py\", line 10, in <module>
from . import overrides
File \"/Users/giulianomirabella/Desktop/RESTest/ml/restest-env/lib/python3.8/site-packages/numpy/core/overrides.py\", line 6, in <module>
from numpy.core._multiarray_umath import (
ImportError: dlopen(/Users/giulianomirabella/Desktop/RESTest/ml/restest-env/lib/python3.8/site-packages/numpy/core/_multiarray_umath.cpython-38-darwin.so, 0x0002): tried: \'/Users/giulianomirabella/Desktop/RESTest/ml/restest-env/lib/python3.8/site-packages/numpy/core/_multiarray_umath.cpython-38-darwin.so\' (mach-o file, but is an incompatible architecture (have \'arm64\', need \'x86_64\'))
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File \"ml/python-scripts/al_predictor.py\", line 2, in <module>
import numpy as np
File \"/Users/giulianomirabella/Desktop/RESTest/ml/restest-env/lib/python3.8/site-packages/numpy/__init__.py\", line 140, in <module>
from . import core
File \"/Users/giulianomirabella/Desktop/RESTest/ml/restest-env/lib/python3.8/site-packages/numpy/core/__init__.py\", line 49, in <module>
raise ImportError(msg)
ImportError:
IMPORTANT: PLEASE READ THIS FOR ADVICE ON HOW TO SOLVE THIS ISSUE!
Importing the numpy C-extensions failed. This error can happen for
many reasons, often due to issues with your setup or how NumPy was
installed.
We have compiled some common reasons and troubleshooting tips at:
https://numpy.org/devdocs/user/troubleshooting-importerror.html
Please note and check the following:
* The Python version is: Python3.8 from \"/Users/giulianomirabella/Desktop/RESTest/ml/restest-env/bin/python3\"
* The NumPy version is: \"1.23.1\"
and make sure that they are the versions you expect.
Please carefully study the documentation linked above for further help.
Original error was: dlopen(/Users/giulianomirabella/Desktop/RESTest/ml/restest-env/lib/python3.8/site-packages/numpy/core/_multiarray_umath.cpython-38-darwin.so, 0x0002): tried: \'/Users/giulianomirabella/Desktop/RESTest/ml/restest-env/lib/python3.8/site-packages/numpy/core/_multiarray_umath.cpython-38-darwin.so\' (mach-o file, but is an incompatible architecture (have \'arm64\', need \'x86_64\'))
2022-07-18 11:21:14 INFO stdout:36 - Traceback (most recent call last):
File \"/Users/giulianomirabella/Desktop/RESTest/ml/restest-env/lib/python3.8/site-packages/numpy/core/__init__.py\", line 23, in <module>
from . import multiarray
File \"/Users/giulianomirabella/Desktop/RESTest/ml/restest-env/lib/python3.8/site-packages/numpy/core/multiarray.py\", line 10, in <module>
from . import overrides
File \"/Users/giulianomirabella/Desktop/RESTest/ml/restest-env/lib/python3.8/site-packages/numpy/core/overrides.py\", line 6, in <module>
from numpy.core._multiarray_umath import (
ImportError: dlopen(/Users/giulianomirabella/Desktop/RESTest/ml/restest-env/lib/python3.8/site-packages/numpy/core/_multiarray_umath.cpython-38-darwin.so, 0x0002): tried: \'/Users/giulianomirabella/Desktop/RESTest/ml/restest-env/lib/python3.8/site-packages/numpy/core/_multiarray_umath.cpython-38-darwin.so\' (mach-o file, but is an incompatible architecture (have \'arm64\', need \'x86_64\'))
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File \"ml/python-scripts/al_predictor.py\", line 2, in <module>
import numpy as np
File \"/Users/giulianomirabella/Desktop/RESTest/ml/restest-env/lib/python3.8/site-packages/numpy/__init__.py\", line 140, in <module>
from . import core
File \"/Users/giulianomirabella/Desktop/RESTest/ml/restest-env/lib/python3.8/site-packages/numpy/core/__init__.py\", line 49, in <module>
raise ImportError(msg)
ImportError:
IMPORTANT: PLEASE READ THIS FOR ADVICE ON HOW TO SOLVE THIS ISSUE!
Importing the numpy C-extensions failed. This error can happen for
many reasons, often due to issues with your setup or how NumPy was
installed.
We have compiled some common reasons and troubleshooting tips at:
https://numpy.org/devdocs/user/troubleshooting-importerror.html
Please note and check the following:
* The Python version is: Python3.8 from \"/Users/giulianomirabella/Desktop/RESTest/ml/restest-env/bin/python3\"
* The NumPy version is: \"1.23.1\"
and make sure that they are the versions you expect.
Please carefully study the documentation linked above for further help.
Original error was: dlopen(/Users/giulianomirabella/Desktop/RESTest/ml/restest-env/lib/python3.8/site-packages/numpy/core/_multiarray_umath.cpython-38-darwin.so, 0x0002): tried: \'/Users/giulianomirabella/Desktop/RESTest/ml/restest-env/lib/python3.8/site-packages/numpy/core/_multiarray_umath.cpython-38-darwin.so\' (mach-o file, but is an incompatible architecture (have \'arm64\', need \'x86_64\'))
所以奇怪的是python在直接从终端执行时工作正常,但从Java执行时失败。我不能使用conda。有任何想法吗?
-
如何运行 Java 进程?使用
java可执行文件? -
错误说您需要 x86_64 依赖项,但您有 arm64,我建议您安装 x86_64 依赖项并重试。
-
我怀疑Java是通过模拟器运行的,并且是伪装的x86_64进程。所以从 Java 内部执行的任何命令都会认为它在 x86_42 环境中运行,而 NumPy 是专门为 Arm64 编译的。至于为什么 Python 在这两种情况下都运行:默认的
/usr/bin/python3在其二进制文件中包含这两种架构。 -
您的虚拟环境是如何创建的?
-
尝试让 Java 运行
arch -arm64 python3 ...。显然不是便携式解决方案。
标签: python numpy apple-m1 arm64