Code Monkey home page Code Monkey logo

python-javabridge's Introduction

Travis CI Status


The javabridge Python package makes it easy to start a Java virtual machine (JVM) from Python and interact with it. Python code can interact with the JVM using a low-level API or a more convenient high-level API.

PyPI record: https://pypi.python.org/pypi/javabridge

Documentation: http://pythonhosted.org/javabridge/

GitHub repository: https://github.com/CellProfiler/python-javabridge

Report bugs here: https://github.com/CellProfiler/python-javabridge/issues

python-javabridge is licensed under the BSD license. See the accompanying file LICENSE for details.

Copyright (c) 2003-2009 Massachusetts Institute of Technology Copyright (c) 2009-2013 Broad Institute All rights reserved.

python-javabridge's People

Contributors

0x00b1 avatar altendky avatar cbarrick avatar cgohlke avatar dscho avatar emmenlau avatar jakirkham avatar jbcoe avatar jni avatar joelostblom avatar joshmoore avatar larandvit avatar leekamentsky avatar ljosa avatar mingwandroid avatar oleksandr-pavlyk avatar rhoerbe avatar sankarshant avatar stelfrich avatar tjb900 avatar yoda-vid avatar zacsimile avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

python-javabridge's Issues

Call Python from Java

Implement a JNI class that can execute a CPython script and can start the CPython interpreter from a Java process.

Installation from source on Windows

A naive user (= me) might clone the repository and type "python setup.py build" and expect things to work but alas they did not. I think it would be worthwhile to improve the setup script for Windows:

  • If the JDK isn't found, print an informative error message asking the user to install it and exit.
  • Determine the path to javac explicitly rather than assuming it is on the PATH.

I'll make some tentative fixes and then show to you before merging.

Installing javabridge in Ubuntu 12.04

I wrote a script to install javabridge using virtualenv

$VIRTUALENV virtual_environment
. virtual_environment/bin/activate

pip install cython
pip install --allow-all-external pyrex
pip install numpy
pip install nose

#install javabridge
python setup.py build_ext --inplace

cd demo
python demo_nogui.py
cd ..

deactivate

but when I run it I get the following error

+ cd demo
+ python demo_nogui.py
Traceback (most recent call last):
  File "demo_nogui.py", line 15, in <module>
    import javabridge
ImportError: No module named javabridge
Build step 'Execute shell' marked build as failure
Finished: FAILURE

you can see the full log here http://developers.compbio.cs.cmu.edu:8080/job/python-javabridge-glnx64/13/console

Have you experienced this problem before?

JVMNotFoundError NameError on pip install

While trying to pip install --upgrade from 1.03 to 1.0.9, I get the following error:

Traceback (most recent call last):
  File "<string>", line 17, in <module>
  File "c:\users\develo~1\appdata\local\temp\pip_build_Developer\javabridge\setup.py", line 238, in <module>
    ext_modules=ext_modules(),
  File "c:\users\develo~1\appdata\local\temp\pip_build_Developer\javabridge\setup.py", line 58, in ext_modules
    raise JVMNotFoundError()
NameError: global name 'JVMNotFoundError' is not defined

Default behavior for javabridge.start_vm()

I'm thinking it might make sense to let the user start the JVM by supplying no arguments to javabridge.start_vm(). In this case, you'd start the VM with just the -Djava.class.path argument and javabridge.JARS.

@ljosa let me know what you think.

Modify location of registry search for Java

While diagnosing why Tracer crashes on Win8 x64, I found that the search for Java in locate.py references the current Java version as 'SOFTWARE\JavaSoft\Java Runtime Environment'. This key doesn't seem to exist in Win8 x64 and the search fails. I think this may have been written for Win x86.

This page indicates that the proper location should be 'SOFTWARE\Wow6432Node\JavaSoft\Java Runtime Environment'. This exists in both Win7 and Win8 x64.

Mac OSX Can't run Java > 1.6 applications

On my Mac OSX v 10.9.4 system, I am unable to use javabridge with applications requiring Java version >= 7, getting the following error:

Exception in thread "Thread-2" java.lang.UnsupportedClassVersionError: net/maizegenetics/dna/WHICH_ALLELE : Unsupported major.minor version 51.0
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClassCond(ClassLoader.java:637)
at java.lang.ClassLoader.defineClass(ClassLoader.java:621)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:141)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:283)
at java.net.URLClassLoader.access$000(URLClassLoader.java:58)
at java.net.URLClassLoader$1.run(URLClassLoader.java:197)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)

I tried making libraries point to an updated JDK, but the issue seems to stem from the JNI and the JavaVM file, which I'm not sure how to (or if it's possible) to migrate above v. 6. Any suggestions?

Exception when calling JWrapper with variable arguments

The following code throws an exception in the constructor:

import javabridge
javabridge.start_vm()
args = ("foo", "bar")
javabridge.JClassWrapper("javax.swing.filechooser.FileNameExtensionFilter")("baz", *args)

C:\Python27\lib\site-packages\javabridge-1.0.7_41_g5ac4864-py2.7-win-amd64.egg\javabridge\wrappers.pyc in __call__(self, *args)
    281             if is_var_args:
    282                 pm1 = len(params)-1
--> 283                 args1 = args[:pm1] + [args[pm1:]]
    284             else:
    285                 args1 = args

TypeError: can only concatenate tuple (not "list") to tuple

Compiler failure on on python-javabridge installation

Hello there!

I have some problems with installing python-javabridge via pipe for Anaconda scientific python distribution.

When I execute (in $ANACONDA_HOME) the ./pip install javabridge, I get a long error stack centred around .pyx modules and the following concluding failure message:

Command /home/ank/Documents/Programming_common/anaconda/bin/python -c "import setuptools, tokenize;file='/tmp/pip_build_ank/javabridge/setup.py';exec(compile(getattr(tokenize, 'open', open)(file).read().replace('\r\n', '\n'), file, 'exec'))" install --record /tmp/pip-MCQyET-record/install-record.txt --single-version-externally-managed --compile failed with error code 1 in /tmp/pip_build_ank/javabridge
Traceback (most recent call last):
File "./pip", line 6, in
sys.exit(main())
File "/home/ank/Documents/Programming_common/anaconda/lib/python2.7/site-packages/pip/init.py", line 198, in main
return command.main(cmd_args)
File "/home/ank/Documents/Programming_common/anaconda/lib/python2.7/site-packages/pip/basecommand.py", line 161, in main
text = '\n'.join(complete_log)

mac_stop_run_loop doesn't work so well.

If you run javabridge.mac_enter_run_loop in your main thread and call javabridge.mac_stop_run_loop in a second thread, the second thread hangs and the run loop doesn't exit.

javabridge install - fatal error LNK1120: 2 unresolved externals

I'm trying to install javabridge but I'm running into the following error:

C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\BIN\link.exe /DLL /nologo /INCREMENTAL:NO "/LIBPATH:C:\Program Files\Java\jdk1.7.0_45\lib" /LIBPATH:C:
7\libs /LIBPATH:C:\Python27\PCbuild jvm.lib /EXPORT:init_javabridge build\temp.win32-2.7\Release\_javabridge.obj build\temp.win32-2.7\Release\_javabridge_nom
uild\temp.win32-2.7\Release\strtoull.obj /OUT:build\lib.win32-2.7\javabridge\_javabridge.pyd /IMPLIB:build\temp.win32-2.7\Release\_javabridge.lib /MANIFESTFI
\temp.win32-2.7\Release\_javabridge.pyd.manifest /MANIFEST

   Creating library build\temp.win32-2.7\Release\_javabridge.lib and object build\temp.win32-2.7\Release\_javabridge.exp

