Exception: No module named _md5

Help
2010-02-24
2013-05-14
  • Claudio Romo
    Claudio Romo
    2010-02-24

    First of all, Mike, let me congratulate you for your great work on this project. Jep has been very helpful for me and for my projects, specially because I don't know much about Python (but I'm good on Java :-) ) and it was easy putting into operation the communication between Java and a couple of API's in Python. So far so good, but now I'm facing a problem that has me crazy, let me explain you:
    I'm trying to call an script inside my project, this script when try to import md5 module thows this exception:

    2010-02-23 01:23:26,567   jep.JepException: <type 'exceptions.ImportError'>: No module named _md5
    java.lang.Exception: jep.JepException: jep.JepException: <type 'exceptions.ImportError'>: No module named _md5
    at controlpanel.log.LogManager.log(LogManager.java:28)
    at controlpanel.pythoninvoker.AbstractAPI.getJep(AbstractAPI.java:42)
    at controlpanel.pythoninvoker.MotoresAPI.motor_free(MotoresAPI.java:48)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at controlpanel.util.ControlPanelUtils.callMethod(ControlPanelUtils.java:114)
    at controlpanel.gui.components.MotorManager.checkMotor(MotorManager.java:158)
    at controlpanel.gui.components.MotorManager.access$000(MotorManager.java:34)
    at controlpanel.gui.components.MotorManager$1.actionPerformed(MotorManager.java:77)
    at javax.swing.Timer.fireActionPerformed(Timer.java:271)
    at javax.swing.Timer$DoPostEvent.run(Timer.java:201)
    at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:209)
    at java.awt.EventQueue.dispatchEvent(EventQueue.java:597)
    at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)
    at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
    at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)
    Caused by: jep.JepException: jep.JepException: <type 'exceptions.ImportError'>: No module named _md5
    at jep.Jep.eval(Jep.java:294)
    at controlpanel.pythoninvoker.AbstractAPI.getJep(AbstractAPI.java:38)
    … 19 more
    Caused by: jep.JepException: <type 'exceptions.ImportError'>: No module named _md5
    at jep.Jep.eval(Native Method)
    at jep.Jep.eval(Jep.java:278)
    … 20 more

    And the stdout show this:
       __main__:1: DeprecationWarning: the md5 module is deprecated; use hashlib instead

    When I try jep.eval("import md5") throws the same exception, and the same happens using jep.eval("import hashlib"), but when I import another module no exception is thrown!! i.e jep.eval("import copy") or jep.eval("import audiodev"). md5 and hashlib are in my Python instalation directory. Even when I use sys.path I get the exception:

    boolean out = jep.eval("import sys;sys.path.append('/usr/lib/python2.6/');sys.argv=");  // out gets true after this.

    I don't know what direction to take, I googled for a week searching for this error or similar without succeses on finding something to help me solve the problem, so I decided to try here, so perhaps together we can find a solution to my problem.

    Regards,
    Claudio.

     
  • Mike Johnson
    Mike Johnson
    2010-02-24

    Hi,

    Please, answer a couple questions to help me out first:

    What version are you using?

    Are you enabling the old import behavior?

    What platform? (The Unix version can act differently when using native modules.)

    Thanks
    Mike

     
  • Claudio Romo
    Claudio Romo
    2010-02-24

    Wow! That was fast!

    Regarding your questions:

    What version are you using? jep-2.4

    Are you enabling the old import behavior? nope, I saw in some posts here, but I though that

    What platform? Ubuntu Linux 64 bits

    Regards,
    Claudio.

     
  • Mike Johnson
    Mike Johnson
    2010-02-24

    Heh, I get push email on my Android.

    Well, I'm not sure then. Did you set LD_PRELOAD?

    That can also sometimes be caused by running Jep linked to a wrong Python install, but that's rare. But for whatever reason, it's not finding the library.

     
  • Claudio Romo
    Claudio Romo
    2010-02-24

    Now I tried putting LD_PRELOAD on my environment vars, pointing to ldd .libs/libjep.so.2.0.1 out, but still without success. As I told you before, this only happens with md5 and hashlib, so it's very strange because the other libraries are well imported. Could you tell how can I enable the old import behavior, please?

    Regards.

     
  • Mike Johnson
    Mike Johnson
    2010-02-24

    I don't think enabling the old import will help you, this is probably an artifact caused by updating. But you can check the release announcement here:

    http://www.publicstatic.net/2010/01/jepp-2-4-released/

    Anyway, LD_PRELOAD needs to be set to the Python library, not Jep. Your ld path must be okay because it found the jep.so library already (so don't worry about that).

    For example, on my system:
    $ ldd src/jep/.libs/libjep.so | grep python
    libpython2.6.so.1.0 => /usr/lib/libpython2.6.so.1.0 (0x00007f37dce66000)
    $ java -jar jep.jar console.py
    >>> import md5
    __main__:1: DeprecationWarning: the md5 module is deprecated; use hashlib instead
    >>> dir(md5)

    Now, with the old import function:

    $ java -jar jep.jar console.py
    >>> from jep import *
    >>> __builtins__.__import__ = jep.jimport
    >>> import md5
    Traceback (most recent call last):
      File "console.py", line 48, in prompt
        ran = jep.eval(line)
    JepException: jep.JepException: jep.JepException: <type 'exceptions.ImportError'>: jep.JepException: Package not found: md5

    Doh. :-)

    That's why I disabled it by default, it sometimes broke native modules. You should see this if it's disabled (you want that):

    $ grep USE_IMPORT config.h
    /* #undef USE_IMPORT */

     
  • Mike Johnson
    Mike Johnson
    2010-02-24

    Sorry, let me try that again:

    Now, with the old import function:
    $ java -jar jep.jar console.py

    >>> from jep import *
    >>> __builtins__.__import__ = jep.jimport
    >>> import md5
    Traceback (most recent call last):
      File "console.py", line 48, in prompt
        ran = jep.eval(line)
    JepException: jep.JepException: jep.JepException: <type 'exceptions.ImportError'>: jep.JepException: Package not found: md5
    >>>
    

    Doh. :-) That's why I disabled it by default, it sometimes broke native modules. You should see this if it's disabled (you want that):

    $ grep USE_IMPORT config.h
     /* #undef USE_IMPORT */
    
     
  • Claudio Romo
    Claudio Romo
    2010-02-24

    This is not my day :p

    When I use java -jar jep.jar console.py I get java.lang.UnsatisfiedLinkError: no jep in java.library.path
    but if I remove console.py the jep.jar is found!

    So, I can't test on console, but I'll try on my application using  from jep import * < blah > with the config.h edited :)

     
  • Mike Johnson
    Mike Johnson
    2010-02-24

    For testing at the console with your compiled version, you can do this from the top-level jep source directory:

    $ export LD_LIBRARY_PATH=`pwd`/src/jep/.libs/
    mrjohnson@imac:~/projects/jepp/trunk/jep$
    
     
  • Claudio Romo
    Claudio Romo
    2010-02-24

    Well my friend.. now I get the same result as you:

    hans@barracuda:~/Escritorio/jep-2.4$ export LD_LIBRARY_PATH=`pwd`/src/jep/.libs/
    hans@barracuda:~/Escritorio/jep-2.4$ java -jar jep.jar console.py

        No readline available.
        You may want to set the LD_PRELOAD environment variable, see the
        README file for details.

        i.e.: export LD_PRELOAD=/usr/lib/libpython2.3.so.1.0

        If your platform really doesn't have readline, try this:
        http://newcenturycomputers.net/projects/readline.html
    >>> from jep import *
    >>> __builtins__.__import__ = jep.jimport
    >>> import md5
    Traceback (most recent call last):
      File "console.py", line 48, in prompt
        ran = jep.eval(line)
    JepException: jep.JepException: jep.JepException: <type 'exceptions.ImportError'>: jep.JepException: Package not found: md5
    >>>

     
  • Mike Johnson
    Mike Johnson
    2010-02-24

    That's weird. What's LD_PRELOAD set to?

     
  • Claudio Romo
    Claudio Romo
    2010-02-24

    You rock!
    I put LD_PRELOAD on my bashrc pointing to my python lib (export LD_PRELOAD=/usr/lib/libpython2.6.so.1.0)  but for some reason, when I run the app o the console.py, they can't see it. Now I tried putting it directly, after LD_LIBRARY_PATH and voilâ, it works!!

    hans@barracuda:~/Escritorio/jep-2.4$ export LD_LIBRARY_PATH=`pwd`/src/jep/.libs/
    hans@barracuda:~/Escritorio/jep-2.4$ export LD_PRELOAD=/usr/lib/libpython2.6.so.1.0
    hans@barracuda:~/Escritorio/jep-2.4$ java -jar jep.jar console.py
    >>> import md5
    __main__:1: DeprecationWarning: the md5 module is deprecated; use hashlib instead
    >>> dir(md5)

    Now I'm facing another problem.. how can I set LD_PRELOAD from my java app, but that's out of our scope on this forum don't? :-)

    Thanks for your help, it helped me a lot!
    Greetings from Chile,

    Claudio.