Quantcast

Re: ImportError: No module named re

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: ImportError: No module named re

Stefan Richthofer
This looks like you placed a jar-file inside a jar-file.
I never tried this, but I doubt that Jython (actually Java?) can handle such nesting of jars (maybe this feature was added and I am overlooking it, sorry in that case). According to http://www.jython.org/jythonbook/en/1.0/SimpleWebApps.html?highlight=explode#distributing-via-standalone-jar (which is somewhat dated though) you should "explode" jython-standalone, add your code-files and then jar it again. I suppose you would have to do this with your other dependencies too or distribute them as separate files.
(Maybe you better try this with a toy-example first, before re-packing all the jars).
Looking at this, the need for some kind of deployment-tool that would automate such a process comes to my mind. You should maybe check, whether such a thing already exists (maybe for Java-apps in general).
 
Best
 
Stefan
 
 
Gesendet: Dienstag, 05. Juli 2016 um 16:21 Uhr
Von: "Ranga Babu Mandada" <[hidden email]>
An: "Stefan Richthofer" <[hidden email]>
Cc: "[hidden email]" <[hidden email]>
Betreff: Re: [Jython-users] ImportError: No module named re

Hello Stefan,

 

I am packaging my application as a runnable jar ex: application.jar.

 

It's contents are like below:

 

 

when I run my application via IDE(Intellij IDEA) it's working properly.

sys.path : 

['/home/rmandada/.m2/repository/org/python/jython-standalone/2.5.2/Lib', '/home/rmandada/.m2/repository/org/python/jython-standalone/2.5.2/jython-standalone-2.5.2.jar/Lib', '__classpath__', '__pyclasspath__/']

 

But when I run the application from command line using java -jar application.jar I am getting the above error.

now sys.path is :

 

['/home/rmandada/amelia-web.jar!/lib/Lib', '__classpath__', '__pyclasspath__/']​

 

I tried to add the path like below code.

 

PySystemState systemState = new PySystemState();
systemState.path.append(Py.newString("lib/jython-standalone-2.5.2.jar/Lib"));
Py.setSystemState(systemState);
return new ScriptEngineManager().getEngineByName("python");
 
​But it's not working . Please tell me how to add the path of jython-standalone-2.5.2.jar​ which lies in lib folder of application.jar.

 

 

 

Regards,
Ranga Babu
 

From: Stefan Richthofer <[hidden email]>
Sent: Friday, June 24, 2016 4:58 PM
To: Ranga Babu Mandada
Cc: [hidden email]
Subject: Re: [Jython-users] ImportError: No module named re
 
Hello Ranga,
 
this looks like in your command-line Jython-launch cannot find its lib-folder/doesn't have Jython-path configured properly.
You should first identify the location of Jython's lib-folder (the folder containing the .py-files making up the major
part of the standard lib). Then
- you can check via import sys; print sys.path whether that folder is on the path.
- you can verify if the problem is cured by manually adding that path via sys.path.append
- you can fix you Jython-path configuration by providing the environment variable JYTHONPATH to the jvm (see jython --help)
- I guess things get easier or issue might be self-soved if you call Jython via its launcher rather than manually via java-command.
- finally you can consider how to solve this for distribution, e.g. by distributing jython-standalone
(which contains the lib folder) or by providing an installer or launcher that makes sure the path is configured correctly for the user
 
Hope this somewhat helps.
Best
 
Stefan
 
 
 
Gesendet: Freitag, 24. Juni 2016 um 12:17 Uhr
Von: "Ranga Babu Mandada" <[hidden email]>
An: "[hidden email]" <[hidden email]>
Betreff: [Jython-users] ImportError: No module named re

 

Hello, 

 

I am using Jython in java application to run python scripts. I am using jython-standalone-2.5.2 as a dependency in pom.xml in maven project.

when I run the application in IDE the script is running without problems.

But when I run the application from command line using java -jar application.jar I get the following error

ImportError: No module named re​.

 

Please help me in fixing the issue.

 

Regards,
Ranga Babu
 
------------------------------------------------------------------------------ Attend Shape: An AT&T Tech Expo July 15-16. Meet us at AT&T Park in San Francisco, CA to explore cutting-edge tech and listen to tech luminaries present their vision of the future. This family event has something for everyone, including kids. Get more information and register today. http://sdm.link/attshape_______________________________________________ Jython-users mailing list [hidden email] https://lists.sourceforge.net/lists/listinfo/jython-users

------------------------------------------------------------------------------
Attend Shape: An AT&T Tech Expo July 15-16. Meet us at AT&T Park in San
Francisco, CA to explore cutting-edge tech and listen to tech luminaries
present their vision of the future. This family event has something for
everyone, including kids. Get more information and register today.
http://sdm.link/attshape
_______________________________________________
Jython-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/jython-users
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: ImportError: No module named re