_javabridge.obj : warning LNK4217: locally defined symbol _StopVM imported in function ___pyx_pf_11_javabridge_5JB_VM_12destroy

_javabridge.obj : error LNK2019: unresolved external symbol __imp__JNI_GetDefaultJavaVMInitArgs@4 referenced in function ___pyx_pf_11_javabridge_12get_defaul
m_init_args

_javabridge.obj : error LNK2019: unresolved external symbol __imp__JNI_CreateJavaVM@12 referenced in function ___pyx_pf_11_javabridge_5JB_VM_2create

build\lib.win32-2.7\javabridge\_javabridge.pyd : fatal error LNK1120: 2 unresolved externals

error: command 'link.exe' failed with exit status 1120

Below is my system configuration:

  • python 2.7 (32-bit)
  • Visual Studio 2010 Premium Edition

I tried using the installation instructions documented at the following link:
http://pythonhosted.org//javabridge/installation.html

My deviation from the installation instructions was that I didn't install the the Windows SDK as my impression from the documentation was that the C/C++ compiler is what was really needed. I decided to use the one that visual studio already provides and ran the installation from the Visual Studio Command Prompt. I'm in an area that has VERY low bandwidth (I'm using dial-up FYI) and it will take me a very very long time to download the SDK, so I'd like to try and avoid it if possible.

Thanks in advance.

fail to start hello world on Ubuntu 13.04

Install with
sudo pip install javabridge

Run

import os
import javabridge

javabridge.start_vm(['-Djava.class.path=' + os.pathsep.join(javabridge.JARS)],
            run_headless=True)
try:
    print javabridge.run_script('java.lang.String.format("Hello, %s!", greetee);',
                                dict(greetee='world'))
finally:
    javabridge.kill_vm()

Get

Traceback (most recent call last):
    import javabridge
  File "/usr/local/lib/python2.7/dist-packages/javabridge/__init__.py", line 22, in <module>
    from .jutil import start_vm, kill_vm, activate_awt, deactivate_awt
  File "/usr/local/lib/python2.7/dist-packages/javabridge/jutil.py", line 122, in <module>
    import _javabridge
ImportError: No module named _javabridge

JWrapper with varargs throws exception

Use of JWrapper and JClassWrapper to call a varargs method results in an exception:

>>> import javabridge
>>> javabridge.start_vm()
>>> javabridge.JClassWrapper("java.lang.String").format("Hello, %s.", "world")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/imaging/analysis/CPCluster/CellProfiler-2.0/javabridge-bioformats-site-packages/javabridge/wrappers.py", line 187, in <lambda>
    fn = lambda naame=name: lambda *args: self.__call_static(naame, *args)
  File "/imaging/analysis/CPCluster/CellProfiler-2.0/javabridge-bioformats-site-packages/javabridge/wrappers.py", line 250, in __call_static
    args1 = args[:pm1] + [args[pm1:]]
TypeError: can only concatenate tuple (not "list") to tuple
>>> 

undefined symbol MacStartVM on linux

Hi,

After what looked like a successful installation on Linux 64-bit, this is the error trace I get when running the headless hello world example from the docs:

Traceback (most recent call last):
  File "f.py", line 2, in <module>
    import javabridge
  File "/home/andrei/.pyenv/versions/2.7.9/lib/python2.7/site-packages/javabridge-0.0.0-py2.7-linux-x86_64.egg/javabridge/__init__.py", line 28, in <module>
    from .jutil import start_vm, kill_vm, activate_awt, deactivate_awt
  File "/home/andrei/.pyenv/versions/2.7.9/lib/python2.7/site-packages/javabridge-0.0.0-py2.7-linux-x86_64.egg/javabridge/jutil.py", line 119, in <module>
    import _javabridge
ImportError: /home/andrei/.pyenv/versions/2.7.9/lib/python2.7/site-packages/javabridge-0.0.0-py2.7-linux-x86_64.egg/javabridge/_javabridge.so: undefined symbol: MacStartVM

Wrappers do not intelligently select a method where there are several possibilities with the same number of parameters.

I am trying to use this as a link to COMSOL. Unfortunately there are some methods ('set', most notably) with multiple overloaded methods that have the same number of parameters, but different types.

Right now, javabridge finds the first method with a matching number of parameters. It probably wouldn't be too difficult to search for an exact type match first.

It is possible to work around the problem by dropping down to the low-level interface and selecting the method manually, but this is rather complicated.

Thoughts?

Protect against thrown exceptions in deactivate_awt

The script, javabridge.jutil.CLOSE_ALL_WINDOWS should close each frame from within a try/catch block so that a first exception does not prevent subsequent windows from closing.

>>> import javabridge
>>> javabridge.start_vm(class_path=javabridge.JARS + ['imagej/jars/ij-1.49e.jar'])
>>> ij = javabridge.JClassWrapper('ij.IJ')
>>> image = ij.openImage('CellProfilerIcon.png')
>>> image.show()
>>> image.changes=False
>>> imagej = javabridge.JClassWrapper('ij.ImageJ')()
>>> javabridge.kill_vm()
Exception during disposal:
java.lang.reflect.InvocationTargetException
    at java.awt.EventQueue.invokeAndWait(EventQueue.java:1288)
    at java.awt.Window.doDispose(Window.java:1209)
    at java.awt.Window.dispose(Window.java:1147)
    at ij.ImageJ.run(ImageJ.java:775)
    at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.IllegalArgumentException: null source
    at java.util.EventObject.<init>(EventObject.java:56)
    at java.awt.AWTEvent.<init>(AWTEvent.java:337)
    at java.awt.event.InvocationEvent.<init>(InvocationEvent.java:285)
    at java.awt.event.InvocationEvent.<init>(InvocationEvent.java:174)
    at sun.awt.X11.XBaseMenuWindow.dispose(XBaseMenuWindow.java:907)
    at java.awt.MenuComponent.removeNotify(MenuComponent.java:310)
    at java.awt.Menu.removeNotify(Menu.java:198)
    at java.awt.Component.removeNotify(Component.java:6991)
    at java.awt.Container.removeNotify(Container.java:2800)
    at java.awt.Window.removeNotify(Window.java:782)
    at java.awt.Frame.removeNotify(Frame.java:1041)
    at java.awt.Window$1DisposeAction.run(Window.java:1190)
    at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:302)
    at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:745)
    at java.awt.EventQueue.access$300(EventQueue.java:103)
    at java.awt.EventQueue$3.run(EventQueue.java:706)
    at java.awt.EventQueue$3.run(EventQueue.java:704)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
    at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:87)
    at java.awt.EventQueue$4.run(EventQueue.java:720)
    at java.awt.EventQueue$4.run(EventQueue.java:718)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
    at java.awt.EventQueue.dispatchEvent(EventQueue.java:717)
    at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:242)
    at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:161)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:150)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:146)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:138)
    at java.awt.EventDispatchThread.run(EventDispatchThread.java:91)

BTW - the above is a result of the "fiji won't quit" bug which you can google for if interested.

Python objects and CPython.exec()

There are back-door ways to maintain Python objects across calls to CPython.exec() - for instance, importing main and then adding attributes to it. It would be nice, though, to have a simple, safe, uniform and reliable way of passing Python objects around in Java - a way to get a token for a Python object, retrieve the object using the token and otherwise manage its lifetime.

Build error

After a pip install javabridge when I import javabridge it quits the Python interactive shell after printing the error No Java runtime present, requesting install.

So I cloned this repo and built from source and got the following error.

