How to use python modules in jepp?

3.3k Views Asked by At

I'd like to use python modules in my python code. But I think jepp cannot handle it properly.

For example:

>>>from  sklearn  import  linear_model    
>>>clf  =  linear_model.LinearRegression()    
>>>clf.fit  ([[0,  0],  [1,  1],  [2,  2]],  [0,  1,  2])    
>>>LinearRegression(copy_X=True, fit_intercept=True, normalize=False)    
>>>clf.coef_    
>>>array([ 0.5,  0.5])

Jepp seems to run forever after the first line: no error message or exception(I call these lines from eclipse with jep.eval("script") ), but the code works if I run it from the python interpreter 'manually'.

It doesn't work either if I use it in this way:

>>>import sklearn
>>>clf  =  sklearn.linear_model.LinearRegression()
>>>...same as above...

In this case I get the following error message: "SEVERE: null

jep.JepException: jep.JepException: : 'module' object has

no attribute 'linear_model'

at jep.Jep.eval(Jep.java:294)

at Main.executeScript(Main.java:72)

at Main.main(Main.java:36)

Caused by: jep.JepException: : 'module' object has no

attribute 'linear_model'

at jep.Jep.eval(Native Method)

at jep.Jep.eval(Jep.java:278)

... 2 more"

My only working version with modules is:

import numpy as np

beta = np.array([1, 0.1, 10])

So I need a solution in order to

  • use code: 'module.submodule.function'
  • use import: 'import module.submodule' and use code: 'submodule.function'

Is it possible?

I'm using python 2.7.2 and jep 2.4 on Ubuntu 12.04. And I call the code above from eclipse, where I set these environment variables:

  • LD_PRELOAD /usr/lib/libpython2.7.so
  • LD_LIBRARY_PATH /usr/local/lib/python2.7/dist-packages/

I know there's a newer version of jepp but for me it was hard to configure 2.4. too, so I wouldn't install a newer if it's unnecessary. (Because it was time-consuming for me. I had to compile a totally new python interpreter with ucs4, copy the installed python packages from dist-packages to site-packages, set environment variables and so on.)

Thanks in advance!

5

There are 5 best solutions below

0
Balazs Varhegyi On BEST ANSWER

There's another sourceforge project called pyro4. It can handle python modules like: numpy, sklearn... And maybe it's even better because it is currently developed. (last jepp version was released in 2010)

1
Balazs Varhegyi On

I've found this link today.

It says: 'Jepp doesn't seem to be able to import third-party libraries like scipy, numpy or wx (pure Python modules can be imported, though).'

Can anybody confirm this?

0
Dev Maha On

Check out https://github.com/mrj0/jep, that's where JEP is now. And it seems it was updated recently. As per the site it now works with Python version >= 2.6.

0
Francis On

I cannot speak for earlier versions of JEP, but I was able to run your script from the JEP 3.7.1 command line. It uses Python 3.6.5. I can also run the equivalent in Java 8.

C:>jep ... .... python\python36\Lib\site-packages\jep\console.py"

          No readline available. History will not be available.

               For Windows use pyreadline and get it from the official git
               repo on github:
               https://github.com/pyreadline/pyreadline

               Do NOT use the version on pypi.python.org, and therefore
               Do NOT use the version installed by pip.  It is out of date
               and doesn't work with Jep!

>>> from sklearn import linear_model <-- JEP takes a few seconds for the import to process
>>> clf = linear_model.LinearRegression()
>>> clf.fit ([[0, 0], [1, 1], [2, 2]], [0, 1, 2])
LinearRegression(copy_X=True, fit_intercept=True, n_jobs=1, normalize=False) <-- JEP Returns
>>> clf.fit ([[0, 0], [1, 1], [2, 2]], [0, 1, 2])
LinearRegression(copy_X=True, fit_intercept=True, n_jobs=1, normalize=False) <-- JEP Returns
>>> clf.coef_
array([0.5, 0.5]) <-- JEP Returns
>>>

0
Francis On

Balazs, it will indeed import 3rd-party libraries. One can do a Jep.eval('import sklearn') statement.