0

i'm trying to build a wrapper around a Python module, to embed it in my java code.

looks like this module use many tricks like subprocess, threading and so on

(actually it is itself a module that control a C utility provided AS-IS and only as a binary, i am trying to avoid the overcost to recode the inner logic and others tools that this python wrapper already provided)

by the way, when instantiate my own wrapper it from Java i get :

------------------
Exception in thread "MainThread" Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "__pyclasspath__/mywrapper.py", line 303, in <module>
  File "C:\jython2.5.2\Lib\subprocess.py", line 375, in <module>
    import msvcrt
ImportError: No module named msvcrt

if i look on my harddisk, there is no msvscrt.py where is it suppose to live ?

i am launching my jython with :

    PythonInterpreter interpreter = new PythonInterpreter(null, new PySystemState());

    PySystemState sys = Py.getSystemState();
    sys.path.append(new PyString("C:/jython2.5.2/Lib"));
    sys.platform = new PyString("win32"); // this is a trick for the wrapper to not fail on a inner plateform test detection with java1.7.0_03
mzjn
  • 48,958
  • 13
  • 128
  • 248
user1340802
  • 1,157
  • 4
  • 17
  • 36

1 Answers1

1

msvcrt is not available in Jython. In CPython on Windows, msvcrt is a built-in module compiled into the Python interpreter (you can check this with sys.builtin_module_names). There is no msvcrt.py file.

Why you need "a trick for the wrapper to not fail on a inner plateform test detection with java1.7.0_03", I can't say. But setting sys.platform to win32 makes Jython try to import msvcrt when using subprocess, which doesn't work.

mzjn
  • 48,958
  • 13
  • 128
  • 248
  • thank you ! i do not know how you were able to check that, but adapting my sys.platform value dependant part without changing actual value to 'win32' did it ! BTW i was very far than guessing it was linked ! And i could have not even write it here on SO in my question... – user1340802 May 04 '12 at 09:27