TRSS-MacBook-Pro:python-javabridge trss$  python setup.py build
Using jdk_home = /Library/Java/JavaVirtualMachines/jdk1.7.0_65.jdk/Contents/Home
running build
running build_py
creating build
creating build/lib.macosx-10.8-x86_64-2.7
creating build/lib.macosx-10.8-x86_64-2.7/javabridge
copying javabridge/__init__.py -> build/lib.macosx-10.8-x86_64-2.7/javabridge
copying javabridge/_version.py -> build/lib.macosx-10.8-x86_64-2.7/javabridge
copying javabridge/jutil.py -> build/lib.macosx-10.8-x86_64-2.7/javabridge
copying javabridge/locate.py -> build/lib.macosx-10.8-x86_64-2.7/javabridge
copying javabridge/noseplugin.py -> build/lib.macosx-10.8-x86_64-2.7/javabridge
copying javabridge/wrappers.py -> build/lib.macosx-10.8-x86_64-2.7/javabridge
creating build/lib.macosx-10.8-x86_64-2.7/javabridge/jars
copying javabridge/jars/rhino-1.7R4.jar -> build/lib.macosx-10.8-x86_64-2.7/javabridge/jars
running build_ext
running build_java
javac java/org/cellprofiler/runnablequeue/RunnableQueue.java
jar cf javabridge/jars/runnablequeue.jar -C java org/cellprofiler/runnablequeue/RunnableQueue$1.class -C java org/cellprofiler/runnablequeue/RunnableQueue.class
javac java/org/cellprofiler/javabridge/test/RealRect.java
jar cf javabridge/jars/test.jar -C java org/cellprofiler/javabridge/test/RealRect.class
error: [Errno 2] No such file or directory

mutable default argument of args parameter to java.util.start_vm

The "args" parameter's default argument is set to an empty list. Since lists are mutable objects, mutations to the default argument list in one call of the method (such as by args.append) will be present in the subsequent calls to the method. Instead, make "None" the default argument perform a check within the method.

start_vm recommendations in the docs

Thanks very much for breaking this out as its own tool! I've begun using it to execute our Java simulations and may end up using it to integrate them with other simulation platforms.

The usage examples for start_vm() all use the VM arguments parameter like so:

javabridge.start_vm(['-Djava.class.path=' + os.pathsep.join(javabridge.JARS)],
            run_headless=True)

But setting the class path this way led to some strangeness that I failed to debug. By contrast, using the class_path parameter worked perfectly. e.g.:

javaclasspath = [os.path.realpath(os.path.join(os.path.dirname(__file__),'..','build','classes'))] + \
                [os.path.realpath(os.path.join(os.path.dirname(__file__),'..','cfg'))] + \
                [os.path.realpath(os.path.join(os.path.dirname(__file__),'..','lib', name + '.jar'))
                   for name in ['hamcrest-core-1.1', 'logback-core-0.9.28', 'slf4j-api-1.6.1']] + \
                javabridge.JARS

javabridge.start_vm(class_path=[os.pathsep.join(javaclasspath)], run_headless=True)

I don't know if this is only an issue for me or if others have experienced it. I couldn't find any other issues, forum posts, or cellprofiler-dev posts that treated it explicitly. I hope posting it here helps. If/when I learn more, I'll submit it.

Thanks again.
-glen

Visual Studio 2008 Dependancy

I am trying to install javabridge on my system but their is a dependency on Visual Studio 2008. I have on my system the newest version of Visual Studio 2013 installed. Is this not sufficient to install javabridge? I cannot find an old distribution of visual studio 2008 to get beyond this point.
Thanks for the help

set_static_field segfault

Steps to reproduce:

import javabridge
javabridge.start_vm()
javabridge.set-static_field("java/lang/Integer", "foo", "I", 5)

Jutil is missing a check for a field ID that does not exist.

gcc.exe: /MANIFEST: No such file or directory when installing on Windows 7.

Trying to install javabridge (and bioformats) on Windows 7.

Windows 7 64-bit SP1
JDK 1.7
Python 2.7.2 64-bit
pip 1.5.4

Here is the console output when trying to install javabridge:

C:\Windows\system32>pip install javabridge
Downloading/unpacking javabridge
  Running setup.py (path:c:\users\user~1.las\appdata\local\temp\pip_build_user\javabridge\setup.py) egg_info for package javabridge
    Using jdk_home = C:\Program Files\Java\jdk1.7.0_67

    no previously-included directories found matching '*.pyx'
Requirement already satisfied (use --upgrade to upgrade): numpy in c:\python27\lib\site-packages (from javabridge)
Installing collected packages: javabridge
  Running setup.py install for javabridge
    Using jdk_home = C:\Program Files\Java\jdk1.7.0_67
    building 'javabridge._javabridge' extension
    C:\Python27\Scripts\gcc.exe -mno-cygwin -mdll -O -Wall -DMS_WIN64 -IC:\Python27\lib\site-packages\numpy\core\include "-IC:\Program Files\Java\jdk1.7.0_67\in
clude" "-IC:\Program Files\Java\jdk1.7.0_67\include\win32" -IC:\Python27\include -IC:\Python27\PC -c _javabridge.c -o build\temp.win-amd64-2.7\Release\_javabrid
ge.o
    _javabridge.c: In function '__pyx_pf_11_javabridge_9JB_Object_2__repr__':
    _javabridge.c:3637:37: warning: cast from pointer to integer of different size
    _javabridge.c: In function '__pyx_pf_11_javabridge_9JB_Object_6addr':
    _javabridge.c:3882:37: warning: cast from pointer to integer of different size
    _javabridge.c: In function '__pyx_pf_11_javabridge_8JB_Class_2__repr__':
    _javabridge.c:4007:37: warning: cast from pointer to integer of different size
    _javabridge.c: In function '__pyx_pf_11_javabridge_13__JB_MethodID_2__repr__':
    _javabridge.c:4153:37: warning: cast from pointer to integer of different size
    _javabridge.c: In function '__pyx_pf_11_javabridge_12__JB_FieldID_2__repr__':
    _javabridge.c:4307:37: warning: cast from pointer to integer of different size
    _javabridge.c: In function '__pyx_pf_11_javabridge_6JB_Env_118get_string':
    _javabridge.c:17208:18: warning: cast from pointer to integer of different size
    _javabridge.c: In function '__pyx_pf_11_javabridge_6JB_Env_120get_string_utf':
    _javabridge.c:17336:18: warning: cast from pointer to integer of different size
    _javabridge.c: In function '__Pyx_RaiseArgtupleInvalid':
    _javabridge.c:25610:18: warning: unknown conversion type character 'z' in format
    _javabridge.c:25610:18: warning: format '%.1s' expects type 'char *', but argument 5 has type 'Py_ssize_t'
    _javabridge.c:25610:18: warning: unknown conversion type character 'z' in format
    _javabridge.c:25610:18: warning: too many arguments for format
    _javabridge.c: In function '__Pyx_RaiseTooManyValuesError':
    _javabridge.c:26394:18: warning: unknown conversion type character 'z' in format
    _javabridge.c:26394:18: warning: too many arguments for format
    _javabridge.c: In function '__Pyx_RaiseNeedMoreValuesError':
    _javabridge.c:26400:18: warning: unknown conversion type character 'z' in format
    _javabridge.c:26400:18: warning: format '%.1s' expects type 'char *', but argument 3 has type 'Py_ssize_t'
    _javabridge.c:26400:18: warning: too many arguments for format
    _javabridge.c: In function '__Pyx_BufFmt_ProcessTypeChunk':
    _javabridge.c:26690:26: warning: unknown conversion type character 'z' in format
    _javabridge.c:26690:26: warning: unknown conversion type character 'z' in format
    _javabridge.c:26690:26: warning: too many arguments for format
    _javabridge.c:26742:20: warning: unknown conversion type character 'z' in format
    _javabridge.c:26742:20: warning: unknown conversion type character 'z' in format
    _javabridge.c:26742:20: warning: too many arguments for format
    _javabridge.c: In function '__pyx_buffmt_parse_array':
    _javabridge.c:26802:25: warning: unknown conversion type character 'z' in format
    _javabridge.c:26802:25: warning: format '%d' expects type 'int', but argument 3 has type 'size_t'
    _javabridge.c:26802:25: warning: too many arguments for format
    _javabridge.c: In function '__Pyx_GetBufferAndValidate':
    _javabridge.c:26983:7: warning: unknown conversion type character 'z' in format
    _javabridge.c:26983:7: warning: format '%s' expects type 'char *', but argument 3 has type 'Py_ssize_t'
    _javabridge.c:26983:7: warning: unknown conversion type character 'z' in format
    _javabridge.c:26983:7: warning: too many arguments for format
    _javabridge.c: At top level:
    C:\Python27\lib\site-packages\numpy\core\include/numpy/__ufunc_api.h:226:1: warning: '_import_umath' defined but not used
    C:\Python27\Scripts\gcc.exe -mno-cygwin -mdll -O -Wall -DMS_WIN64 -IC:\Python27\lib\site-packages\numpy\core\include "-IC:\Program Files\Java\jdk1.7.0_67\in
