7

I am trying to use Neo4j for a project, and want to interface with it through Python since I'm a newbie to programming and don't know any Java. I'm following the installation instructions, but I'm stuck on the first step, which is to install JPype.

I'm using OS X 10.7 (lion). I think my configuration is pretty standard with Python 2.7.2 downloaded from the Python website and Java 1.6.0 downloaded from the Apple website.

When I run

% sudo python setup.py install

On the JPype installer, I get about a 100 lines of error code about various .h files, then it terminates with the lines:

lipo: can't figure out the architecture type of: /var/tmp//
ccwOzLi9.out

error: command 'gcc-4.2' failed with exit status 1

I found a blog post about a gcc error with JPype, but I followed the instructions there to no avail. I also emailed the author of that post, and he told me had never actually used JPype, had been working in OS X 10.6, and didn't have any insight.

I also emailed the creator of JPype, who told me that he only uses Windows, and has no idea how to make the install work on OS X. But if we can solve this, I can point him to the answer and maybe he can add the solution to the JPype documentation and help lots of other people as well!

So, anyone know what I'm doing wrong? I would like to use Neo4j, but I don't know Java so I'm at a complete loss for how to fix a compiler error.

Based on reading every Google result available, my two running theories are that:

  1. I'm somehow using a 32-bit version of Python or of Java (though I used standard official installations and can't figure out how to switch to 64-bit or if that's even possible)

  2. The JPype files can only be compiled using GCC 4.0 instead of 4.2. But I can't find anything online about how to rollback to GCC 4.0 (or if it comes shipped with 2011 MacBooks and there is some way to force JPype to compile with that instead).

There is another similar question, but the solution there is to use a different adapter that goes through REST instead of hooking directly into Java. I will try that if I have to, but I would really rather use the recommended Neo4j method if it's possible.

2
  • +1 for trying to solve the problem yourself first.
    – edwardw
    Dec 16, 2011 at 2:09
  • I created a fork on github with some of the proposed changes mentioned in this thread.
    – Luis Nell
    Jul 31, 2012 at 9:59

10 Answers 10

11

I'm not a Python guy, but tried installing JPype on my machine:

% uname -a
Darwin fatty-i7.local.tld 11.2.0 Darwin Kernel Version 11.2.0: Tue Aug  9 20:54:00 PDT 2011; root:xnu-1699.24.8~1/RELEASE_X86_64 x86_64
% java -version
java version "1.6.0_29"
Java(TM) SE Runtime Environment (build 1.6.0_29-b11-402-11M3527)
Java HotSpot(TM) 64-Bit Server VM (build 20.4-b02-402, mixed mode)

On OSX Lion, the latest JDK appears to be located here:

/Developer/SDKs/MacOSX10.7.sdk/System/Library/Frameworks/JavaVM.framework/

A little googling turned up this post: http://blog.y3xz.com/post/5037243230/installing-jpype-on-mac-os-x

I followed those instructions to modify setup.py, then ran sudo python setup.py install with no problems.

Does that help?

2
  • 2
    Woo! That solved it. I followed the blog post you cited, but I was using /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home as my java_home, which is what I got from running % /usr/libexec/java_home (which another blog post told me to do). I will email the JPype guy and ask him to add this to the documentation. Dec 15, 2011 at 22:17
  • In setup.py, you need to add self.jdkInclude = "darwin" and self.javaHome = '/Library/Java/JavaVirtualMachines/jdk1.8.0_121.jdk/Contents/Home'. Then run python setup.py install --user
    – Sandeep
    Jun 8, 2017 at 20:42
10

On my Lion, the "include" directory in the JDK was gone, so JPype couldn't find jni.h.

I updated setup.py in two places, one to set where to find jar libraries:

def setupMacOSX(self):
    self.javaHome = '/System/Library/Frameworks/JavaVM.framework'
    self.jdkInclude = ""
    self.libraries = ["dl"]
    self.libraryDir = [self.javaHome+"/Home/lib"]
    self.macros = [('MACOSX',1)]

And one to set where to find jni.h:

