setting CLASSPATH in Python?

9,214 views
Skip to first unread message

Matt Dorn

unread,
May 15, 2013, 12:47:48 PM5/15/13
to pyjni...@googlegroups.com
Hi all,

I have a Python script that looks like this:

import os

from jnius import autoclass

javapath = ".:/path/to/jar_files/*"
os.environ['CLASSPATH'] = javapath
print 'CLASSPATH: ', os.environ['CLASSPATH']

adb = autoclass('com.android.ddmlib.AndroidDebugBridge')
print 'adb obj: ', adb

When I run it, it fails like so:

user@host:$ python foo.py 
CLASSPATH:  .:/path/to/jar_files/*
Traceback (most recent call last):
  File "bin/python", line 33, in <module>
    execfile(__file__)
  File "ve_android/bar.py", line 9, in <module>
    adb = autoclass('com.android.ddmlib.AndroidDebugBridge')
  File "/usr/local/lib/python2.7/dist-packages/jnius/reflect.py", line 109, in autoclass
    c = find_javaclass(clsname)
  File "jnius_export_func.pxi", line 23, in jnius.find_javaclass (jnius/jnius.c:7134)
jnius.JavaException: Class not found 'com/android/ddmlib/AndroidDebugBridge'

But if I set CLASSPATH manually in the shell, and then run it, it works:

user@host:$ export CLASSPATH=".:/path/to/jar_files/*"
user@host:$ python foo.py 
CLASSPATH:  .:/path/to/jar_files/*
adb obj:  <class 'jnius.reflect.com.android.ddmlib.AndroidDebugBridge'>

I would have expected my Python os.environ manipulations to have the same effect as exporting the env var in the shell, but no such luck.  Any ideas?

Thanks,

Matt

Mathieu Virbel

unread,
May 15, 2013, 12:49:51 PM5/15/13
to pyjni...@googlegroups.com
I think you need to do it _before_ importing jnius.
Once it's imported, the java internal is already imported, so it's over.

Did you try to push the os.environ before the import ?

Mathieu

Le 15/05/2013 18:47, Matt Dorn a �crit :
> --
> You received this message because you are subscribed to the Google
> Groups "PyJNIus development ML" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to pyjnius-dev...@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>

Matt Dorn

unread,
May 15, 2013, 1:00:44 PM5/15/13
to pyjni...@googlegroups.com
Thank you Mathieu for the lightning-quick response -- that worked! 


On Wednesday, May 15, 2013 11:49:51 AM UTC-5, Mathieu Virbel wrote:
I think you need to do it _before_ importing jnius.
Once it's imported, the java internal is already imported, so it's over.

Did you try to push the os.environ before the import ?

Mathieu

Le 15/05/2013 18:47, Matt Dorn a �crit :
Reply all
Reply to author
Forward
0 new messages