clude" "-IC:\Program Files\Java\jdk1.7.0_67\include\win32" -IC:\Python27\include -IC:\Python27\PC -c _javabridge_nomac.c -o build\temp.win-amd64-2.7\Release\_ja
vabridge_nomac.o
    C:\Python27\Scripts\gcc.exe -mno-cygwin -mdll -O -Wall -DMS_WIN64 -IC:\Python27\lib\site-packages\numpy\core\include "-IC:\Program Files\Java\jdk1.7.0_67\in
clude" "-IC:\Program Files\Java\jdk1.7.0_67\include\win32" -IC:\Python27\include -IC:\Python27\PC -c strtoull.c -o build\temp.win-amd64-2.7\Release\strtoull.o
    C:\Python27\Scripts\gcc.exe -mno-cygwin -shared -s build\temp.win-amd64-2.7\Release\_javabridge.o build\temp.win-amd64-2.7\Release\_javabridge_nomac.o build
\temp.win-amd64-2.7\Release\strtoull.o build\temp.win-amd64-2.7\Release\_javabridge.def "-LC:\Program Files\Java\jdk1.7.0_67\lib" -LC:\Python27\libs -LC:\Python
27\PCbuild\amd64 -ljvm -lpython27 -lmsvcr90 -o build\lib.win-amd64-2.7\javabridge\_javabridge.pyd /MANIFEST
    gcc.exe: /MANIFEST: No such file or directory
    error: command 'gcc' failed with exit status 1
    Complete output from command C:\Python27\python.exe -c "import setuptools, tokenize;__file__='c:\\users\\user~1.las\\appdata\\local\\temp\\pip_build_user\
\javabridge\\setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record c:\users\user~
1.las\appdata\local\temp\pip-qucvet-record\install-record.txt --single-version-externally-managed --compile:
    Using jdk_home = C:\Program Files\Java\jdk1.7.0_67

running install

running build

running build_py

creating build

creating build\lib.win-amd64-2.7

creating build\lib.win-amd64-2.7\javabridge

copying javabridge\jutil.py -> build\lib.win-amd64-2.7\javabridge

copying javabridge\locate.py -> build\lib.win-amd64-2.7\javabridge

copying javabridge\noseplugin.py -> build\lib.win-amd64-2.7\javabridge

copying javabridge\wrappers.py -> build\lib.win-amd64-2.7\javabridge

copying javabridge\_version.py -> build\lib.win-amd64-2.7\javabridge

copying javabridge\__init__.py -> build\lib.win-amd64-2.7\javabridge

creating build\lib.win-amd64-2.7\javabridge\jars

copying javabridge\jars\rhino-1.7R4.jar -> build\lib.win-amd64-2.7\javabridge\jars

copying javabridge\jars\runnablequeue.jar -> build\lib.win-amd64-2.7\javabridge\jars

copying javabridge\jars\test.jar -> build\lib.win-amd64-2.7\javabridge\jars

running build_ext

running build_java

building 'javabridge._javabridge' extension

creating build\temp.win-amd64-2.7

creating build\temp.win-amd64-2.7\Release

C:\Python27\Scripts\gcc.exe -mno-cygwin -mdll -O -Wall -DMS_WIN64 -IC:\Python27\lib\site-packages\numpy\core\include "-IC:\Program Files\Java\jdk1.7.0_67\includ
e" "-IC:\Program Files\Java\jdk1.7.0_67\include\win32" -IC:\Python27\include -IC:\Python27\PC -c _javabridge.c -o build\temp.win-amd64-2.7\Release\_javabridge.o


_javabridge.c: In function '__pyx_pf_11_javabridge_9JB_Object_2__repr__':

_javabridge.c:3637:37: warning: cast from pointer to integer of different size

_javabridge.c: In function '__pyx_pf_11_javabridge_9JB_Object_6addr':

_javabridge.c:3882:37: warning: cast from pointer to integer of different size

_javabridge.c: In function '__pyx_pf_11_javabridge_8JB_Class_2__repr__':

_javabridge.c:4007:37: warning: cast from pointer to integer of different size

_javabridge.c: In function '__pyx_pf_11_javabridge_13__JB_MethodID_2__repr__':

_javabridge.c:4153:37: warning: cast from pointer to integer of different size

_javabridge.c: In function '__pyx_pf_11_javabridge_12__JB_FieldID_2__repr__':

_javabridge.c:4307:37: warning: cast from pointer to integer of different size

_javabridge.c: In function '__pyx_pf_11_javabridge_6JB_Env_118get_string':

_javabridge.c:17208:18: warning: cast from pointer to integer of different size

_javabridge.c: In function '__pyx_pf_11_javabridge_6JB_Env_120get_string_utf':

_javabridge.c:17336:18: warning: cast from pointer to integer of different size

_javabridge.c: In function '__Pyx_RaiseArgtupleInvalid':

_javabridge.c:25610:18: warning: unknown conversion type character 'z' in format

_javabridge.c:25610:18: warning: format '%.1s' expects type 'char *', but argument 5 has type 'Py_ssize_t'

_javabridge.c:25610:18: warning: unknown conversion type character 'z' in format

_javabridge.c:25610:18: warning: too many arguments for format

_javabridge.c: In function '__Pyx_RaiseTooManyValuesError':

_javabridge.c:26394:18: warning: unknown conversion type character 'z' in format

_javabridge.c:26394:18: warning: too many arguments for format

_javabridge.c: In function '__Pyx_RaiseNeedMoreValuesError':

_javabridge.c:26400:18: warning: unknown conversion type character 'z' in format

_javabridge.c:26400:18: warning: format '%.1s' expects type 'char *', but argument 3 has type 'Py_ssize_t'

_javabridge.c:26400:18: warning: too many arguments for format

_javabridge.c: In function '__Pyx_BufFmt_ProcessTypeChunk':

_javabridge.c:26690:26: warning: unknown conversion type character 'z' in format

_javabridge.c:26690:26: warning: unknown conversion type character 'z' in format

_javabridge.c:26690:26: warning: too many arguments for format

_javabridge.c:26742:20: warning: unknown conversion type character 'z' in format

_javabridge.c:26742:20: warning: unknown conversion type character 'z' in format