Michael Chisholm
On 7/7/2016 6:08 PM, Stefan Richthofer wrote:
> This looks like you placed a jar-file inside a jar-file.
> I never tried this, but I doubt that Jython (actually Java?) can handle such
> nesting of jars (maybe this feature was added and I am overlooking it, sorry in
> that case).

It's possible; spring-boot does it [1].  I guess with the ability to
write custom classloaders, the sky's the limit :)

  According to
> http://www.jython.org/jythonbook/en/1.0/SimpleWebApps.html?highlight=explode#distributing-via-standalone-jar
> (which is somewhat dated though) you should "explode" jython-standalone, add
> your code-files and then jar it again. I suppose you would have to do this with
> your other dependencies too or distribute them as separate files.
> (Maybe you better try this with a toy-example first, before re-packing all the
> jars).

That's sometimes referred to as a "shaded" jar.  [1] mentions that
approach too.

> Looking at this, the need for some kind of deployment-tool that would automate
> such a process comes to my mind. You should maybe check, whether such a thing
> already exists (maybe for Java-apps in general).

I know Maven has a plugin for it [2].  Other build tools might too.

I don't know if this is helpful for Ranga's actual problem, but from the
quoted email, I thought it would be of interest.

Andy

1.
http://docs.spring.io/spring-boot/docs/current-SNAPSHOT/reference/htmlsingle/#executable-jar
2. http://maven.apache.org/plugins/maven-shade-plugin/



------------------------------------------------------------------------------
Attend Shape: An AT&T Tech Expo July 15-16. Meet us at AT&T Park in San
Francisco, CA to explore cutting-edge tech and listen to tech luminaries
present their vision of the future. This family event has something for
everyone, including kids. Get more information and register today.
http://sdm.link/attshape
_______________________________________________
Jython-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/jython-users
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: ImportError: No module named re

magicalne
This post was updated on .
In reply to this post by Stefan Richthofer
Hi all,

I have been through this issue for almost 2 days. I think I have figured it out.

I use jsr223(groovy, jython) in my spring boot web project. I can execute groovy script, but not jython script.

It looks like jython script want to import some modules from "Lib". But it cannot locate the right path to the "Lib".

I think jython is a little guilty on this issue.

The simplest way to get it work is to use :
springBoot { requiresUnpack = ['org.jruby:jruby-complete'] }

You can find it in spring boot doc:http://docs.spring.io/spring-boot/docs/current/reference/html/howto-build.html#howto-extract-specific-libraries-when-an-executable-jar-runs 

And it explains how it works.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: ImportError: No module named re

Curtis Rueden
Hi Chandler,

> It looks like jython script want to import some modules from "Lib".
> But it cannot locate the right path to the "Lib".

The Lib files are only present in jython-standalone, not jython base:

$ jar tf ~/.m2/repository/org/python/jython/2.7.0/jython-2.7.0.jar|grep ^Lib|wc -l
       0
$ jar tf ~/.m2/repository/org/python/jython-standalone/2.7.0/jython-standalone-2.7.0.jar|grep ^Lib|wc -l
    1226

I'm not sure how JRuby relates to this issue though, except that Jython and JRuby are rather incompatible with one another on the same classpath, unless you take special measures [1].

Regards,
Curtis


--
Curtis Rueden
LOCI software architect - http://loci.wisc.edu/software
ImageJ2 lead, Fiji maintainer - http://imagej.net/User:Rueden


On Thu, Dec 29, 2016 at 1:13 AM, magicalne <[hidden email]> wrote:
Hi all,

I have been through this issue for almost 2 days. I think I have figured it
out.

I use jsr223(groovy, jython) in my spring boot web project. I can execute
groovy script, but not jython script.

It looks like jython script want to import some modules from "Lib". But it
cannot locate the right path to the "Lib".

I think jython is a little guilty on this issue.

The most simple way to get it work is to use :
*springBoot { requiresUnpack = ['org.jruby:jruby-complete'] }*

You can find it in spring boot doc:
http://docs.spring.io/spring-boot/docs/current/reference/html/howto-build.html#howto-extract-specific-libraries-when-an-executable-jar-runs
<http://docs.spring.io/spring-boot/docs/current/reference/html/howto-build.html#howto-extract-specific-libraries-when-an-executable-jar-runs>

And it explains how it works.




--
View this message in context: http://python.6.x6.nabble.com/Re-ImportError-No-module-named-re-tp5194446p5206030.html
Sent from the jython-users mailing list archive at Nabble.com.

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, SlashDot.org! http://sdm.link/slashdot
_______________________________________________


------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, SlashDot.org! http://sdm.link/slashdot
_______________________________________________
Jython-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/jython-users
Loading...