def setupInclusion(self):
    self.includeDirs = [
        self.javaHome+"/Headers",
        <other stuff>
0
4

For me,

self.javaHome = '/System/Library/Frameworks/JavaVM.framework/Versions/Current/'

worked.

$ uname -a Darwin  11.4.0 Darwin Kernel Version 11.4.0: Mon Apr 9 19:32:15 PDT 2012; root:xnu-1699.26.8~1/RELEASE_X86_64 x86_64 

$ java -version java version "1.6.0_33" Java(TM) SE Runtime Environment (build 1.6.0_33-b03-424-11M3720) Java HotSpot(TM) 64-Bit Server VM (build 20.8-b03-424, mixed mode)
0
2

Here are directions I put in my README to install JPype on OS X 10.7. Same idea as the answers here but different enough to warrant the submission.

The python interface to java (JPype) needs mods to the setup.py: In summary, you need to make sure the JPype setup.py script can see your Java SDK "Headers" and "Home" directory I had to install Java from Apple first since my default OS X installation did not come with Headers in the typical Java install path which I found by executing:

/usr/libexec/java_home

If you do happen to have a Headers dir, you probably do not need to reinstall Java and can set the path vars below based on your java HOME directory which is likely different from those in these directions

After I installed Java, I found the new installation in:

/Library/Java/JavaVirtualMachines/

My Home directory was:

/Library/Java/JavaVirtualMachines/1.6.0_37-b06-434.jdk/Contents/Home/

and my Header directory was:

/Library/Java/JavaVirtualMachines/1.6.0_37-b06-434.jdk/Contents/Headers/

1) The JPype script assumes that Headers is within the Home directory but it's not, so I changed the Home path var and created a new Content path var in the setup.py script - In setupMacOSX(self):

self.javaHome = '/Library/Java/JavaVirtualMachines/1.6.0_37-b06-434.jdk/Contents/Home/'
self.javaContents = '/Library/Java/JavaVirtualMachines/1.6.0_37-b06-434.jdk/Contents/'

2) In setupMacOSX(self), change self.libraryDir:

self.libraryDir = [self.javaContents + "/Libraries"]
  • Note that this step was mentioned as required but I did not have to do this for it to work so maybe try without it first

3) In setupInclusion, add paths to your "Home/include" dir and your "Headers" dir:

self.javaHome+"/include", 
self.javaContents + "/Headers",

4) Running the installation should now work:

sudo python setup.py install
2

For everyone who is still trying to install Jpype but has meanwhile updated Mac OS: Andreas Kolleger's answer just works fine, but with XCode 4.3 the path changed to /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.7.sdk/System/Library/Frameworks/JavaVM.framework/Versions/Current/

In ML it's MacOSX10.8.sdk. At least on my system. :)

1

For me, on Mountain Lion

self.javaHome = '/System/Library/Frameworks/JavaVM.framework/'

worked.

$uname -a
Darwin 12.0.0 Darwin Kernel Version 12.0.0: Sun Jun 24 23:00:16 PDT 2012; root:xnu-2050.7.9~1/RELEASE_X86_64 x86_64

$ java -version
java version "1.6.0_33"
Java(TM) SE Runtime Environment (build 1.6.0_33-b03-424-11M3720)
Java HotSpot(TM) 64-Bit Server VM (build 20.8-b03-424, mixed mode)
1

I did the same, but choosing

self.javaHome = '/Developer/SDKs/**MacOSX10.6.sdk**/System/Library/Frameworks/JavaVM.framework/Versions/CurrentJDK/'

instead

self.javaHome = '/Developer/SDKs/**MacOSX10.7.sdk**/System/Library/Frameworks/JavaVM.framework/Versions/CurrentJDK/'

realize that I use version 6 vs 7. With the 7 version I got the same errors that the beginning.

1
  • Yes, that's a good point. I should've mentioned the OS version, and have edited my answer to reflect that. The exact path will vary with your particular version of MacOSX and installed JDK.
    – akollegger
    Dec 20, 2011 at 18:26
0

To make Will's answer a bit more specific: I had to modify the setupInclusion(self) method by adding the directory path he suggested, ie, '/System/Library/Frameworks/JavaVM.framework/Headers' on Mountain Lion (java version 1.6). With that the installation of JPype succeeded (though gave a bunch of warnings...)

0

Here's what worked for me - recommend you put the first line in your profile.

export JAVA_HOME=$(/usr/libexec/java_home) cd $JAVA_HOME sudo ln -s include Headers sudo cp include/darwin/* include/ cd -

Note that instead of changing setup.py, I'm changing my JDK install. This has the advantage of fixing the issue for other projects.

-1

For those trying to install on Mountain Lion, I had to further edit the setup.py file to include the header files here:

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

1
  • Thank you for adding this information, but since it is not a direct answer, it would be more appropriate as a comment Sep 29, 2012 at 16:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.