_javabridge.c:26742:20: warning: too many arguments for format

_javabridge.c: In function '__pyx_buffmt_parse_array':

_javabridge.c:26802:25: warning: unknown conversion type character 'z' in format

_javabridge.c:26802:25: warning: format '%d' expects type 'int', but argument 3 has type 'size_t'

_javabridge.c:26802:25: warning: too many arguments for format

_javabridge.c: In function '__Pyx_GetBufferAndValidate':

_javabridge.c:26983:7: warning: unknown conversion type character 'z' in format

_javabridge.c:26983:7: warning: format '%s' expects type 'char *', but argument 3 has type 'Py_ssize_t'

_javabridge.c:26983:7: warning: unknown conversion type character 'z' in format

_javabridge.c:26983:7: warning: too many arguments for format

_javabridge.c: At top level:

C:\Python27\lib\site-packages\numpy\core\include/numpy/__ufunc_api.h:226:1: warning: '_import_umath' defined but not used

C:\Python27\Scripts\gcc.exe -mno-cygwin -mdll -O -Wall -DMS_WIN64 -IC:\Python27\lib\site-packages\numpy\core\include "-IC:\Program Files\Java\jdk1.7.0_67\includ
e" "-IC:\Program Files\Java\jdk1.7.0_67\include\win32" -IC:\Python27\include -IC:\Python27\PC -c _javabridge_nomac.c -o build\temp.win-amd64-2.7\Release\_javabr
idge_nomac.o

C:\Python27\Scripts\gcc.exe -mno-cygwin -mdll -O -Wall -DMS_WIN64 -IC:\Python27\lib\site-packages\numpy\core\include "-IC:\Program Files\Java\jdk1.7.0_67\includ
e" "-IC:\Program Files\Java\jdk1.7.0_67\include\win32" -IC:\Python27\include -IC:\Python27\PC -c strtoull.c -o build\temp.win-amd64-2.7\Release\strtoull.o

writing build\temp.win-amd64-2.7\Release\_javabridge.def

C:\Python27\Scripts\gcc.exe -mno-cygwin -shared -s build\temp.win-amd64-2.7\Release\_javabridge.o build\temp.win-amd64-2.7\Release\_javabridge_nomac.o build\tem
p.win-amd64-2.7\Release\strtoull.o build\temp.win-amd64-2.7\Release\_javabridge.def "-LC:\Program Files\Java\jdk1.7.0_67\lib" -LC:\Python27\libs -LC:\Python27\P
Cbuild\amd64 -ljvm -lpython27 -lmsvcr90 -o build\lib.win-amd64-2.7\javabridge\_javabridge.pyd /MANIFEST

gcc.exe: /MANIFEST: No such file or directory

error: command 'gcc' failed with exit status 1

----------------------------------------
Cleaning up...
Command C:\Python27\python.exe -c "import setuptools, tokenize;__file__='c:\\users\\user~1.las\\appdata\\local\\temp\\pip_build_user\\javabridge\\setup.py';ex
ec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record c:\users\user~1.las\appdata\local\temp\
pip-qucvet-record\install-record.txt --single-version-externally-managed --compile failed with error code 1 in c:\users\user~1.las\appdata\local\temp\pip_build
_user\javabridge
Storing debug log for failure in C:\Users\user.company\pip\pip.log

C:\Windows\system32>

python3 support

Hi,

it seems javebridge doesnt support python3, at least it showed me a syntax error with an old style syntax while using it.

Given that python 2 isn't supported anymore (they're just accepting patches) you might consider the effort of migrating? I'd love to be able to use javabridge...

Maven support

CellProfiler uses Maven to assemble its many JAR dependencies. This is for quite a bit into the future, but, similar to CellProfiler, the Javabridge could collect the JAR files it needs and could do other tasks such as assemble its own dependencies using a Maven pom.xml file.

The plan would be to move some facilities we have in external_dependencies.py to python-javabridge and to create a pom.xml file for the Javabridge's dependencies.

Error to do with numpy

I am trying to install javabridge using my Anaconda distribution of Python (within Cygwin) by running:

cd javabridge-1.0.9
python setup.py install

However, I'm getting these errors.

Using jdk_home = C:\Program Files\Java\jdk1.7.0_11
running install
running bdist_egg
running egg_info
writing requirements to javabridge.egg-info\requires.txt
writing javabridge.egg-info\PKG-INFO
writing top-level names to javabridge.egg-info\top_level.txt
writing dependency_links to javabridge.egg-info\dependency_links.txt
writing entry points to javabridge.egg-info\entry_points.txt
reading manifest file 'javabridge.egg-info\SOURCES.txt'
reading manifest template 'MANIFEST.in'
no previously-included directories found matching '*.pyx'
writing manifest file 'javabridge.egg-info\SOURCES.txt'
installing library code to build\bdist.win-amd64\egg
running install_lib
running build_py
running build_ext
running build_java
building 'javabridge._javabridge' extension
C:\cygwin\bin\gcc.exe -DMS_WIN64 -mdll -O -Wall -IC:\Anaconda\lib\site-packages\numpy\core\include "-IC:\Program Files\Java\jdk1.7.0_11\include" "-IC:\Program Files\Java\jdk1.7.0_11\include\win32" -IC:\Anaconda\include -IC:\Anaconda\PC -c _javabridge.c -o build\temp.win-amd64-2.7\Release\_javabridge.o
In file included from C:\Anaconda\include/Python.h:58:0,
                 from _javabridge.c:16:
C:\Anaconda\include/pyport.h:171:33: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘Py_uintptr_t’
 typedef unsigned PY_LONG_LONG   Py_uintptr_t;
                                 ^
C:\Anaconda\include/pyport.h:172:1: error: unknown type name ‘__int64’
 typedef PY_LONG_LONG            Py_intptr_t;
 ^
In file included from C:\Anaconda\include/Python.h:86:0,
                 from _javabridge.c:16:
C:\Anaconda\include/intobject.h:46:35: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘PyInt_AsUnsignedLongLongMask’
 PyAPI_FUNC(unsigned PY_LONG_LONG) PyInt_AsUnsignedLongLongMask(PyObject *);
                                   ^
In file included from C:\Anaconda\include/Python.h:88:0,
                 from _javabridge.c:16:
C:\Anaconda\include/longobject.h:50:1: warning: parameter names (without types) in function declaration [enabled by default]
 PyAPI_FUNC(PyObject *) PyLong_FromLongLong(PY_LONG_LONG);
 ^
In file included from C:\Anaconda\include/Python.h:58:0,
                 from _javabridge.c:16:
C:\Anaconda\include/pyconfig.h:302:23: error: unknown type name ‘__int64’
 # define PY_LONG_LONG __int64
                       ^
C:\Anaconda\include/pyport.h:793:34: note: in definition of macro ‘PyAPI_FUNC’
 #       define PyAPI_FUNC(RTYPE) RTYPE
                                  ^
C:\Anaconda\include/longobject.h:52:12: note: in expansion of macro ‘PY_LONG_LONG’
 PyAPI_FUNC(PY_LONG_LONG) PyLong_AsLongLong(PyObject *);
            ^
In file included from C:\Anaconda\include/Python.h:88:0,
                 from _javabridge.c:16:
C:\Anaconda\include/longobject.h:53:35: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘PyLong_AsUnsignedLongLong’
 PyAPI_FUNC(unsigned PY_LONG_LONG) PyLong_AsUnsignedLongLong(PyObject *);
                                   ^
C:\Anaconda\include/longobject.h:54:35: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘PyLong_AsUnsignedLongLongMask’
 PyAPI_FUNC(unsigned PY_LONG_LONG) PyLong_AsUnsignedLongLongMask(PyObject *);
                                   ^
