我正在尝试使用ScriptEngine在Java中编写Python脚本。但是当我导入tflearn模块时,它会给我以下错误。
javax.script.ScriptException: ImportError:
Importing the multiarray numpy extension module failed. Most
likely you are trying to import a failed build of numpy.
If you're working with a numpy git repo, try `git clean -xdf` (removes all
files not under version control). Otherwise reinstall numpy.
Original error was: cannot import name multiarray
in <script> at line number 1
at org.python.jsr223.PyScriptEngine.scriptException(PyScriptEngine.java:222)
at org.python.jsr223.PyScriptEngine.eval(PyScriptEngine.java:59)
at org.python.jsr223.PyScriptEngine.eval(PyScriptEngine.java:31)
at javax.script.AbstractScriptEngine.eval(AbstractScriptEngine.java:264)
at com.ultimatix.bot.JavaRunCommand.main(JavaRunCommand.java:48)
Caused by: Traceback (most recent call last):
File "<script>", line 1, in <module>
File "D:\Python\Lib\site-packages\tflearn\__init__.py", line 4, in <module>
from . import config
File "D:\Python\Lib\site-packages\tflearn\config.py", line 3, in <module>
import tensorflow as tf
File "D:\Python\Lib\site-packages\tensorflow\__init__.py", line 24, in <module>
from tensorflow.python import *
File "D:\Python\Lib\site-packages\tensorflow\python\__init__.py", line 47, in <module>
import numpy as np
File "D:\Python\Lib\site-packages\numpy\__init__.py", line 142, in <module>
from . import add_newdocs
File "D:\Python\Lib\site-packages\numpy\add_newdocs.py", line 13, in <module>
from numpy.lib import add_newdoc
File "D:\Python\Lib\site-packages\numpy\lib\__init__.py", line 8, in <module>
from .type_check import *
File "D:\Python\Lib\site-packages\numpy\lib\type_check.py", line 11, in <module>
import numpy.core.numeric as _nx
File "D:\Python\Lib\site-packages\numpy\core\__init__.py", line 26, in <module>
raise ImportError(msg)
我还尝试导入一些不同的包,如sys,pickle。它们正在成功导入。
Python版本:3.5.4 操作系统:窗口7 - 64位
答案 0 :(得分:0)
Numpy是用Fortran编写的,编译成二进制文件。因此,在JVM上运行是不兼容的。您导入的其他包是用纯python实现的。
标准的python实现CPython已经做了很多工作以保持二进制级别的兼容性。 Numpy数组与C数组具有相同的内存布局,这些数组与Java数组的内存布局不同。随着你对python的深入研究,关于为什么它不能工作会有更多的不兼容性。