Mac下安装jpype遇到的问题

项目需要,在python中调用java方法。于是乎在mac下安装jpype,网上有win32下的安装程序(.exe),没有直接的安装程序,需要编译源码安装。我下载的时是JPype-0.5.4.2,里面有如下文件:

Mac下安装jpype遇到的问题_第1张图片

这里的setup.py就是要运行的安装程序。


执行安装程序:python setup.py install。


报错:

running install
running build
running build_py
creating build
creating build/lib.macosx-10.8-intel-2.7
creating build/lib.macosx-10.8-intel-2.7/jpype
copying src/python/jpype/__init__.py -> build/lib.macosx-10.8-intel-2.7/jpype
copying src/python/jpype/_core.py -> build/lib.macosx-10.8-intel-2.7/jpype
copying src/python/jpype/_darwin.py -> build/lib.macosx-10.8-intel-2.7/jpype
copying src/python/jpype/_gui.py -> build/lib.macosx-10.8-intel-2.7/jpype
copying src/python/jpype/_jarray.py -> build/lib.macosx-10.8-intel-2.7/jpype
copying src/python/jpype/_jclass.py -> build/lib.macosx-10.8-intel-2.7/jpype
copying src/python/jpype/_jcollection.py -> build/lib.macosx-10.8-intel-2.7/jpype
copying src/python/jpype/_jexception.py -> build/lib.macosx-10.8-intel-2.7/jpype
copying src/python/jpype/_jobject.py -> build/lib.macosx-10.8-intel-2.7/jpype
copying src/python/jpype/_jpackage.py -> build/lib.macosx-10.8-intel-2.7/jpype
copying src/python/jpype/_jproxy.py -> build/lib.macosx-10.8-intel-2.7/jpype
copying src/python/jpype/_jwrapper.py -> build/lib.macosx-10.8-intel-2.7/jpype
copying src/python/jpype/_linux.py -> build/lib.macosx-10.8-intel-2.7/jpype
copying src/python/jpype/_properties.py -> build/lib.macosx-10.8-intel-2.7/jpype
copying src/python/jpype/_pykeywords.py -> build/lib.macosx-10.8-intel-2.7/jpype
copying src/python/jpype/_refdaemon.py -> build/lib.macosx-10.8-intel-2.7/jpype
copying src/python/jpype/_windows.py -> build/lib.macosx-10.8-intel-2.7/jpype
copying src/python/jpype/findjvm.py -> build/lib.macosx-10.8-intel-2.7/jpype
copying src/python/jpype/JClassUtil.py -> build/lib.macosx-10.8-intel-2.7/jpype
copying src/python/jpype/nio.py -> build/lib.macosx-10.8-intel-2.7/jpype
copying src/python/jpype/reflect.py -> build/lib.macosx-10.8-intel-2.7/jpype
creating build/lib.macosx-10.8-intel-2.7/jpype/awt
copying src/python/jpype/awt/__init__.py -> build/lib.macosx-10.8-intel-2.7/jpype/awt
creating build/lib.macosx-10.8-intel-2.7/jpype/awt/event
copying src/python/jpype/awt/event/__init__.py -> build/lib.macosx-10.8-intel-2.7/jpype/awt/event
copying src/python/jpype/awt/event/WindowAdapter.py -> build/lib.macosx-10.8-intel-2.7/jpype/awt/event
creating build/lib.macosx-10.8-intel-2.7/jpypex
copying src/python/jpypex/__init__.py -> build/lib.macosx-10.8-intel-2.7/jpypex
creating build/lib.macosx-10.8-intel-2.7/jpypex/swing
copying src/python/jpypex/swing/__init__.py -> build/lib.macosx-10.8-intel-2.7/jpypex/swing
copying src/python/jpypex/swing/AbstractAction.py -> build/lib.macosx-10.8-intel-2.7/jpypex/swing
copying src/python/jpypex/swing/pyutils.py -> build/lib.macosx-10.8-intel-2.7/jpypex/swing
running build_ext
building '_jpype' extension
creating build/temp.macosx-10.8-intel-2.7
creating build/temp.macosx-10.8-intel-2.7/src
creating build/temp.macosx-10.8-intel-2.7/src/native
creating build/temp.macosx-10.8-intel-2.7/src/native/common
creating build/temp.macosx-10.8-intel-2.7/src/native/python
clang -fno-strict-aliasing -fno-common -dynamic -g -Os -pipe -fno-common -fno-strict-aliasing -fwrapv -mno-fused-madd -DENABLE_DTRACE -DMACOSX -DNDEBUG -Wall -Wstrict-prototypes -Wshorten-64-to-32 -DNDEBUG -g -Os -Wall -Wstrict-prototypes -DENABLE_DTRACE -arch i386 -arch x86_64 -pipe -DMACOSX=1 -I/Library/Java/Home/include -I/Library/Java/Home/include/ -Isrc/native/common/include -Isrc/native/python/include -I/System/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7 -c src/native/common/jp_array.cpp -o build/temp.macosx-10.8-intel-2.7/src/native/common/jp_array.o
clang: warning: argument unused during compilation: '-mno-fused-madd'
In file included from src/native/common/jp_array.cpp:17:
src/native/common/include/jpype.h:45:10: fatal error: 'jni.h' file not found
#include <jni.h>
         ^
1 error generated.
error: command 'clang' failed with exit status 1

从log来看,这里是找不到"jni.h"头文件。


看下setup.py,其中有个设置头文件的函数   :

Mac下安装jpype遇到的问题_第2张图片


在mac下,jni.h头文件的路径是:

/System/Library/Frameworks/JavaVM.framework/Versions/A/Headers/


为了让安装程序能找到jni.h头文件,需要在这里加入jni.h的路径。修改setupInclsion(self)函数:



再次执行安装命令。


还报错:

/usr/bin/lipo: can't create output file: build/temp.macosx-10.8-intel-2.7/src/native/common/jp_array.o (Permission denied)
clang: error: lipo command failed with exit code 1 (use -v to see invocation)
error: command 'clang' failed with exit status 1

这个好办,权限问题。


用root权限执行安装:sudo python setup.py install。


哦了!


你可能感兴趣的:(Mac下安装jpype遇到的问题)