In file included from C:\Anaconda\include/Python.h:58:0,
                 from _javabridge.c:16:
C:\Anaconda\include/pyconfig.h:302:23: error: unknown type name ‘__int64’
 # define PY_LONG_LONG __int64
                       ^
C:\Anaconda\include/pyport.h:793:34: note: in definition of macro ‘PyAPI_FUNC’
 #       define PyAPI_FUNC(RTYPE) RTYPE
                                  ^
C:\Anaconda\include/longobject.h:55:12: note: in expansion of macro ‘PY_LONG_LONG’
 PyAPI_FUNC(PY_LONG_LONG) PyLong_AsLongLongAndOverflow(PyObject *, int *);
            ^
In file included from C:\Anaconda\lib\site-packages\numpy\core\include/numpy/ndarraytypes.h:4:0,
                 from C:\Anaconda\lib\site-packages\numpy\core\include/numpy/ndarrayobject.h:17,
                 from C:\Anaconda\lib\site-packages\numpy\core\include/numpy/arrayobject.h:4,
                 from _javabridge.c:340:
C:\Anaconda\lib\site-packages\numpy\core\include/numpy/npy_common.h:123:1: error: unknown type name ‘Py_uintptr_t’
 typedef Py_uintptr_t npy_uintp;
 ^
C:\Anaconda\lib\site-packages\numpy\core\include/numpy/npy_common.h:221:1: error: unknown type name ‘__int64’
 typedef PY_LONG_LONG npy_longlong;
 ^
C:\Anaconda\lib\site-packages\numpy\core\include/numpy/npy_common.h:222:31: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘npy_ulonglong’
 typedef unsigned PY_LONG_LONG npy_ulonglong;
                               ^
In file included from C:\Anaconda\lib\site-packages\numpy\core\include/numpy/ndarraytypes.h:4:0,
                 from C:\Anaconda\lib\site-packages\numpy\core\include/numpy/ndarrayobject.h:17,
                 from C:\Anaconda\lib\site-packages\numpy\core\include/numpy/arrayobject.h:4,
                 from _javabridge.c:340:
C:\Anaconda\lib\site-packages\numpy\core\include/numpy/npy_common.h:520:9: error: unknown type name ‘npy_ulonglong’
         typedef npy_ulonglong npy_uint64;
         ^
In file included from C:\Anaconda\lib\site-packages\numpy\core\include/numpy/ndarraytypes.h:1761:0,
                 from C:\Anaconda\lib\site-packages\numpy\core\include/numpy/ndarrayobject.h:17,
                 from C:\Anaconda\lib\site-packages\numpy\core\include/numpy/arrayobject.h:4,
                 from _javabridge.c:340:
C:\Anaconda\lib\site-packages\numpy\core\include/numpy/npy_1_7_deprecated_api.h:15:2: warning: #warning "Using deprecated NumPy API, disable it by " "#defining NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION" [-Wcpp]
 #warning "Using deprecated NumPy API, disable it by " \
  ^
In file included from _javabridge.c:341:0:
C:\Anaconda\lib\site-packages\numpy\core\include/numpy/ufuncobject.h:424:29: fatal error: numpy/fenv/fenv.h: No such file or directory
 #include "numpy/fenv/fenv.h"
                             ^
compilation terminated.
error: command 'C:\\cygwin\\bin\\gcc.exe' failed with exit status 1

Stared at it quite a while and I'm a bit stumped as to what the issue is. Any ideas?

Cheers

pip install javabridge failing (OSX 10.9)

Hi all,

I recently made a mistake and nuked my Anaconda environment, so I have to reinstall a few packages, including this one. I'm pretty sure my last install consisted precisely of pip install javabridge, but this time it's failing:

http://pastebin.com/9SYrPZf1

Here's the final error:

gcc -fno-strict-aliasing -I/Users/nuneziglesiasj/anaconda/envs/bioformats/include -arch x86_64 -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -I/Users/nuneziglesiasj/anaconda/envs/bioformats/lib/python2.7/site-packages/numpy/core/include -I/System/Library/Frameworks/JavaVM.framework/Headers -I/Users/nuneziglesiasj/anaconda/envs/bioformats/include/python2.7 -c mac_javabridge_utils.c -o build/temp.macosx-10.5-x86_64-2.7/mac_javabridge_utils.o

clang: error: no such file or directory: 'mac_javabridge_utils.c'

clang: error: no input files

error: command 'gcc' failed with exit status 1

Any ideas?

BSD or GPL license

I am a bit confused as to what the license for this code is

When looking at the license file ( https://github.com/CellProfiler/python-javabridge/blob/master/LICENSE ), it reads like a BSD license and the latest commit references BSD. However, these lines ( https://github.com/CellProfiler/python-javabridge/blob/master/LICENSE#L1-L2 ) suggest that some code may be under the GPL. Doing a quick search doesn't reveal anything in this project with "GPL" in it (other than those lines from the license). However, this statement is a bit disconcerting.

Is this actually BSD licensed in whole or is it not?

Cross-thread use of JB_Env

There are a couple of places in the code where the JB_Env of one thread is bound to a closure or, in the case of the destructor for JB_Object, saved in the object itself. If the JB_Env is used in another thread... bad things happen.

See CellProfiler/CellProfiler@91f157b

Can't access fields via JWrapper

The following does not work:

from javabridge import *
start_vm()
rr = JClassWrapper("org.cellprofiler.javabridge.test.RealRect")(1.5, 2.5, 3.5, 4.5)
print rr.x
kill_vm()

Add configuration for Java version to start_vm

You can choose the JNI version in the invocation API. That should be exposed through the start_vm interface and we might want to add logic to figure out which versions are available via another API. This would help on OS/X Yosemite where CellProfiler is asking the user to install JRE 6 when that is unnecessary.

OS X Java VM problems

I am trying to call Java method from a compiled Java class using Python code. I dont want to run "java" executable just to run my code this I find this library really promising. Im no expert on Java but my OS X dev machine has troubles finding libjvm.dylib.

My $JAVA_HOME is:

export JAVA_HOME=$(/usr/libexec/java_home)

My libjvm.dylib is located under $JAVA_HOME/../Libraries/libjvm.dylib:

$ find $JAVA_HOME/.. -iname "libjvm.dylib" 
/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home/../Libraries/libjvm.dylib

My Java is the default one shipped with OS X 10.10:

$ java -version
java version "1.6.0_65"
Java(TM) SE Runtime Environment (build 1.6.0_65-b14-466.1-11M4716)
Java HotSpot(TM) 64-Bit Server VM (build 20.65-b04-466.1, mixed mode)

But javabridge library does some nasty things to find libjvm.dylib. See https://github.com/CellProfiler/python-javabridge/blob/master/javabridge/jutil.py#L98-L113. I think this piece of code is just wrong. My point is there could be a better way to deal with libjni.dylib location.

Since I am not expert on Java, and I have basically zero knowledge about coding Java and JNI and java libs I think better approach is to try some "known paths" for different Java vendors. AFAIK there is only Oracle Java available at this moment.

After reading Java docs and materials on the internet (and examining my own system) it looks like there are two possible places where libjvm.dylib could be located:

  1. $JAVA_HOME/../Libraries
  2. $JAVA_HOME/jre/lib

My installation has only (1) option valid, and the second path is non existing.

Right now I can suggest to use (2) by default (most of sources on the internet suggests this), and maybe check if your Java on your OS X does the same as (1).

Could you replicate this issue?

Thanks!

fatal error: jni.h: No such file or directory

Hello,

The install of javabridge-1.0.7 via pip fails. Done on Archlinux x86_64.
Seems like an issue with the version of numpy being incompatible.

gcc -pthread -fno-strict-aliasing -march=x86-64 -mtune=generic -O2 -pipe -fstack-protector --param=ssp-buffer-size=4 -DNDEBUG -march=x86-64 -mtune=generic -O2 -pipe -fstack-protector --param=ssp-buffer-size=4 -fPIC -I/usr/lib/python2.7/site-packages/numpy/core/include -I/usr/lib/jvm/java-7-openjdk/include -I/usr/lib/jvm/java-7-openjdk/include/linux -I/usr/include/python2.7 -c _javabridge.c -o build/temp.linux-x86_64-2.7/_javabridge.o

In file included from /usr/lib/python2.7/site-packages/numpy/core/include/numpy/ndarraytypes.h:1761:0,
                 from /usr/lib/python2.7/site-packages/numpy/core/include/numpy/ndarrayobject.h:17,
                 from /usr/lib/python2.7/site-packages/numpy/core/include/numpy/arrayobject.h:4,
                 from _javabridge.c:346:

/usr/lib/python2.7/site-packages/numpy/core/include/numpy/npy_1_7_deprecated_api.h:15:2: warning: #warning "Using deprecated NumPy API, disable it by " "#defining NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION" [-Wcpp]

 #warning "Using deprecated NumPy API, disable it by " \
  ^

_javabridge.c:348:17: fatal error: jni.h: No such file or directory

 #include "jni.h"
                 ^

compilation terminated.

error: command 'gcc' failed with exit status 1

Thanks

Defalt class path override -Djava.class.path=…

If you start the VM with

javabridge.start_vm(['-Djava.class.path=something'])

then start_vm discovers that you haven't used the class_path keyword argument and appends another -Djava.class.path argument based on the contents of javabridge.JARS. This second argument overrides the first one, so you don't get the class path you thought you defined with -Djava.class.path.

I'm think this is a bug. Do you agree, @LeeKamentsky?

A possible ways to fix: append an argument if you specify the class path using the class_path keyword argument, but prepend an argument if you don't. That way, your args will override your default class path, but your class_path keyword argument will override your args.

The alternative is to poke inside args and try to append class_path to what is already in the args. That seems messy. It seems more intuitive to have class_path override args, since that's how Java interprets the -D declarations in args in the first place.

Running nosetests

I followed the instructions on http://pythonhosted.org/javabridge/ to install and test javabridge

I wrote the script

$VIRTUALENV virtual_environment
. virtual_environment/bin/activate

pip install cython

pip install --allow-all-external pyrex
pip install numpy
pip install nose

python setup.py build_ext --inplace
python nosetests.py

deactivate

and I use the same script on MacOSX and Ubuntu. For some reason it works on MacOSX but fails two tests in Ubuntu

======================================================================
ERROR: test_09_01_get_field (javabridge.tests.test_jutil.TestJutil)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/usr0/home/jenkins/workspace/python-javabridge-glnx64/javabridge/tests/test_jutil.py", line 511, in test_09_01_get_field
    o = javabridge.make_instance("org/cellprofiler/javabridge/test/RealRect", "(DDDD)V", 1, 2, 3, 4)
  File "/usr0/home/jenkins/workspace/python-javabridge-glnx64/javabridge/jutil.py", line 1694, in make_instance
    raise JavaException(jexception)
JavaException: org/cellprofiler/javabridge/test/RealRect : Unsupported major.minor version 51.0

======================================================================
ERROR: test_09_02_set_field (javabridge.tests.test_jutil.TestJutil)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/usr0/home/jenkins/workspace/python-javabridge-glnx64/javabridge/tests/test_jutil.py", line 515, in test_09_02_set_field
    o = javabridge.make_instance("org/cellprofiler/javabridge/test/RealRect", "(DDDD)V", 1, 2, 3, 4)
  File "/usr0/home/jenkins/workspace/python-javabridge-glnx64/javabridge/jutil.py", line 1694, in make_instance
    raise JavaException(jexception)
JavaException: org/cellprofiler/javabridge/test/RealRect : Unsupported major.minor version 51.0

----------------------------------------------------------------------
Ran 125 tests in 0.496s

FAILED (errors=2)
Failed to get class org/cellprofiler/javabridge/test/RealRect
Failed to get class org/cellprofiler/javabridge/test/RealRect
Build step 'Execute shell' marked build as failure
Finished: FAILURE

You can check the full logs here
http://developers.compbio.cs.cmu.edu:8080/job/python-javabridge-macosx/
http://developers.compbio.cs.cmu.edu:8080/job/python-javabridge-glnx64/

Fatal error using JVM in Celery thread with NLTK on Mac OS X

Hello,

I am using the Python wrapper for Weka which is based on javabridge. I have a long task to perform and, therefore, I am using Celery to do so. The problem is that I get

# A fatal error has been detected by the Java Runtime Environment:
#
#  SIGSEGV (0xb) at pc=0x00007fff91a3c16f, pid=11698, tid=3587
#
# JRE version:  (8.0_31-b13) (build )
# Java VM: Java HotSpot(TM) 64-Bit Server VM (25.31-b07 mixed mode bsd-amd64 compressed oops)
# Problematic frame:
# C  [libdispatch.dylib+0x616f]  _dispatch_async_f_slow+0x18b
#
# Failed to write core dump. Core dumps have been disabled. To enable core dumping, try "ulimit -c unlimited" before starting Java again
#
# If you would like to submit a bug report, please visit:
#   http://bugreport.java.com/bugreport/crash.jsp
# The crash happened outside the Java Virtual Machine in native code.
# See problematic frame for where to report the bug.

when starting the JVM inside the thread. These two lines of code are used in order to do so (from weka.core.jvm):

javabridge.start_vm(run_headless=True)
javabridge.attach()

From what I've read, it is probably caused by the fact that the JVM is not attached to the Celery thread. However, javabridge.attach() is indeed run inside it.

What am I missing ?

Question also asked on Stack Overflow.

Add JRE requirement to documentation

Just ran into an error on Windows:

ERROR:javabridge.locate:Failed to find registry entry: SOFTWARE\JavaSoft\Java Runtime Environment
Traceback (most recent call last):
  File "C:\Python27\lib\site-packages\javabridge-1.0.3-py2.7-win-amd64.egg\javabridge\locate.py", line 64, in find_javahome
    kjava = _winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE, java_key_path)
WindowsError: [Error 2] The system cannot find the file specified

This was on a VM that didn't have JRE installed, only the JDK. The docs at http://pythonhosted.org//javabridge/installation.html didn't mention that JRE was needed.

Signature on method with inner enum argument

I'd like to use javabridge to call a method that takes as an argument an enum that is declared within the scope of an interface:

Example:

public interface MyInterface {
    public static enum INNER_ENUM {
        INNER_ENUM(int index) {
            myindex=index;
        }
    };
    public int callFunction(INNER_ENUM val);
}

I'd like to know how to make the signature for the function type. I've tried Lpath/to/MyInterface/INNER_ENUM; and Lpath/to/MyInterace$INNER_ENUM; without success.

Thanks for your help and work on this project!

Can't pass unicode options to start_vm

If you have a path name to a JAR that is not ascii, for instance, calling start_vm with that unicode text results in the following stack trace:

Traceback (most recent call last):
  File "c:\users\leek\cpdev\python-javabridge\python-javabridge\javabridge\jutil.py", line 226, in start_thread
    env = vm.create(args)
  File "_javabridge.pyx", line 586, in _javabridge.JB_VM.create (_javabridge.c:5582)
    options = [str(option) for option in options]
UnicodeEncodeError: 'ascii' codec can't encode character u'\u2211' in position 8889: ordinal not in range(128)
Failed to create Java VM

Suppressing JavaExceptions

For a project, I want to list all methods of a JWrapped object that do not throw an error. I do this as follows:

for name, method in JWrapped_object.methods.iteritems():
    try:
        fn = getattr(JWrapped_object, name)
        field = fn(*args)
        # some action here if java didn't throw an error
    except javabridge.JavaException:
        pass

This works nicely, except for the fact that in commandline there is a lot of JavaExceptions printed. I can't figure out how to suppress this printing. I tried to set the java log level to OFF like this (similar to bioformats.init_logger()):

javabridge.start_vm()
javabridge.static_call("org/apache/log4j/BasicConfigurator",
                       "configure", "()V")
log4j_logger = javabridge.static_call("org/apache/log4j/Logger",
                                  "getRootLogger",
                                  "()Lorg/apache/log4j/Logger;")
warn_level = javabridge.get_static_field("org/apache/log4j/Level", 'OFF',
                                     "Lorg/apache/log4j/Level;")
javabridge.call(log4j_logger, "setLevel", "(Lorg/apache/log4j/Level;)V",
            warn_level)

With no effect. Also I tried to redirect the stdout and stderr, also with no effect. Does anybody know how to suppress these errors?

Messy logging during instantiation of JClassWrapper

Instantiating a JClassWrapper spews some disturbing log information:

>>> a = J.JClassWrapper("java.util.ArrayList")()
Exception in thread "Thread-0" java.lang.NoSuchFieldException: static_methods
        at java.lang.Class.getField(Unknown Source)
Exception in thread "Thread-0" java.lang.NoSuchFieldException: methods
        at java.lang.Class.getField(Unknown Source)

The problem is that get_attr is called to find out if self.static_methods exists and that makes its way down into Java asking "is there a field named "static_methods"?". So get_attr needs to throw its AttributeError semi-silently when asked to fetch "static_methods" and "methods".

Otherwise, this is just a cosmetic issue - everything works fine.

Installing javabridge fails with gcc error while gcc is available

As you can see I have gcc available. I have gcc44 & created alias in ~/.bashrc to point to gcc44 & gcc -v works but I get this error. Please help.
$ $HOME/Enthought/Canopy_64bit/User/bin/python2.7 setup.py install
running install
running bdist_egg
running egg_info
writing requirements to javabridge.egg-info/requires.txt
writing javabridge.egg-info/PKG-INFO
writing top-level names to javabridge.egg-info/top_level.txt
writing dependency_links to javabridge.egg-info/dependency_links.txt
writing entry points to javabridge.egg-info/entry_points.txt
reading manifest file 'javabridge.egg-info/SOURCES.txt'
reading manifest template 'MANIFEST.in'
no previously-included directories found matching '*.pyx'
writing manifest file 'javabridge.egg-info/SOURCES.txt'
installing library code to build/bdist.linux-x86_64/egg
running install_lib
running build_py
running build_ext
javac -source 6 -target 6 java/org/cellprofiler/runnablequeue/RunnableQueue.java
javac -source 6 -target 6 java/org/cellprofiler/javabridge/test/RealRect.java
javac -source 6 -target 6 java/org/cellprofiler/javabridge/CPython.java java/org/cellprofiler/javabridge/CPythonInvocationHandler.java
Note: java/org/cellprofiler/javabridge/CPythonInvocationHandler.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
building 'javabridge._javabridge' extension
gcc -pthread -fno-strict-aliasing -DNDEBUG -g -O2 -fPIC -I/home/sysnyqcestg/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/numpy/core/include -I/usr/java/include -I/usr/java/include/linux -I/home/sysnyqcestg/Canopy/appdata/canopy-1.5.1.2730.rh5-x86_64/include/python2.7 -c _javabridge.c -o build/temp.linux-x86_64-2.7/_javabridge.o
unable to execute gcc: No such file or directory
error: command 'gcc' failed with exit status 1
$ gcc -v
Using built-in specs.
Target: x86_64-redhat-linux6E
Configured with: ../configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=http://bugzilla.redhat.com/bugzilla --enable-bootstrap --enable-shared --enable-threads=posix --enable-checking=release --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --disable-gnu-unique-object --with-as=/usr/libexec/binutils220/as --enable-languages=c,c++,fortran --disable-libgcj --with-mpfr=/builddir/build/BUILD/gcc-4.4.7-20120601/obj-x86_64-redhat-linux6E/mpfr-install/ --with-ppl=/builddir/build/BUILD/gcc-4.4.7-20120601/obj-x86_64-redhat-linux6E/ppl-install --with-cloog=/builddir/build/BUILD/gcc-4.4.7-20120601/obj-x86_64-redhat-linux6E/cloog-install --with-tune=generic --with-arch_32=i586 --build=x86_64-redhat-linux6E
Thread model: posix
gcc version 4.4.7 20120313 (Red Hat 4.4.7-11) (GCC)
$

Segfault calling iterate_java on non-iterator

Steps to reproduce:

import javabridge
javabridge.start_vm()
list(javabridge.iterate_java(javabridge.make_list(range(10)).o))

Haven't checked, but I think it crashes here:
https://github.com/CellProfiler/python-javabridge/blob/master/javabridge/jutil.py#L1622

The rules are that it's ok for low-level calls to segfault because of precondition violations, but high-level ones should have enough checking to prevent that.

Java reports:
#
# A fatal error has been detected by the Java Runtime Environment:
#
# Internal Error (klass.cpp:109), pid=1604, tid=6708
# Error: ShouldNotReachHere()
#

JavaNotFoundException not found

Accidentally ran install of CPA Tracer without Java installed first and got the following error:

Traceback (most recent call last):
  File "CellProfiler-Analyst.py", line 7, in <module>
  File "javabridge\__init__.pyc", line 28, in <module>
    ☻!♦♥☺;♥"☻∟♦▬♦F♣"☺▬☻►♥L♠(♣"♣∟☻∟
  File "javabridge\jutil.pyc", line 115, in <module>

  File "javabridge\jutil.pyc", line 107, in _find_jvm
    s▲
NameError: global name 'JavaNotFoundException' is not defined

Should it be JVMNotFoundError?

Cannot pass 2D array as argument

I'm trying to pass a 2D double array object (already a javabridge.JB_OBJECT) to a wrapped function, and I'm getting the following:

method_id
<Java method with sig=([[DLnet/maizegenetics/taxa/TaxaList;)V at 0x1e629f0>

javabridge.get_env().new_object(obj_class,method_id,primative_mat.o,taxa_list.o)
Traceback (most recent call last):
File "", line 1, in
File "_javabridge.pyx", line 1416, in _javabridge.JB_Env.new_object (_javabridge.c:14706)
File "_javabridge.pyx", line 451, in _javabridge.fill_values (_javabridge.c:3567)
TypeError: float() argument must be a string or a number

Upon inspection, the troublesome code appears to be around line 465 of javabridge._javabridge.pyx. There appears to be an assumption that all are 1D in the fill_values function. This leads it to try and find a single double instance where there shouldn't be one.

Unable to specify new directory in classpath using class_path & unable to add -Xdebug as an arg.

Hi,

I have tried to add a directory using class_path either passing path or using os.path.
javabridge.start_vm(class_path=[os.path.realpath(os.path.join(os.path.dirname(file),'misc','jars'))], run_headless=True)
subsequent print javabridge.JARS is not showing the directory added.
How can I add a directory using class_path while starting jvm?

How can I also run the script in jvm DEBUG mode (-Xdebug)?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.