You can subscribe to this list here.
2000 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
(6) |
Nov
(8) |
Dec
(51) |
---|---|---|---|---|---|---|---|---|---|---|---|---|
2001 |
Jan
(105) |
Feb
(93) |
Mar
(194) |
Apr
(145) |
May
(100) |
Jun
(111) |
Jul
(117) |
Aug
(126) |
Sep
(233) |
Oct
(138) |
Nov
(164) |
Dec
(109) |
2002 |
Jan
(216) |
Feb
(175) |
Mar
(216) |
Apr
(194) |
May
(157) |
Jun
(140) |
Jul
(158) |
Aug
(73) |
Sep
(105) |
Oct
(164) |
Nov
(104) |
Dec
(95) |
2003 |
Jan
(72) |
Feb
(69) |
Mar
(81) |
Apr
(151) |
May
(101) |
Jun
(139) |
Jul
(99) |
Aug
(118) |
Sep
(115) |
Oct
(151) |
Nov
(161) |
Dec
(102) |
2004 |
Jan
(120) |
Feb
(175) |
Mar
(106) |
Apr
(111) |
May
(54) |
Jun
(78) |
Jul
(76) |
Aug
(105) |
Sep
(94) |
Oct
(143) |
Nov
(75) |
Dec
(85) |
2005 |
Jan
(99) |
Feb
(77) |
Mar
(164) |
Apr
(97) |
May
(79) |
Jun
(57) |
Jul
(65) |
Aug
(102) |
Sep
(95) |
Oct
(129) |
Nov
(123) |
Dec
(52) |
2006 |
Jan
(48) |
Feb
(99) |
Mar
(90) |
Apr
(51) |
May
(81) |
Jun
(136) |
Jul
(56) |
Aug
(109) |
Sep
(50) |
Oct
(44) |
Nov
(74) |
Dec
(75) |
2007 |
Jan
(92) |
Feb
(137) |
Mar
(93) |
Apr
(79) |
May
(52) |
Jun
(74) |
Jul
(143) |
Aug
(175) |
Sep
(154) |
Oct
(137) |
Nov
(88) |
Dec
(90) |
2008 |
Jan
(58) |
Feb
(113) |
Mar
(167) |
Apr
(88) |
May
(105) |
Jun
(37) |
Jul
(87) |
Aug
(72) |
Sep
(56) |
Oct
(41) |
Nov
(102) |
Dec
(70) |
2009 |
Jan
(115) |
Feb
(113) |
Mar
(126) |
Apr
(58) |
May
(125) |
Jun
(45) |
Jul
(90) |
Aug
(125) |
Sep
(84) |
Oct
(61) |
Nov
(111) |
Dec
(61) |
2010 |
Jan
(85) |
Feb
(86) |
Mar
(130) |
Apr
(58) |
May
(57) |
Jun
(32) |
Jul
(25) |
Aug
(50) |
Sep
(41) |
Oct
(65) |
Nov
(63) |
Dec
(24) |
2011 |
Jan
(43) |
Feb
(31) |
Mar
(28) |
Apr
(68) |
May
(53) |
Jun
(42) |
Jul
(58) |
Aug
(26) |
Sep
(51) |
Oct
(76) |
Nov
(60) |
Dec
(9) |
2012 |
Jan
(16) |
Feb
(32) |
Mar
(32) |
Apr
(39) |
May
(16) |
Jun
(19) |
Jul
(3) |
Aug
(11) |
Sep
(35) |
Oct
(47) |
Nov
(28) |
Dec
(18) |
2013 |
Jan
(18) |
Feb
(36) |
Mar
(10) |
Apr
(7) |
May
(7) |
Jun
(27) |
Jul
(17) |
Aug
(35) |
Sep
(19) |
Oct
(31) |
Nov
(8) |
Dec
(22) |
2014 |
Jan
(5) |
Feb
(11) |
Mar
(18) |
Apr
(23) |
May
(26) |
Jun
(14) |
Jul
(18) |
Aug
(26) |
Sep
(20) |
Oct
(48) |
Nov
(13) |
Dec
(9) |
2015 |
Jan
(9) |
Feb
(15) |
Mar
(25) |
Apr
(10) |
May
(26) |
Jun
(6) |
Jul
(13) |
Aug
(5) |
Sep
(14) |
Oct
(36) |
Nov
(24) |
Dec
(18) |
2016 |
Jan
(24) |
Feb
(11) |
Mar
(1) |
Apr
(6) |
May
(7) |
Jun
(3) |
Jul
(9) |
Aug
(15) |
Sep
(22) |
Oct
(5) |
Nov
(5) |
Dec
(2) |
2017 |
Jan
(20) |
Feb
(4) |
Mar
(4) |
Apr
(1) |
May
(5) |
Jun
(7) |
Jul
(14) |
Aug
(9) |
Sep
(18) |
Oct
(2) |
Nov
(3) |
Dec
(3) |
2018 |
Jan
(7) |
Feb
(6) |
Mar
(1) |
Apr
(2) |
May
|
Jun
|
Jul
(1) |
Aug
(18) |
Sep
(8) |
Oct
(9) |
Nov
(4) |
Dec
(6) |
2019 |
Jan
(5) |
Feb
|
Mar
(2) |
Apr
(4) |
May
(6) |
Jun
(8) |
Jul
(11) |
Aug
(10) |
Sep
(6) |
Oct
|
Nov
(1) |
Dec
|
2020 |
Jan
(8) |
Feb
(3) |
Mar
(1) |
Apr
(4) |
May
(1) |
Jun
(1) |
Jul
|
Aug
|
Sep
(1) |
Oct
(5) |
Nov
(2) |
Dec
(1) |
2021 |
Jan
|
Feb
|
Mar
(5) |
Apr
(2) |
May
|
Jun
(1) |
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
2022 |
Jan
|
Feb
(2) |
Mar
(1) |
Apr
|
May
|
Jun
|
Jul
(7) |
Aug
(1) |
Sep
(1) |
Oct
|
Nov
|
Dec
|
2023 |
Jan
|
Feb
|
Mar
|
Apr
|
May
(3) |
Jun
(5) |
Jul
(15) |
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
2024 |
Jan
|
Feb
(1) |
Mar
|
Apr
(2) |
May
|
Jun
(5) |
Jul
|
Aug
(1) |
Sep
|
Oct
|
Nov
|
Dec
|
2025 |
Jan
|
Feb
|
Mar
(1) |
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
From: Ted L. F. <te...@pr...> - 2018-10-02 04:16:27
|
Hi, Jeff. Another list member replied directly yesterday with this answer, which solved my issue: java -cp /opt/jython2.7.0/jython.jar:. HelloWorld\$py I needed the full path to the jar as well as the ":." to include the current working directory. And you're right that the classpath must come first. Several examples I tried all worked, even just a single print statement. So it must not be a requirement to have a main() in the Python script itself. Thanks for your analysis. Ted PS. I didn't realize until now that the message I referred to above had not been cc'ed to this list. ‐‐‐‐‐‐‐ Original Message ‐‐‐‐‐‐‐ On Monday, October 1, 2018 12:02 PM, Jeff Allen <ja...@fa...> wrote: > Hi Ted. > > Can you put the classpath at the end like that? Last thing is usually the class. Although why is java not complaining about main? Possibly it thinks HelloWorld$py is an inner class. Or is the $py being treated as a variable="" by the shell. It hardly matters: it still has to be a class that contains a main(), and one compiled from Python does not.If you want to see what it contains, you can javap it. > > You can make a class you run like that, but you have to write it in Java, and reference the .py file, or maybe have the text of the program in there as a string. It would be something like this: > > package demo_jython; > > import org.python.util.PythonInterpreter; > > public class ListDemo { > > public static void main(String[] args) { > PythonInterpreter interp = new PythonInterpreter(); > interp.exec("print 6*7"); > interp.execfile("HelloWorld.py"); > } > } > > You would then run that in the normal way for a Java program, except you need the dependencies on the path, say by putting the jython.jar or jython-standalone.jar on the class path. > > Jeff Allen > > On 30/09/2018 20:05, Ted Larson Freeman wrote: > >> Hi, Jeff and Adam. >> >> Thanks for your replies. My goal is to see if I can produce a Java .class file using Jython, which can then be run using Java on the command line. A coworker was able to do this with Scala in less than 15 minutes (including installation), and I wanted to see if I could do the same thing with Jython. (I can run Jython itself with the script below just fine.) >> >> I'm still missing something, as I get the same error with either the CLASSPATH evironment variable or when explicitly setting it on the command line. For example: >> >> % ls >> HelloWorld.py HelloWorld$py.class >> % java HelloWorld$py -classpath /home/ted/jython2.7.0 >> Error: Could not find or load main class HelloWorld >> >> Any further suggestions are greatly appreciated. >> >> Thanks! >> >> Ted >> >> PS. In case it helps, here is some info on my environment: >> >> % jython --version >> Jython 2.7.0 >> % java -version >> openjdk version "1.8.0_171" >> OpenJDK Runtime Environment (build 1.8.0_171-8u171-b11-0ubuntu0.17.10.1-b11) >> OpenJDK 64-Bit Server VM (build 25.171-b11, mixed mode) >> % uname -srv >> Linux 4.13.0-46-generic #51-Ubuntu SMP Tue Jun 12 12:36:29 UTC 2018 >> >> Sent with [ProtonMail](https://protonmail.com) Secure Email. >> >> ‐‐‐‐‐‐‐ Original Message ‐‐‐‐‐‐‐ >> On Sunday, September 30, 2018 10:51 AM, Jeff Allen [<ja...@fa...>](mailto:ja...@fa...) wrote: >> >>> The normal way to use Jython would be like CPython: >>> >>> $ jython HelloWorld.py >>> >>> That's with an appropriate PATH, of course, or you say explicitly where the launcher is as part of the command. If you just wanted to run the the Python code, that would be the way. The compiled $py.class would only ever live in memory. >>> >>> But maybe you know this and have something more complicated in mind. You can run the class you made from a Java program (class with main()) that you write. But you could run the .py file from a Java program too, and I think more easily. Either way, you need the jython JAR on the path as Adam says. What do you have in mind that makes you want to compile it as a separate step like this? >>> >>> Jeff Allen >>> >>> On 29/09/2018 21:13, Ted Larson Freeman via Jython-users wrote: >>> >>>> I have just installed Jython 2.7, and am looking for a simple example of compiling a Python script down to a Java .class file. Following a suggestion on Stack Overflow, I tried to compile a file called HelloWorld.py, which contains this: >>>> >>>> class HelloWorld(object): >>>> def hello(self): >>>> print 'Hello, World!' >>>> >>>> if __name__ == '__main__': >>>> h = HelloWorld() >>>> h.hello() >>>> >>>> Using these Jython commands (in the same working directory): >>>> >>>> import py_compile >>>> py_compile.compile('HelloWorld.py') >>>> >>>> That produces a file called HelloWorld$py.class, but when I try to run it with java from the command line, I get this error: >>>> >>>> Error: Could not find or load main class HelloWorld >>>> >>>> Please let me know what commands I should use. >>>> >>>> Thanks. >>>> >>>> Ted |
From: Jeff A. <ja...@fa...> - 2018-10-01 19:02:54
|
Hi Ted. Can you put the classpath at the end like that? Last thing is usually the class. Although why is java not complaining about main? Possibly it thinks HelloWorld$py is an inner class. Or is the $py being treated as a variable="" by the shell. It hardly matters: it still has to be a class that contains a main(), and one compiled from Python does not.If you want to see what it contains, you can javap it. You can make a class you run like that, but you have to write it in Java, and reference the .py file, or maybe have the text of the program in there as a string. It would be something like this: package demo_jython; import org.python.util.PythonInterpreter; public class ListDemo { public static void main(String[] args) { PythonInterpreter interp = new PythonInterpreter(); interp.exec("print 6*7"); interp.execfile("HelloWorld.py"); } } You would then run that in the normal way for a Java program, except you need the dependencies on the path, say by putting the jython.jar or jython-standalone.jar on the class path. Jeff Allen On 30/09/2018 20:05, Ted Larson Freeman wrote: > Hi, Jeff and Adam. > > Thanks for your replies. My goal is to see if I can produce a Java > .class file using Jython, which can then be run using Java on the > command line. A coworker was able to do this with Scala in less than > 15 minutes (including installation), and I wanted to see if I could do > the same thing with Jython. (I can run Jython itself with the script > below just fine.) > > I'm still missing something, as I get the same error with either the > CLASSPATH evironment variable or when explicitly setting it on the > command line. For example: > > % ls > HelloWorld.py HelloWorld$py.class > % java HelloWorld$py -classpath /home/ted/jython2.7.0 > Error: Could not find or load main class HelloWorld > > Any further suggestions are greatly appreciated. > > Thanks! > > Ted > > PS. In case it helps, here is some info on my environment: > > % jython --version > Jython 2.7.0 > % java -version > openjdk version "1.8.0_171" > OpenJDK Runtime Environment (build > 1.8.0_171-8u171-b11-0ubuntu0.17.10.1-b11) > OpenJDK 64-Bit Server VM (build 25.171-b11, mixed mode) > % uname -srv > Linux 4.13.0-46-generic #51-Ubuntu SMP Tue Jun 12 12:36:29 UTC 2018 > > > > Sent with ProtonMail <https://protonmail.com> Secure Email. > > ‐‐‐‐‐‐‐ Original Message ‐‐‐‐‐‐‐ > On Sunday, September 30, 2018 10:51 AM, Jeff Allen > <ja...@fa...> wrote: > >> The normal way to use Jython would be like CPython: >> >> $ jython HelloWorld.py >> >> That's with an appropriate PATH, of course, or you say explicitly >> where the launcher is as part of the command. If you just wanted to >> run the the Python code, that would be the way. The compiled >> $py.class would only ever live in memory. >> >> But maybe you know this and have something more complicated in mind. >> You can run the class you made from a Java program (class with >> main()) that you write. But you could run the .py file from a Java >> program too, and I think more easily. Either way, you need the jython >> JAR on the path as Adam says. What do you have in mind that makes you >> want to compile it as a separate step like this? >> >> >> Jeff Allen >> >> On 29/09/2018 21:13, Ted Larson Freeman via Jython-users wrote: >>> I have just installed Jython 2.7, and am looking for a simple >>> example of compiling a Python script down to a Java .class file. >>> Following a suggestion on Stack Overflow, I tried to compile a file >>> called HelloWorld.py, which contains this: >>> >>> class HelloWorld(object): >>> def hello(self): >>> print 'Hello, World!' >>> >>> if __name__ == '__main__': >>> h = HelloWorld() >>> h.hello() >>> >>> Using these Jython commands (in the same working directory): >>> >>> import py_compile >>> py_compile.compile('HelloWorld.py') >>> >>> That produces a file called HelloWorld$py.class, but when I try to >>> run it with java from the command line, I get this error: >>> >>> Error: Could not find or load main class HelloWorld >>> >>> Please let me know what commands I should use. >>> >>> Thanks. >>> >>> Ted > |
From: Ted L. F. <te...@pr...> - 2018-09-30 19:05:26
|
Hi, Jeff and Adam. Thanks for your replies. My goal is to see if I can produce a Java .class file using Jython, which can then be run using Java on the command line. A coworker was able to do this with Scala in less than 15 minutes (including installation), and I wanted to see if I could do the same thing with Jython. (I can run Jython itself with the script below just fine.) I'm still missing something, as I get the same error with either the CLASSPATH evironment variable or when explicitly setting it on the command line. For example: % ls HelloWorld.py HelloWorld$py.class % java HelloWorld$py -classpath /home/ted/jython2.7.0 Error: Could not find or load main class HelloWorld Any further suggestions are greatly appreciated. Thanks! Ted PS. In case it helps, here is some info on my environment: % jython --version Jython 2.7.0 % java -version openjdk version "1.8.0_171" OpenJDK Runtime Environment (build 1.8.0_171-8u171-b11-0ubuntu0.17.10.1-b11) OpenJDK 64-Bit Server VM (build 25.171-b11, mixed mode) % uname -srv Linux 4.13.0-46-generic #51-Ubuntu SMP Tue Jun 12 12:36:29 UTC 2018 Sent with [ProtonMail](https://protonmail.com) Secure Email. ‐‐‐‐‐‐‐ Original Message ‐‐‐‐‐‐‐ On Sunday, September 30, 2018 10:51 AM, Jeff Allen <ja...@fa...> wrote: > The normal way to use Jython would be like CPython: > > $ jython HelloWorld.py > > That's with an appropriate PATH, of course, or you say explicitly where the launcher is as part of the command. If you just wanted to run the the Python code, that would be the way. The compiled $py.class would only ever live in memory. > > But maybe you know this and have something more complicated in mind. You can run the class you made from a Java program (class with main()) that you write. But you could run the .py file from a Java program too, and I think more easily. Either way, you need the jython JAR on the path as Adam says. What do you have in mind that makes you want to compile it as a separate step like this? > > Jeff Allen > > On 29/09/2018 21:13, Ted Larson Freeman via Jython-users wrote: > >> I have just installed Jython 2.7, and am looking for a simple example of compiling a Python script down to a Java .class file. Following a suggestion on Stack Overflow, I tried to compile a file called HelloWorld.py, which contains this: >> >> class HelloWorld(object): >> def hello(self): >> print 'Hello, World!' >> >> if __name__ == '__main__': >> h = HelloWorld() >> h.hello() >> >> Using these Jython commands (in the same working directory): >> >> import py_compile >> py_compile.compile('HelloWorld.py') >> >> That produces a file called HelloWorld$py.class, but when I try to run it with java from the command line, I get this error: >> >> Error: Could not find or load main class HelloWorld >> >> Please let me know what commands I should use. >> >> Thanks. >> >> Ted |
From: Jeff A. <ja...@fa...> - 2018-09-30 17:51:18
|
The normal way to use Jython would be like CPython: $ jython HelloWorld.py That's with an appropriate PATH, of course, or you say explicitly where the launcher is as part of the command. If you just wanted to run the the Python code, that would be the way. The compiled $py.class would only ever live in memory. But maybe you know this and have something more complicated in mind. You can run the class you made from a Java program (class with main()) that you write. But you could run the .py file from a Java program too, and I think more easily. Either way, you need the jython JAR on the path as Adam says. What do you have in mind that makes you want to compile it as a separate step like this? Jeff Allen On 29/09/2018 21:13, Ted Larson Freeman via Jython-users wrote: > I have just installed Jython 2.7, and am looking for a simple example > of compiling a Python script down to a Java .class file. Following a > suggestion on Stack Overflow, I tried to compile a file called > HelloWorld.py, which contains this: > > class HelloWorld(object): > def hello(self): > print 'Hello, World!' > > if __name__ == '__main__': > h = HelloWorld() > h.hello() > > Using these Jython commands (in the same working directory): > > import py_compile > py_compile.compile('HelloWorld.py') > > That produces a file called HelloWorld$py.class, but when I try to run > it with java from the command line, I get this error: > > Error: Could not find or load main class HelloWorld > > Please let me know what commands I should use. > > Thanks. > > Ted > |
From: Adam B. <ada...@gm...> - 2018-09-30 12:34:30
|
Do you have jython on your classpath? It will be needed because of the classes extended and improted. Java seems to give an unexpectedly terse error message in this case. Adam On Sun, 30 Sep 2018 at 06:14, Ted Larson Freeman via Jython-users < jyt...@li...> wrote: > I have just installed Jython 2.7, and am looking for a simple example of > compiling a Python script down to a Java .class file. Following a > suggestion on Stack Overflow, I tried to compile a file called > HelloWorld.py, which contains this: > > class HelloWorld(object): > def hello(self): > print 'Hello, World!' > > if __name__ == '__main__': > h = HelloWorld() > h.hello() > > Using these Jython commands (in the same working directory): > > import py_compile > py_compile.compile('HelloWorld.py') > > That produces a file called HelloWorld$py.class, but when I try to run it > with java from the command line, I get this error: > > Error: Could not find or load main class HelloWorld > > Please let me know what commands I should use. > > Thanks. > > Ted > > _______________________________________________ > Jython-users mailing list > Jyt...@li... > https://lists.sourceforge.net/lists/listinfo/jython-users > |
From: Ted L. F. <te...@pr...> - 2018-09-29 20:13:48
|
I have just installed Jython 2.7, and am looking for a simple example of compiling a Python script down to a Java .class file. Following a suggestion on Stack Overflow, I tried to compile a file called HelloWorld.py, which contains this: class HelloWorld(object): def hello(self): print 'Hello, World!' if __name__ == '__main__': h = HelloWorld() h.hello() Using these Jython commands (in the same working directory): import py_compile py_compile.compile('HelloWorld.py') That produces a file called HelloWorld$py.class, but when I try to run it with java from the command line, I get this error: Error: Could not find or load main class HelloWorld Please let me know what commands I should use. Thanks. Ted |
From: James K. <ji...@sr...> - 2018-09-09 02:41:14
|
I believe if there were snapshot builds of the jython-installer were published that would provide a solution to a wider audience. I think a found an interim solution as we do utilize Artifactory for project artifacts. I was able to pull the current master branch, collect the Informix and Oracle JDBC jars and produce a full-build on my Mac which allowed me publish the jython-installer.jar to our artifact repository with a different version (2.7.2a1). That seems to work for my users. I was then able to use the jython-installer on the win10 vm and everything just worked. 2.7.0 poses other problems with Sphinx dependencies. Ultimately I may need to transition to JEP If Python 3 support is eventually needed - however I’m sticking with Jython as long as I can. - JK Sent from my iPhone > On Sep 8, 2018, at 10:53 AM, Jeff Allen <ja...@fa...> wrote: > > I am not entirely sure of the mechanism, but it is something to do with the C runtime DLL having to match the one against which the executable was built. See https://na01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fstackoverflow.com%2Fquestions%2F32457341%2Fpyinstaller-and-onefile-build-causes-error-loading-python-dll-error-code-14001&data=01%7C01%7Cjim.klo%40sri.com%7C3908dcd03c3d421c683808d615b3ed9c%7C40779d3379c44626b8bf140c4d5e9075%7C1&sdata=6%2BZm%2Bsj2PFF7Jy2xpTEIGXVQsLEroMcBfapbY8l9QCU%3D&reserved=0, which suggests you can get the missing dependency from the MS site. Or it may be that installing a CPython 2.7 will supply it. > > If that does not work it may be necessary to go down to 2.7.0 until 2.7.2 is available. (Sorry, no simple date available.) > > It would be useful to hear how you get on. This is a tricky one to reproduce because jython.exe always runs perfectly on the machine where you built it. The section in the dev-guide captures what we believe is the necessary incantation to package the dependencies so it works everywhere in 2.7.2. > > I'm assuming in all this that you actually need Jython for other work. If this is only happening as part of the Sphinx plug-in, later versions (that use Python 3) have found a way to provide CPython as a binary. > > > Jeff Allen > >> On 07/09/2018 02:19, James Klo wrote: >> >> Greetings, >> >> We have a maven job which installs Jython, Sphinx, a custom Pygments package we wrote that utilizes a Java library to parse a semantic reasoning language, and all the dependencies so we can generate documentation with color coded and formatted language examples. >> >> FWIW: all of our developers have historically been working on macOS or Linux, and haven’t had a Windows developer in a while (like 2 years). Anyways this user is getting this error: >> >> [INFO] --- maven-antrun-plugin:1.8:run (install-sphinx-doc) @ sphinx-doc --- >> >> [INFO] Executing tasks >> >> main: >> >> [java] Performing silent installation >> >> [java] 10 % >> >> [java] 20 % >> >> [java] 30 % >> >> [java] 40 % >> >> [java] 50 % >> >> [java] 60 % >> >> [java] 70 % >> >> [java] Generating start scripts ... >> >> [java] Installing pip and setuptools >> >> [java] 90 % >> >> *[java] Error loading Python DLL: Z:\source\sunflower-docs\doc\sphinx-doc\target\jython\bin\python27.dll (error code 14001)* >> >> > <snip> > > > _______________________________________________ > Jython-users mailing list > Jyt...@li... > https://na01.safelinks.protection.outlook.com/?url=https%3A%2F%2Flists.sourceforge.net%2Flists%2Flistinfo%2Fjython-users&data=01%7C01%7Cjim.klo%40sri.com%7C3908dcd03c3d421c683808d615b3ed9c%7C40779d3379c44626b8bf140c4d5e9075%7C1&sdata=q2DKsfO9U2%2ByfBbP0UdZtV7vYK3HAST7hadvx5vunxQ%3D&reserved=0 |
From: Jeff A. <ja...@fa...> - 2018-09-08 17:52:36
|
I am not entirely sure of the mechanism, but it is something to do with the C runtime DLL having to match the one against which the executable was built. See https://stackoverflow.com/questions/32457341/pyinstaller-and-onefile-build-causes-error-loading-python-dll-error-code-14001, which suggests you can get the missing dependency from the MS site. Or it may be that installing a CPython 2.7 will supply it. If that does not work it may be necessary to go down to 2.7.0 until 2.7.2 is available. (Sorry, no simple date available.) It would be useful to hear how you get on. This is a tricky one to reproduce because jython.exe always runs perfectly on the machine where you built it. The section in the dev-guide captures what we believe is the necessary incantation to package the dependencies so it works everywhere in 2.7.2. I'm assuming in all this that you actually need Jython for other work. If this is only happening as part of the Sphinx plug-in, later versions (that use Python 3) have found a way to provide CPython as a binary. Jeff Allen On 07/09/2018 02:19, James Klo wrote: > > Greetings, > > We have a maven job which installs Jython, Sphinx, a custom Pygments > package we wrote that utilizes a Java library to parse a semantic > reasoning language, and all the dependencies so we can generate > documentation with color coded and formatted language examples. > > FWIW: all of our developers have historically been working on macOS or > Linux, and haven’t had a Windows developer in a while (like 2 years). > Anyways this user is getting this error: > > [INFO] --- maven-antrun-plugin:1.8:run (install-sphinx-doc) @ > sphinx-doc --- > > [INFO] Executing tasks > > main: > > [java] Performing silent installation > > [java] 10 % > > [java] 20 % > > [java] 30 % > > [java] 40 % > > [java] 50 % > > [java] 60 % > > [java] 70 % > > [java] Generating start scripts ... > > [java] Installing pip and setuptools > > [java] 90 % > > *[java] Error loading Python DLL: > Z:\source\sunflower-docs\doc\sphinx-doc\target\jython\bin\python27.dll > (error code 14001)* > > <snip> |
From: James K. <ji...@sr...> - 2018-09-07 01:52:33
|
Greetings, We have a maven job which installs Jython, Sphinx, a custom Pygments package we wrote that utilizes a Java library to parse a semantic reasoning language, and all the dependencies so we can generate documentation with color coded and formatted language examples. FWIW: all of our developers have historically been working on macOS or Linux, and haven’t had a Windows developer in a while (like 2 years). Anyways this user is getting this error: [INFO] --- maven-antrun-plugin:1.8:run (install-sphinx-doc) @ sphinx-doc --- [INFO] Executing tasks main: [java] Performing silent installation [java] 10 % [java] 20 % [java] 30 % [java] 40 % [java] 50 % [java] 60 % [java] 70 % [java] Generating start scripts ... [java] Installing pip and setuptools [java] 90 % [java] Error loading Python DLL: Z:\source\sunflower-docs\doc\sphinx-doc\target\jython\bin\python27.dll (error code 14001) [java] 100 % [java] Congratulations! You successfully installed Jython 2.7.1 to directory Z:\source\sunflower-docs\doc\sphinx-doc\target\jython. [java] Z:\source\sunflower-docs\doc\sphinx-doc\target\jython\bin\pip install --build C:\Users\jimkl\AppData\Local\Temp\pip_build_1536281438690 Sphinx==1.5.2 sphinxcontrib-plantuml==0.11 sphinx-rtd-theme==0.3.0 [java] Exception in thread "main" java.io.IOException: Cannot run program "Z:\source\sunflower-docs\doc\sphinx-doc\target\jython\bin\pip": CreateProcess error=2, The system cannot find the file specified [java] at java.lang.ProcessBuilder.start(ProcessBuilder.java:1048) [java] at com.sri.sphinx.doc.InstallPhase2.installRequirements(InstallPhase2.java:165) [java] at com.sri.sphinx.doc.InstallPhase2.run(InstallPhase2.java:58) [java] at com.sri.sphinx.doc.InstallPhase2.main(InstallPhase2.java:42) [java] Caused by: java.io.IOException: CreateProcess error=2, The system cannot find the file specified [java] at java.lang.ProcessImpl.create(Native Method) [java] at java.lang.ProcessImpl.<init>(ProcessImpl.java:386) [java] at java.lang.ProcessImpl.start(ProcessImpl.java:137) [java] at java.lang.ProcessBuilder.start(ProcessBuilder.java:1029) [java] ... 3 more [java] Java Result: 1 We are running this install with the following Java code: List<String> installArgs = new ArrayList<String>(Arrays.asList(new String[]{ "--silent", "--directory", jythonHomeDir.toAbsolutePath().toString(), "--type", "standard", "--include", "mod", "ensurepip", "--exclude", "demo", "doc", "src" })); org.python.util.install.Installation.main(installArgs.toArray(new String[installArgs.size()])); I had located this bug report here: http://bugs.jython.org/issue2620 And this note in the Dev Guide… https://jython-devguide.readthedocs.io/en/latest/setup_jy.html#the-launcher-jython-exe which doesn’t seem to apply to me as I’m not checking out the source myself… Is there an updated jython-installer that accommodates this change? Is there some known workaround I can follow that doesn’t require me to refactor our install? Thanks, * Jim Klo |
From: Fabio Z. <fa...@gm...> - 2018-09-03 18:05:49
|
PyDev 6.5.0 Release Highlights - *Debugger* - Debugger is *much* more responsive (fixed bug in reader/writer on the PyDev side). - *breakpoint()* builtin is now supported to add a programmatic breakpoint (on any Python version). - Watch expression no longer giving error if evaluation is empty (patch by glhez). - *Editor* - Code folding of *#region/#endregion* regions (patch by ghbcode). - There's a new action which allows creating local imports from a global import (use *Ctrl+1* on top of global import name). - It's now possible to change the default interpreter through an action (default binding: *Ctrl+Shift+Alt+I*). - The interactive console now has scroll lock (patch by bongibong). About PyDev PyDev is an open-source Python IDE on top of Eclipse for Python, Jython and IronPython development, now also available for Python on Visual Studio Code. It comes with goodies such as code completion, syntax highlighting, syntax analysis, code analysis, refactor, debug, interactive console, etc. It is also available as a standalone through LiClipse with goodies such as multiple cursors, theming and support for many other languages, such as Django Templates, Jinja2, Html, JavaScript, etc. Links: PyDev: http://pydev.org PyDev Blog: http://pydev.blogspot.com PyDev on VSCode: http://pydev.org/vscode LiClipse: http://www.liclipse.com PyVmMonitor - Python Profiler: http://www.pyvmmonitor.com/ Cheers, Fabio Zadrozny |
From: Debashish <deb...@gm...> - 2018-08-15 10:40:34
|
Thanks so much Jeff & Adam. I am delighted to inform that this worked (especially setting *sys.argv* to an empty list, before adding my arguments, which got rid of the args being cached). Also, I am not sure if that was due to Adam's shaded JAR, renaming it to *jython.jar*, or the fact that I converted by WebApp to package my Spring Boot deployable as a WAR instead of a JAR, but the Jython library is now being detected and is able to invoke the Python script (without using CPython as I was doing earlier). The only thing left now to is to deploy it on my PaaS and see if it works fine on the cloud as well. Thanks again, much appreciated. Regards, Deb On Mon, 13 Aug 2018 at 23:20, Jeff Allen <ja...@fa...> wrote: > Deb: > > You could try building your JAR from the contents extracted from the > Jython standalone JAR. Most build tools can treat a JAR as a source in this > way. e.g. Ant: https://stackoverflow.com/a/185116 , or Gradle: > https://docs.gradle.org/current/userguide/working_with_files.html#sec:creating_uber_jar_example > . > In my example, argv is a reference to a PyList. This has an API by which > you could add/remove items without setting sys.argv. It may be clearer like > this: > > PySystemState sys = pyInterpreter.getSystemState(); > sys.argv.__add__(Py.newString("hello")); > sys.argv.__add__(Py.newString("world")); > > Although I think you could safely make a new PyList and replace it if you > wanted: > > sys.argv = new PyList() > > > Jeff Allen > > On 13/08/2018 09:53, Debashish wrote: > > Hi Jeff, > > Sorry but my requirement is not to run the Jython standalone JAR. The > Jython JAR will be packaged (along with other dependency JARs) inside my > application JAR and I have to run this application JAR. This is my primary > pain point, that there is no obvious way to specify the Jythin library > files to the running application, even after putting Jythin JAR on > classpath. Here I have no way to supply an absolute, file system path to > the library. > > Also I am not sure I understand how we can manipulaet the argv we get from: > PyList argv = pyInterpreter.getSystemState().argv; > > I see no setter method inside pyInterpreter to set the modified argv back. > > Thanks, > > Deb > > On Sun, 12 Aug 2018 at 18:41, Jeff Allen <ja...@fa...> wrote: > >> Hi Deb: >> >> By CPython I mean the implementation of the Python language written in C, >> which is the one most people mean when they just say "Python". >> >> Do not put the copy of the standard library that comes with CPython on >> the path for Jython. It may seem to work, but then bizarre things start to >> happen and no-one can help you. Jython has its own copy with many small >> adaptations, which (for you) is in the standalone JAR and need not be >> extracted. >> >> You probably don't need python.home. It is as easy as this to run Jython >> (in an empty directory that I just created): >> >> PS here> java -cp "C:\Jython\2.7.1-sa\jython-standalone-2.7.1.jar" org.python.util.jython >> Jython 2.7.1 (default:0df7adb1b397, Jun 30 2017, 19:02:43) >> [Java HotSpot(TM) 64-Bit Server VM (Oracle Corporation)] on java1.7.0_60 >> Type "help", "copyright", "credits" or "license" for more information. >> >>> import sys, colorsys >> >>> sys.path >> ['', 'C:\\Jython\\2.7.1-sa\\Lib', 'C:\\Jython\\2.7.1-sa\\jython-standalone-2.7.1.jar\\Lib', '__classpath__', '__pyclasspath__/', 'C:\\Users\\Jeff\\.local\\lib\\jython2.7\\site-packages'] >> >> I'm not sure why we have the second entry as well as the third on the >> path in this case as the library is in the JAR: >> >> >>> colorsys.__file__ >> 'C:\\Jython\\2.7.1-sa\\*jython-standalone-2.7.1.jar**\\Lib\\*colorsys.py' >> >>> exit() >> >> Now, if I define python.home to a folder that contains an alternate >> library: >> >> PS here> java "-Dpython.home=..\271-sa" -cp "C:\Jython\2.7.1-sa\jython-standalone-2.7.1.jar" org.python.util.jython >> Jython 2.7.1 (default:0df7adb1b397, Jun 30 2017, 19:02:43) >> [Java HotSpot(TM) 64-Bit Server VM (Oracle Corporation)] on java1.7.0_60 >> Type "help", "copyright", "credits" or "license" for more information. >> >>> import sys, colorsys >> >>> sys.path >> ['', 'C:\\Users\\Jeff\\Documents\\Jython\\271-sa\\Lib', 'C:\\Jython\\2.7.1-sa\\jython-standalone-2.7.1.jar\\Lib', '__classpath__', '__pyclasspath__/', 'C:\\Users\\Jeff\\.local\\lib\\jython2.7\\site-packages', 'C:\\Users\\Jeff\\Documents\\Jython\\271-sa\\Lib\\site-packages'] >> >>> colorsys.__file__ >> 'C:\\Users\\Jeff\\Documents\\Jython\\271-sa\\Lib\\colorsys.py' >> >> You see that Jython has looked there first and found the colorsys module. >> >> It's always worth exploring Python at the prompt first, but I'm aware you >> want to call interpreters from Java. I'm pretty sure argv is just: >> >> PyList argv = pyInterpreter.getSystemState().argv; >> >> This will be a copy of the default you supplied, that you can manipulate >> as you wish. >> >> Jeff >> >> Jeff Allen >> >> On 12/08/2018 10:53, Debashish wrote: >> >> Sorry, I got confused by the term CPython, I guess if I have Python >> installed its already CPython that I am using :) So the first bullet in my >> reply should only read that "Indeed I set *python.home* to my local >> CPython installation". And that worked (somehow). >> >> On Sun, 12 Aug 2018 at 15:11, Debashish <deb...@gm...> wrote: >> >>> Hi Jeff, Adam, >>> >>> Thanks a ton for the prompt reply. Few clarifications: >>> >>> 1. The *python.home* path I gave is the *local* Python 2.7 >>> installation path. I assume you are saying this should be *CPython* >>> home rather. I will try this after installing CPython locally. >>> 2. The problem is that I wish to deploy my code on Pivotal Cloud >>> Foundry (PCF) where I would not be able to install anything else apart from >>> the application JAR, no file-system access is available as since the code >>> runs inside PCF containers, I cannot expect Python or CPython to be >>> installed on that system. >>> 3. I tried several thing to make it work (for e.g. extracted the >>> *Lib* folder from the JAR and added it on the classpath, also >>> renamed the JAR to *jython.jar* and added it to classpath, supplied >>> the Lib folder path as *python.path* as well), none of these worked. >>> It seems if there is no way to supply the absolute path, then there is no >>> way to make it work from within a Java JAR. >>> 4. My Python script is current 400 LOCs and will keep on growing, so >>> I cannot possibly call its *functions* from my Java code as it would >>> couple it to the Python code. I guess the only better option would be to >>> port this Python code to Java. >>> 5. I am using Jython Standalone JAR 2.7.1 from Maven central. I >>> think what you are saying is that instead of passing command line arguments >>> (argv) to the static *initialize* method I can pass it to the >>> *PythonInterpreter* object rather. I am not sure how, as I do not >>> such any such method in the API. Is there a code example available? >>> >>> Thanks again for your help. >>> >>> Deb >>> >>> On Sun, 12 Aug 2018 at 03:26, Adam Burke <ada...@gm...> >>> wrote: >>> >>>> Hi Deb >>>> >>>> On top of that, depending on how the script you’re calling is written, >>>> it might be useful to call one layer down instead of using I/O. Jython lets >>>> you work with python objects fairly directly from Java, and call Python >>>> functions directly as well. So if your python script has internal functions >>>> and classes, you could call straight into them. >>>> >>>> YMMV. >>>> >>>> Adam >>>> >>>> > 在 2018年8月12日,上午7:41,Jeff Allen <ja...@fa...> 写道: >>>> > >>>> > I don't know anything about Spring Boot, but the standalone JAR must >>>> be on your path for you to be able to refer to "PythonInterpreter" in your >>>> code. So by "not detected" I guess you mean that Jython appear not to find >>>> its library (which is in the standalone JAR). Jython guesses based on the >>>> path to the JAR it seems to be running from (that org.python.core.Py >>>> was loaded from) but telling it is safer. >>>> > >>>> > This bit struck me as odd: >>>> > >>>> > props.put("python.home", "C:\\Dev\\Python27"); >>>> > >>>> > That's not the location of CPython is it? That would cause you a >>>> world of confusion. >>>> > >>>> > However, none of that addresses your question about argv (meaning >>>> sys.argv I suppose). The important observation here is that >>>> "PythonInterpreter.initialize" is a static method that sets a default argv >>>> that all interpreters will see as they are created. It makes a big >>>> difference now what version you are using. In 2.7.0, all interpreters were >>>> really the same interpreter: you got a separate namespace for your main, >>>> but the modules where all the same, in particular every interpreter shared >>>> sys. In 2.7.1, each interpreter gets its own sys, and so each module used >>>> is loaded again for each interpreter. >>>> > >>>> > I cannot say off the top of my head what the behaviour of the default >>>> argv and sys.argv is, but I'm pretty sure the interpreter you make in the >>>> next line has its own sys and the sys.argv you could set independently, >>>> although not in the constructor. >>>> > >>>> > Jeff Allen >>>> > >>>> >> On 11/08/2018 20:16, Debashish wrote: >>>> >> Hi, >>>> >> >>>> >> I am trying to call a Python Script from a Spring Boot applications. >>>> There are two issues I am facing: >>>> >> (1) The Jython Standalone JAR is not detected and I am forced to >>>> supply the local install path as "python.home" to make it work. >>>> >> (2) Once I initialize the /PythonInterpreter/ class, it seems it >>>> caches the argv I supply to it as for the subsequent invocation it uses the >>>> same argv values. I do call the close() method to do cleanup, but it >>>> doesn't help :( >>>> >> >>>> >> Properties preprops = System.getProperties(); >>>> >> Properties props = new Properties(); >>>> >> >>>> >> props.put("python.home", "C:\\Dev\\Python27"); >>>> >> props.put("python.console.encoding", "UTF-8"); >>>> >> props.put("python.security.respectJavaAccessibility", "false"); >>>> >> props.put("python.import.site", "false"); >>>> >> >>>> >> PythonInterpreter.initialize(preprops, props, arguments); >>>> >> PythonInterpreter pyInterpreter = new PythonInterpreter(); >>>> >> >>>> >> try { >>>> >> resource = new ClassPathResource("mypyscript.py"); >>>> >> out = new ByteArrayOutputStream(); >>>> >> err = new ByteArrayOutputStream(); >>>> >> pyInterpreter.setOut(out); >>>> >> pyInterpreter.setErr(err); >>>> >> pyInterpreter.execfile(resource.getInputStream()); >>>> >> result[0] = out.toString(); // reading the output >>>> >> result[1] = err.toString(); // reading any error >>>> >> } catch (Exception e) { >>>> >> throw new Exception(e); >>>> >> } finally { >>>> >> try { >>>> >> if (out != null) >>>> >> out.close(); >>>> >> if (err != null) >>>> >> err.close(); >>>> >> pyInterpreter.close(); >>>> >> } catch (IOException e) { >>>> >> e.printStackTrace(); >>>> >> } >>>> >> } >>>> >> >>>> >> Please help. >>>> >> >>>> >> Thanks, >>>> >> >>>> >> Deb >>>> >> >>>> >> >>>> >> >>>> ------------------------------------------------------------------------------ >>>> >> 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 >>>> >> Jyt...@li... >>>> >> https://lists.sourceforge.net/lists/listinfo/jython-users >>>> > >>>> > >>>> > >>>> ------------------------------------------------------------------------------ >>>> > 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 >>>> > Jyt...@li... >>>> > https://lists.sourceforge.net/lists/listinfo/jython-users >>>> >>>> >>>> ------------------------------------------------------------------------------ >>>> 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 >>>> Jyt...@li... >>>> https://lists.sourceforge.net/lists/listinfo/jython-users >>>> >>> >> > |
From: Jeff A. <ja...@fa...> - 2018-08-14 06:17:44
|
Hi Peter: From here it is a question of zeroing-in on the boundary between what works and what doesn't -- the usual debugging process. Does my simple example work for you, with the simple script? If even that fails for you, ask what powershell may be doing at start-up. It loads libraries from various default places. Maybe that hangs. There is a -NoProfile option to suppress some of it. And a -NonInteractive (?) I think probably simplifies i/o. You can look up the options. If the simple script works, then it seems to be something about your script. It is obviously more complicated than mine. If you start from my simple script and introduce your own by parts, where does it start to hang? You want to capture the output, but the way you show stdout captured is not what we see in the documentation (use PIPE). There are also warnings that when doing so, deadlock is possible but communicate() is a good choice. It seems to include the wait(). Here is a version of my example that captures the output: ==> script.py <== import subprocess p = subprocess.Popen(['powershell.exe', '-File', '.\\script.ps1'], stdout=subprocess.PIPE, stderr=subprocess.PIPE) r = p.communicate() print "stdout =", repr(r[0]) print "stderr =", repr(r[1]) print "exit status =", p.returncode I am using repr() in the output to make visible non-printing or non-ascii characters (bytes really) that may be a source of problems. PS here> java -jar "C:\Jython\2.7.1-sa\jython-standalone-2.7.1.jar" script.py stdout = 'Hello World!\r\n' stderr = '' exit status = 1234 Lastly, all this may equally be run under C Python, in case you suspect a divergence or broken installation. (Jython has to work hard to conceal various differences between Java Process API and the system call. Or maybe your library is bad.) It worked for me under IDLE. Jeff Jeff Allen On 14/08/2018 00:32, pr144 wrote: > > The problem is I can see the powershell is executing a Windows task, > but control never returns back to the calling Jython script..even > after the task is complete. > > So Jython is never getting to p.returncode.. > > Seems like it's stuck on the p.wait() line... > > > > On 8/13/2018 6:25 PM, Jeff Allen wro >> >> ==> script.ps1 <== >> echo "Hello World!" >> Exit 1234 >> >> ==> script.py <== >> import subprocess >> p = subprocess.Popen(['powershell.exe', '-File', '.\\script.ps1']) >> p.wait() >> print "exit status =", p.returncode >> >> ============== >> >> The p.wait() is important: >> https://docs.python.org/2/library/subprocess.html?highlight=check_output#subprocess.Popen.wait >> >> Now ... >> >> PS here> java -jar "C:\Jython\2.7.1-sa\jython-standalone-2.7.1.jar" >> script.py >> Hello World! >> exit status = 1234 >> >> >> Jeff Allen >> On 13/08/2018 18:20, Peter O'Reilly via Jython-users wrote: >>> Error says, >>> AttributeError: 'module' objects\ has no attribute 'check_output' >>> >>> I need the \return code from this line, >>> pipe = subprocess.Popen(['powershell.exe', >>> 'MY_SCRIPT.ps1',stdout=sys.stdout] >>> >>> >>> >>> >>> Peter >>> >>> >> > -- > Thank you, > Peter O'Reilly |
From: pr144 <pr...@ya...> - 2018-08-13 23:32:36
|
The problem is I can see the powershell is executing a Windows task, but control never returns back to the calling Jython script..even after the task is complete. So Jython is never getting to p.returncode.. Seems like it's stuck on the p.wait() line... On 8/13/2018 6:25 PM, Jeff Allen wro > > ==> script.ps1 <== > echo "Hello World!" > Exit 1234 > > ==> script.py <== > import subprocess > p = subprocess.Popen(['powershell.exe', '-File', '.\\script.ps1']) > p.wait() > print "exit status =", p.returncode > > ============== > > The p.wait() is important: > https://docs.python.org/2/library/subprocess.html?highlight=check_output#subprocess.Popen.wait > > Now ... > > PS here> java -jar "C:\Jython\2.7.1-sa\jython-standalone-2.7.1.jar" > script.py > Hello World! > exit status = 1234 > > > Jeff Allen > On 13/08/2018 18:20, Peter O'Reilly via Jython-users wrote: >> Error says, >> AttributeError: 'module' objects\ has no attribute 'check_output' >> >> I need the \return code from this line, >> pipe = subprocess.Popen(['powershell.exe', >> 'MY_SCRIPT.ps1',stdout=sys.stdout] >> >> >> >> >> Peter >> >> > -- Thank you, Peter O'Reilly |
From: Jeff A. <ja...@fa...> - 2018-08-13 22:25:13
|
==> script.ps1 <== echo "Hello World!" Exit 1234 ==> script.py <== import subprocess p = subprocess.Popen(['powershell.exe', '-File', '.\\script.ps1']) p.wait() print "exit status =", p.returncode ============== The p.wait() is important: https://docs.python.org/2/library/subprocess.html?highlight=check_output#subprocess.Popen.wait Now ... PS here> java -jar "C:\Jython\2.7.1-sa\jython-standalone-2.7.1.jar" script.py Hello World! exit status = 1234 Jeff Allen On 13/08/2018 18:20, Peter O'Reilly via Jython-users wrote: > Error says, > AttributeError: 'module' objects\ has no attribute 'check_output' > > I need the \return code from this line, > pipe = subprocess.Popen(['powershell.exe', > 'MY_SCRIPT.ps1',stdout=sys.stdout] > > > > > Peter > > |
From: <jem...@fr...> - 2018-08-13 20:38:04
|
If the Python module is not working for you, perhaps try java.lang.ProcessBuilder instead. Something like: import java pb=java.lang.ProcessBuilder('powershell.exe', 'MY_SCRIPT.ps1') # Redirect stdout as desired. p=pb.start() p.waitFor() print p.exitValue() On Mon, 13 Aug 2018 17:20:43 +0000 (UTC), Peter O'Reilly via Jython-users <jyt...@li...> wrote: > Error says, AttributeError: 'module' objects has no attribute > 'check_output' > I need the return code from this line, pipe = > subprocess.Popen(['powershell.exe', 'MY_SCRIPT.ps1',stdout=sys.stdout] > > Peter > > On Sunday, August 12, 2018, 11:28:17 AM EDT, Suvarchal wrote: > > How about > > cmd=["echo","hello"] > try: > retval=subprocess.check_output(cmd) > except OSError as e: > retval=e > > Cheers, > Suvi > > On Sun, Aug 12, 2018 at 10:58 AM pr144 via Jython-users wrote: > > I am running a Powershell script that executes a Task Manger scheduled > job on a different Windows Server from the Jython script. > > I am having a problem capturing the return value, the Powershell scripts > takes about 1-2 minutes, this is the code, > > pipe = subprocess.Popen(['powershell.exe', > 'MY_SCRIPT.ps1',stdout=sys.stdout] > > This doesn't work, (it returns before Pwershell script completes), > > pipe.communicate() > > This just leaves the the Jython script running at the command prompt > until I kill it, > > retCode=pipe.wait() > > What are the best options? > > Thank you, > PR > > ------------------------------------------------------------------------------ > Check out the vibrant tech community on one of the world's most > engaging tech sites, Slashdot.org! http://sdm.link/slashdot > [2]_______________________________________________ > Jython-users mailing list > Jyt...@li... [3] > https://lists.sourceforge.net/lists/listinfo/jython-users [4] > > > Links: > ------ > [1] mailto:jyt...@li... > [2] http://sdm.link/slashdot > [3] mailto:Jyt...@li... > [4] https://lists.sourceforge.net/lists/listinfo/jython-users |
From: Jeff A. <ja...@fa...> - 2018-08-13 17:50:21
|
Deb: You could try building your JAR from the contents extracted from the Jython standalone JAR. Most build tools can treat a JAR as a source in this way. e.g. Ant: https://stackoverflow.com/a/185116 , or Gradle: https://docs.gradle.org/current/userguide/working_with_files.html#sec:creating_uber_jar_example . In my example, argv is a reference to a PyList. This has an API by which you could add/remove items without setting sys.argv. It may be clearer like this: PySystemState sys = pyInterpreter.getSystemState(); sys.argv.__add__(Py.newString("hello")); sys.argv.__add__(Py.newString("world")); Although I think you could safely make a new PyList and replace it if you wanted: sys.argv = new PyList() Jeff Allen On 13/08/2018 09:53, Debashish wrote: > Hi Jeff, > > Sorry but my requirement is not to run the Jython standalone JAR. The > Jython JAR will be packaged (along with other dependency JARs) inside > my application JAR and I have to run this application JAR. This is my > primary pain point, that there is no obvious way to specify the Jythin > library files to the running application, even after putting Jythin > JAR on classpath. Here I have no way to supply an absolute, file > system path to the library. > > Also I am not sure I understand how we can manipulaet the argv we get > from: > PyList argv = pyInterpreter.getSystemState().argv; > > I see no setter method inside pyInterpreter to set the modified argv back. > > Thanks, > > Deb > > On Sun, 12 Aug 2018 at 18:41, Jeff Allen <ja...@fa... > <mailto:ja...@fa...>> wrote: > > Hi Deb: > > By CPython I mean the implementation of the Python language > written in C, which is the one most people mean when they just say > "Python". > > Do not put the copy of the standard library that comes with > CPython on the path for Jython. It may seem to work, but then > bizarre things start to happen and no-one can help you. Jython has > its own copy with many small adaptations, which (for you) is in > the standalone JAR and need not be extracted. > > You probably don't need python.home. It is as easy as this to run > Jython (in an empty directory that I just created): > > PS here> java -cp "C:\Jython\2.7.1-sa\jython-standalone-2.7.1.jar" org.python.util.jython > Jython 2.7.1 (default:0df7adb1b397, Jun 30 2017, 19:02:43) > [Java HotSpot(TM) 64-Bit Server VM (Oracle Corporation)] on java1.7.0_60 > Type "help", "copyright", "credits" or "license" for more information. > >>> import sys, colorsys > >>> sys.path > ['', 'C:\\Jython\\2.7.1-sa\\Lib', 'C:\\Jython\\2.7.1-sa\\jython-standalone-2.7.1.jar\\Lib', '__classpath__', '__pyclasspath__/', 'C:\\Users\\Jeff\\.local\\lib\\jython2.7\\site-packages'] > > I'm not sure why we have the second entry as well as the third on > the path in this case as the library is in the JAR: > > >>> colorsys.__file__ > 'C:\\Jython\\2.7.1-sa\\*jython-standalone-2.7.1.jar**\\Lib\\*colorsys.py' > >>> exit() > > Now, if I define python.home to a folder that contains an > alternate library: > > PS here> java "-Dpython.home=..\271-sa" -cp "C:\Jython\2.7.1-sa\jython-standalone-2.7.1.jar" org.python.util.jython > Jython 2.7.1 (default:0df7adb1b397, Jun 30 2017, 19:02:43) > [Java HotSpot(TM) 64-Bit Server VM (Oracle Corporation)] on java1.7.0_60 > Type "help", "copyright", "credits" or "license" for more information. > >>> import sys, colorsys > >>> sys.path > ['', 'C:\\Users\\Jeff\\Documents\\Jython\\271-sa\\Lib', 'C:\\Jython\\2.7.1-sa\\jython-standalone-2.7.1.jar\\Lib', '__classpath__', '__pyclasspath__/', 'C:\\Users\\Jeff\\.local\\lib\\jython2.7\\site-packages', 'C:\\Users\\Jeff\\Documents\\Jython\\271-sa\\Lib\\site-packages'] > >>> colorsys.__file__ > 'C:\\Users\\Jeff\\Documents\\Jython\\271-sa\\Lib\\colorsys.py' > > You see that Jython has looked there first and found the colorsys > module. > > It's always worth exploring Python at the prompt first, but I'm > aware you want to call interpreters from Java. I'm pretty sure > argv is just: > > PyList argv = pyInterpreter.getSystemState().argv; > > This will be a copy of the default you supplied, that you can > manipulate as you wish. > > Jeff > > Jeff Allen > > On 12/08/2018 10:53, Debashish wrote: >> Sorry, I got confused by the term CPython, I guess if I have >> Python installed its already CPython that I am using :) So the >> first bullet in my reply should only read that "Indeed I set >> /python.home/ to my local CPython installation". And that worked >> (somehow). >> >> On Sun, 12 Aug 2018 at 15:11, Debashish <deb...@gm... >> <mailto:deb...@gm...>> wrote: >> >> Hi Jeff, Adam, >> >> Thanks a ton for the prompt reply. Few clarifications: >> >> 1. The /python.home/ path I gave is the /local/ Python 2.7 >> installation path. I assume you are saying this should be >> /CPython/ home rather. I will try this after installing >> CPython locally. >> 2. The problem is that I wish to deploy my code on Pivotal >> Cloud Foundry (PCF) where I would not be able to install >> anything else apart from the application JAR, no >> file-system access is available as since the code runs >> inside PCF containers, I cannot expect Python or CPython >> to be installed on that system. >> 3. I tried several thing to make it work (for e.g. extracted >> the /Lib/ folder from the JAR and added it on the >> classpath, also renamed the JAR to /jython.jar/ and added >> it to classpath, supplied the Lib folder path as >> /python.path/ as well), none of these worked. It seems if >> there is no way to supply the absolute path, then there >> is no way to make it work from within a Java JAR. >> 4. My Python script is current 400 LOCs and will keep on >> growing, so I cannot possibly call its /functions/ from >> my Java code as it would couple it to the Python code. I >> guess the only better option would be to port this Python >> code to Java. >> 5. I am using Jython Standalone JAR 2.7.1 from Maven >> central. I think what you are saying is that instead of >> passing command line arguments (argv) to the static >> /initialize/ method I can pass it to the >> /PythonInterpreter/ object rather. I am not sure how, as >> I do not such any such method in the API. Is there a code >> example available? >> >> Thanks again for your help. >> >> Deb >> >> On Sun, 12 Aug 2018 at 03:26, Adam Burke >> <ada...@gm... <mailto:ada...@gm...>> wrote: >> >> Hi Deb >> >> On top of that, depending on how the script you’re >> calling is written, it might be useful to call one layer >> down instead of using I/O. Jython lets you work with >> python objects fairly directly from Java, and call Python >> functions directly as well. So if your python script has >> internal functions and classes, you could call straight >> into them. >> >> YMMV. >> >> Adam >> >> > 在 2018年8月12日,上午7:41,Jeff Allen <ja...@fa... >> <mailto:ja...@fa...>> 写道: >> > >> > I don't know anything about Spring Boot, but the >> standalone JAR must be on your path for you to be able to >> refer to "PythonInterpreter" in your code. So by "not >> detected" I guess you mean that Jython appear not to find >> its library (which is in the standalone JAR). Jython >> guesses based on the path to the JAR it seems to be >> running from (that org.python.core.Py >> <http://org.python.core.Py> was loaded from) but telling >> it is safer. >> > >> > This bit struck me as odd: >> > >> > props.put("python.home", "C:\\Dev\\Python27"); >> > >> > That's not the location of CPython is it? That would >> cause you a world of confusion. >> > >> > However, none of that addresses your question about >> argv (meaning sys.argv I suppose). The important >> observation here is that "PythonInterpreter.initialize" >> is a static method that sets a default argv that all >> interpreters will see as they are created. It makes a big >> difference now what version you are using. In 2.7.0, all >> interpreters were really the same interpreter: you got a >> separate namespace for your main, but the modules where >> all the same, in particular every interpreter shared sys. >> In 2.7.1, each interpreter gets its own sys, and so each >> module used is loaded again for each interpreter. >> > >> > I cannot say off the top of my head what the behaviour >> of the default argv and sys.argv is, but I'm pretty sure >> the interpreter you make in the next line has its own sys >> and the sys.argv you could set independently, although >> not in the constructor. >> > >> > Jeff Allen >> > >> >> On 11/08/2018 20:16, Debashish wrote: >> >> Hi, >> >> >> >> I am trying to call a Python Script from a Spring Boot >> applications. There are two issues I am facing: >> >> (1) The Jython Standalone JAR is not detected and I am >> forced to supply the local install path as "python.home" >> to make it work. >> >> (2) Once I initialize the /PythonInterpreter/ class, >> it seems it caches the argv I supply to it as for the >> subsequent invocation it uses the same argv values. I do >> call the close() method to do cleanup, but it doesn't help :( >> >> >> >> Properties preprops = >> System.getProperties(); >> >> Properties props = new Properties(); >> >> >> >> props.put("python.home", "C:\\Dev\\Python27"); >> >> props.put("python.console.encoding", "UTF-8"); >> >> props.put("python.security.respectJavaAccessibility", >> "false"); >> >> props.put("python.import.site", "false"); >> >> >> >> PythonInterpreter.initialize(preprops, props, arguments); >> >> PythonInterpreter pyInterpreter = new PythonInterpreter(); >> >> >> >> try { >> >> resource = new ClassPathResource("mypyscript.py"); >> >> out = new ByteArrayOutputStream(); >> >> err = new ByteArrayOutputStream(); >> >> pyInterpreter.setOut(out); >> >> pyInterpreter.setErr(err); >> >> pyInterpreter.execfile(resource.getInputStream()); >> >> result[0] = out.toString(); // reading the output >> >> result[1] = err.toString(); // reading any error >> >> } catch (Exception e) { >> >> throw new Exception(e); >> >> } finally { >> >> try { >> >> if (out != null) >> >> out.close(); >> >> if (err != null) >> >> err.close(); >> >> pyInterpreter.close(); >> >> } catch (IOException e) { >> >> e.printStackTrace(); >> >> } >> >> } >> >> >> >> Please help. >> >> >> >> Thanks, >> >> >> >> Deb >> >> >> >> >> >> >> ------------------------------------------------------------------------------ >> >> 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 >> >> Jyt...@li... >> <mailto:Jyt...@li...> >> >> https://lists.sourceforge.net/lists/listinfo/jython-users >> > >> > >> > >> ------------------------------------------------------------------------------ >> > 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 >> > Jyt...@li... >> <mailto:Jyt...@li...> >> > https://lists.sourceforge.net/lists/listinfo/jython-users >> >> ------------------------------------------------------------------------------ >> 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 >> Jyt...@li... >> <mailto:Jyt...@li...> >> https://lists.sourceforge.net/lists/listinfo/jython-users >> > |
From: Peter O'R. <pr...@ya...> - 2018-08-13 17:21:16
|
Error says, AttributeError: 'module' objects\ has no attribute 'check_output' I need the \return code from this line, pipe = subprocess.Popen(['powershell.exe', 'MY_SCRIPT.ps1',stdout=sys.stdout] Peter On Sunday, August 12, 2018, 11:28:17 AM EDT, Suvarchal <suv...@gm...> wrote: How about cmd=["echo","hello"] try: retval=subprocess.check_output(cmd) except OSError as e: retval=e Cheers, Suvi On Sun, Aug 12, 2018 at 10:58 AM pr144 via Jython-users <jyt...@li...> wrote: I am running a Powershell script that executes a Task Manger scheduled job on a different Windows Server from the Jython script. I am having a problem capturing the return value, the Powershell scripts takes about 1-2 minutes, this is the code, pipe = subprocess.Popen(['powershell.exe', 'MY_SCRIPT.ps1',stdout=sys.stdout] This doesn't work, (it returns before Pwershell script completes), pipe.communicate() This just leaves the the Jython script running at the command prompt until I kill it, retCode=pipe.wait() What are the best options? Thank you, PR ------------------------------------------------------------------------------ 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 Jyt...@li... https://lists.sourceforge.net/lists/listinfo/jython-users |
From: Debashish <deb...@gm...> - 2018-08-13 08:54:37
|
Hi Jeff, Sorry but my requirement is not to run the Jython standalone JAR. The Jython JAR will be packaged (along with other dependency JARs) inside my application JAR and I have to run this application JAR. This is my primary pain point, that there is no obvious way to specify the Jythin library files to the running application, even after putting Jythin JAR on classpath. Here I have no way to supply an absolute, file system path to the library. Also I am not sure I understand how we can manipulaet the argv we get from: PyList argv = pyInterpreter.getSystemState().argv; I see no setter method inside pyInterpreter to set the modified argv back. Thanks, Deb On Sun, 12 Aug 2018 at 18:41, Jeff Allen <ja...@fa...> wrote: > Hi Deb: > > By CPython I mean the implementation of the Python language written in C, > which is the one most people mean when they just say "Python". > > Do not put the copy of the standard library that comes with CPython on the > path for Jython. It may seem to work, but then bizarre things start to > happen and no-one can help you. Jython has its own copy with many small > adaptations, which (for you) is in the standalone JAR and need not be > extracted. > > You probably don't need python.home. It is as easy as this to run Jython > (in an empty directory that I just created): > > PS here> java -cp "C:\Jython\2.7.1-sa\jython-standalone-2.7.1.jar" org.python.util.jython > Jython 2.7.1 (default:0df7adb1b397, Jun 30 2017, 19:02:43) > [Java HotSpot(TM) 64-Bit Server VM (Oracle Corporation)] on java1.7.0_60 > Type "help", "copyright", "credits" or "license" for more information. > >>> import sys, colorsys > >>> sys.path > ['', 'C:\\Jython\\2.7.1-sa\\Lib', 'C:\\Jython\\2.7.1-sa\\jython-standalone-2.7.1.jar\\Lib', '__classpath__', '__pyclasspath__/', 'C:\\Users\\Jeff\\.local\\lib\\jython2.7\\site-packages'] > > I'm not sure why we have the second entry as well as the third on the path > in this case as the library is in the JAR: > > >>> colorsys.__file__ > 'C:\\Jython\\2.7.1-sa\\*jython-standalone-2.7.1.jar**\\Lib\\*colorsys.py' > >>> exit() > > Now, if I define python.home to a folder that contains an alternate > library: > > PS here> java "-Dpython.home=..\271-sa" -cp "C:\Jython\2.7.1-sa\jython-standalone-2.7.1.jar" org.python.util.jython > Jython 2.7.1 (default:0df7adb1b397, Jun 30 2017, 19:02:43) > [Java HotSpot(TM) 64-Bit Server VM (Oracle Corporation)] on java1.7.0_60 > Type "help", "copyright", "credits" or "license" for more information. > >>> import sys, colorsys > >>> sys.path > ['', 'C:\\Users\\Jeff\\Documents\\Jython\\271-sa\\Lib', 'C:\\Jython\\2.7.1-sa\\jython-standalone-2.7.1.jar\\Lib', '__classpath__', '__pyclasspath__/', 'C:\\Users\\Jeff\\.local\\lib\\jython2.7\\site-packages', 'C:\\Users\\Jeff\\Documents\\Jython\\271-sa\\Lib\\site-packages'] > >>> colorsys.__file__ > 'C:\\Users\\Jeff\\Documents\\Jython\\271-sa\\Lib\\colorsys.py' > > You see that Jython has looked there first and found the colorsys module. > > It's always worth exploring Python at the prompt first, but I'm aware you > want to call interpreters from Java. I'm pretty sure argv is just: > > > PyList argv = pyInterpreter.getSystemState().argv; > > This will be a copy of the default you supplied, that you can manipulate > as you wish. > > Jeff > > Jeff Allen > > On 12/08/2018 10:53, Debashish wrote: > > Sorry, I got confused by the term CPython, I guess if I have Python > installed its already CPython that I am using :) So the first bullet in my > reply should only read that "Indeed I set *python.home* to my local > CPython installation". And that worked (somehow). > > On Sun, 12 Aug 2018 at 15:11, Debashish <deb...@gm...> wrote: > >> Hi Jeff, Adam, >> >> Thanks a ton for the prompt reply. Few clarifications: >> >> 1. The *python.home* path I gave is the *local* Python 2.7 >> installation path. I assume you are saying this should be *CPython* >> home rather. I will try this after installing CPython locally. >> 2. The problem is that I wish to deploy my code on Pivotal Cloud >> Foundry (PCF) where I would not be able to install anything else apart from >> the application JAR, no file-system access is available as since the code >> runs inside PCF containers, I cannot expect Python or CPython to be >> installed on that system. >> 3. I tried several thing to make it work (for e.g. extracted the *Lib* >> folder from the JAR and added it on the classpath, also renamed the JAR to >> *jython.jar* and added it to classpath, supplied the Lib folder path >> as *python.path* as well), none of these worked. It seems if there is >> no way to supply the absolute path, then there is no way to make it work >> from within a Java JAR. >> 4. My Python script is current 400 LOCs and will keep on growing, so >> I cannot possibly call its *functions* from my Java code as it would >> couple it to the Python code. I guess the only better option would be to >> port this Python code to Java. >> 5. I am using Jython Standalone JAR 2.7.1 from Maven central. I think >> what you are saying is that instead of passing command line arguments >> (argv) to the static *initialize* method I can pass it to the >> *PythonInterpreter* object rather. I am not sure how, as I do not >> such any such method in the API. Is there a code example available? >> >> Thanks again for your help. >> >> Deb >> >> On Sun, 12 Aug 2018 at 03:26, Adam Burke <ada...@gm...> wrote: >> >>> Hi Deb >>> >>> On top of that, depending on how the script you’re calling is written, >>> it might be useful to call one layer down instead of using I/O. Jython lets >>> you work with python objects fairly directly from Java, and call Python >>> functions directly as well. So if your python script has internal functions >>> and classes, you could call straight into them. >>> >>> YMMV. >>> >>> Adam >>> >>> > 在 2018年8月12日,上午7:41,Jeff Allen <ja...@fa...> 写道: >>> > >>> > I don't know anything about Spring Boot, but the standalone JAR must >>> be on your path for you to be able to refer to "PythonInterpreter" in your >>> code. So by "not detected" I guess you mean that Jython appear not to find >>> its library (which is in the standalone JAR). Jython guesses based on the >>> path to the JAR it seems to be running from (that org.python.core.Py >>> was loaded from) but telling it is safer. >>> > >>> > This bit struck me as odd: >>> > >>> > props.put("python.home", "C:\\Dev\\Python27"); >>> > >>> > That's not the location of CPython is it? That would cause you a world >>> of confusion. >>> > >>> > However, none of that addresses your question about argv (meaning >>> sys.argv I suppose). The important observation here is that >>> "PythonInterpreter.initialize" is a static method that sets a default argv >>> that all interpreters will see as they are created. It makes a big >>> difference now what version you are using. In 2.7.0, all interpreters were >>> really the same interpreter: you got a separate namespace for your main, >>> but the modules where all the same, in particular every interpreter shared >>> sys. In 2.7.1, each interpreter gets its own sys, and so each module used >>> is loaded again for each interpreter. >>> > >>> > I cannot say off the top of my head what the behaviour of the default >>> argv and sys.argv is, but I'm pretty sure the interpreter you make in the >>> next line has its own sys and the sys.argv you could set independently, >>> although not in the constructor. >>> > >>> > Jeff Allen >>> > >>> >> On 11/08/2018 20:16, Debashish wrote: >>> >> Hi, >>> >> >>> >> I am trying to call a Python Script from a Spring Boot applications. >>> There are two issues I am facing: >>> >> (1) The Jython Standalone JAR is not detected and I am forced to >>> supply the local install path as "python.home" to make it work. >>> >> (2) Once I initialize the /PythonInterpreter/ class, it seems it >>> caches the argv I supply to it as for the subsequent invocation it uses the >>> same argv values. I do call the close() method to do cleanup, but it >>> doesn't help :( >>> >> >>> >> Properties preprops = System.getProperties(); >>> >> Properties props = new Properties(); >>> >> >>> >> props.put("python.home", "C:\\Dev\\Python27"); >>> >> props.put("python.console.encoding", "UTF-8"); >>> >> props.put("python.security.respectJavaAccessibility", "false"); >>> >> props.put("python.import.site", "false"); >>> >> >>> >> PythonInterpreter.initialize(preprops, props, arguments); >>> >> PythonInterpreter pyInterpreter = new PythonInterpreter(); >>> >> >>> >> try { >>> >> resource = new ClassPathResource("mypyscript.py"); >>> >> out = new ByteArrayOutputStream(); >>> >> err = new ByteArrayOutputStream(); >>> >> pyInterpreter.setOut(out); >>> >> pyInterpreter.setErr(err); >>> >> pyInterpreter.execfile(resource.getInputStream()); >>> >> result[0] = out.toString(); // reading the output >>> >> result[1] = err.toString(); // reading any error >>> >> } catch (Exception e) { >>> >> throw new Exception(e); >>> >> } finally { >>> >> try { >>> >> if (out != null) >>> >> out.close(); >>> >> if (err != null) >>> >> err.close(); >>> >> pyInterpreter.close(); >>> >> } catch (IOException e) { >>> >> e.printStackTrace(); >>> >> } >>> >> } >>> >> >>> >> Please help. >>> >> >>> >> Thanks, >>> >> >>> >> Deb >>> >> >>> >> >>> >> >>> ------------------------------------------------------------------------------ >>> >> 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 >>> >> Jyt...@li... >>> >> https://lists.sourceforge.net/lists/listinfo/jython-users >>> > >>> > >>> > >>> ------------------------------------------------------------------------------ >>> > 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 >>> > Jyt...@li... >>> > https://lists.sourceforge.net/lists/listinfo/jython-users >>> >>> >>> ------------------------------------------------------------------------------ >>> 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 >>> Jyt...@li... >>> https://lists.sourceforge.net/lists/listinfo/jython-users >>> >> > |
From: Jeff A. <ja...@fa...> - 2018-08-12 15:40:14
|
You're right, it's even easier. :) I had simplified my command from a line that needed some other jars in the path (but -cp is ignored when -jar is given). Jeff Allen On 12/08/2018 15:37, Curtis Rueden wrote: > Hi, > > > It is as easy as this to run Jython (in an empty directory that I just > > created): > > > > PS here> java -cp "C:\Jython\2.7.1-sa\jython-standalone-2.7.1.jar" > org.python.util.jython > > I like to use "-jar" to infer the main class: > > java -jar "C:\Jython\2.7.1-sa\jython-standalone-2.7.1.jar" > > |
From: Suvarchal <suv...@gm...> - 2018-08-12 15:28:24
|
How about cmd=["echo","hello"] try: retval=subprocess.check_output(cmd) except OSError as e: retval=e Cheers, Suvi On Sun, Aug 12, 2018 at 10:58 AM pr144 via Jython-users < jyt...@li...> wrote: > I am running a Powershell script that executes a Task Manger scheduled job > on a different Windows Server from the Jython script. > > I am having a problem capturing the return value, the Powershell scripts > takes about 1-2 minutes, this is the code, > > pipe = subprocess.Popen(['powershell.exe', > 'MY_SCRIPT.ps1',stdout=sys.stdout] > > This doesn't work, (it returns before Pwershell script completes), > > pipe.communicate() > > This just leaves the the Jython script running at the command prompt until > I kill it, > > retCode=pipe.wait() > > What are the best options? > > Thank you, > PR > > > ------------------------------------------------------------------------------ > 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 > Jyt...@li... > https://lists.sourceforge.net/lists/listinfo/jython-users > |
From: pr144 <pr...@ya...> - 2018-08-12 14:58:27
|
I am running a Powershell script that executes a Task Manger scheduled job on a different Windows Server from the Jython script. I am having a problem capturing the return value, the Powershell scripts takes about 1-2 minutes, this is the code, pipe = subprocess.Popen(['powershell.exe', 'MY_SCRIPT.ps1',stdout=sys.stdout] This doesn't work, (it returns before Pwershell script completes), pipe.communicate() This just leaves the the Jython script running at the command prompt until I kill it, retCode=pipe.wait() What are the best options? Thank you, PR |
From: Curtis R. <ctr...@wi...> - 2018-08-12 14:37:40
|
Hi, > It is as easy as this to run Jython (in an empty directory that I just > created): > > PS here> java -cp "C:\Jython\2.7.1-sa\jython-standalone-2.7.1.jar" org.python.util.jython I like to use "-jar" to infer the main class: java -jar "C:\Jython\2.7.1-sa\jython-standalone-2.7.1.jar" Relatedly, I wrote a Maven-based Java code launcher called jrun [1], which makes launching Jython even easier: jrun org.python:jython-standalone Finally, Deb, depending on which other dependencies you are including in your application, you may run into trouble with jython-standalone and duplicate classes of incompatible versions. I maintain a variant of jython-standalone that shades its dependencies, which you can read about here: https://github.com/scijava/jython-shaded Regards, Curtis [1] https://github.com/ctrueden/jrun/ -- Curtis Rueden LOCI software architect - https://loci.wisc.edu/software ImageJ2 lead, Fiji maintainer - https://imagej.net/User:Rueden On Sun, Aug 12, 2018 at 8:11 AM, Jeff Allen <ja...@fa...> wrote: > Hi Deb: > > By CPython I mean the implementation of the Python language written in C, > which is the one most people mean when they just say "Python". > > Do not put the copy of the standard library that comes with CPython on the > path for Jython. It may seem to work, but then bizarre things start to > happen and no-one can help you. Jython has its own copy with many small > adaptations, which (for you) is in the standalone JAR and need not be > extracted. > > You probably don't need python.home. It is as easy as this to run Jython > (in an empty directory that I just created): > > PS here> java -cp "C:\Jython\2.7.1-sa\jython-standalone-2.7.1.jar" org.python.util.jython > Jython 2.7.1 (default:0df7adb1b397, Jun 30 2017, 19:02:43) > [Java HotSpot(TM) 64-Bit Server VM (Oracle Corporation)] on java1.7.0_60 > Type "help", "copyright", "credits" or "license" for more information. > >>> import sys, colorsys > >>> sys.path > ['', 'C:\\Jython\\2.7.1-sa\\Lib', 'C:\\Jython\\2.7.1-sa\\jython-standalone-2.7.1.jar\\Lib', '__classpath__', '__pyclasspath__/', 'C:\\Users\\Jeff\\.local\\lib\\jython2.7\\site-packages'] > > I'm not sure why we have the second entry as well as the third on the path > in this case as the library is in the JAR: > > >>> colorsys.__file__ > 'C:\\Jython\\2.7.1-sa\\*jython-standalone-2.7.1.jar**\\Lib\\*colorsys.py' > >>> exit() > > Now, if I define python.home to a folder that contains an alternate > library: > > PS here> java "-Dpython.home=..\271-sa" -cp "C:\Jython\2.7.1-sa\jython-standalone-2.7.1.jar" org.python.util.jython > Jython 2.7.1 (default:0df7adb1b397, Jun 30 2017, 19:02:43) > [Java HotSpot(TM) 64-Bit Server VM (Oracle Corporation)] on java1.7.0_60 > Type "help", "copyright", "credits" or "license" for more information. > >>> import sys, colorsys > >>> sys.path > ['', 'C:\\Users\\Jeff\\Documents\\Jython\\271-sa\\Lib', 'C:\\Jython\\2.7.1-sa\\jython-standalone-2.7.1.jar\\Lib', '__classpath__', '__pyclasspath__/', 'C:\\Users\\Jeff\\.local\\lib\\jython2.7\\site-packages', 'C:\\Users\\Jeff\\Documents\\Jython\\271-sa\\Lib\\site-packages'] > >>> colorsys.__file__ > 'C:\\Users\\Jeff\\Documents\\Jython\\271-sa\\Lib\\colorsys.py' > > You see that Jython has looked there first and found the colorsys module. > > It's always worth exploring Python at the prompt first, but I'm aware you > want to call interpreters from Java. I'm pretty sure argv is just: > > PyList argv = pyInterpreter.getSystemState().argv; > > This will be a copy of the default you supplied, that you can manipulate > as you wish. > > Jeff > > Jeff Allen > > On 12/08/2018 10:53, Debashish wrote: > > Sorry, I got confused by the term CPython, I guess if I have Python > installed its already CPython that I am using :) So the first bullet in my > reply should only read that "Indeed I set *python.home* to my local > CPython installation". And that worked (somehow). > > On Sun, 12 Aug 2018 at 15:11, Debashish <deb...@gm...> wrote: > >> Hi Jeff, Adam, >> >> Thanks a ton for the prompt reply. Few clarifications: >> >> 1. The *python.home* path I gave is the *local* Python 2.7 >> installation path. I assume you are saying this should be *CPython* >> home rather. I will try this after installing CPython locally. >> 2. The problem is that I wish to deploy my code on Pivotal Cloud >> Foundry (PCF) where I would not be able to install anything else apart from >> the application JAR, no file-system access is available as since the code >> runs inside PCF containers, I cannot expect Python or CPython to be >> installed on that system. >> 3. I tried several thing to make it work (for e.g. extracted the *Lib* >> folder from the JAR and added it on the classpath, also renamed the JAR to >> *jython.jar* and added it to classpath, supplied the Lib folder path >> as *python.path* as well), none of these worked. It seems if there is >> no way to supply the absolute path, then there is no way to make it work >> from within a Java JAR. >> 4. My Python script is current 400 LOCs and will keep on growing, so >> I cannot possibly call its *functions* from my Java code as it would >> couple it to the Python code. I guess the only better option would be to >> port this Python code to Java. >> 5. I am using Jython Standalone JAR 2.7.1 from Maven central. I think >> what you are saying is that instead of passing command line arguments >> (argv) to the static *initialize* method I can pass it to the >> *PythonInterpreter* object rather. I am not sure how, as I do not >> such any such method in the API. Is there a code example available? >> >> Thanks again for your help. >> >> Deb >> >> On Sun, 12 Aug 2018 at 03:26, Adam Burke <ada...@gm...> wrote: >> >>> Hi Deb >>> >>> On top of that, depending on how the script you’re calling is written, >>> it might be useful to call one layer down instead of using I/O. Jython lets >>> you work with python objects fairly directly from Java, and call Python >>> functions directly as well. So if your python script has internal functions >>> and classes, you could call straight into them. >>> >>> YMMV. >>> >>> Adam >>> >>> > 在 2018年8月12日,上午7:41,Jeff Allen <ja...@fa...> 写道: >>> > >>> > I don't know anything about Spring Boot, but the standalone JAR must >>> be on your path for you to be able to refer to "PythonInterpreter" in your >>> code. So by "not detected" I guess you mean that Jython appear not to find >>> its library (which is in the standalone JAR). Jython guesses based on the >>> path to the JAR it seems to be running from (that org.python.core.Py >>> was loaded from) but telling it is safer. >>> > >>> > This bit struck me as odd: >>> > >>> > props.put("python.home", "C:\\Dev\\Python27"); >>> > >>> > That's not the location of CPython is it? That would cause you a world >>> of confusion. >>> > >>> > However, none of that addresses your question about argv (meaning >>> sys.argv I suppose). The important observation here is that >>> "PythonInterpreter.initialize" is a static method that sets a default argv >>> that all interpreters will see as they are created. It makes a big >>> difference now what version you are using. In 2.7.0, all interpreters were >>> really the same interpreter: you got a separate namespace for your main, >>> but the modules where all the same, in particular every interpreter shared >>> sys. In 2.7.1, each interpreter gets its own sys, and so each module used >>> is loaded again for each interpreter. >>> > >>> > I cannot say off the top of my head what the behaviour of the default >>> argv and sys.argv is, but I'm pretty sure the interpreter you make in the >>> next line has its own sys and the sys.argv you could set independently, >>> although not in the constructor. >>> > >>> > Jeff Allen >>> > >>> >> On 11/08/2018 20:16, Debashish wrote: >>> >> Hi, >>> >> >>> >> I am trying to call a Python Script from a Spring Boot applications. >>> There are two issues I am facing: >>> >> (1) The Jython Standalone JAR is not detected and I am forced to >>> supply the local install path as "python.home" to make it work. >>> >> (2) Once I initialize the /PythonInterpreter/ class, it seems it >>> caches the argv I supply to it as for the subsequent invocation it uses the >>> same argv values. I do call the close() method to do cleanup, but it >>> doesn't help :( >>> >> >>> >> Properties preprops = System.getProperties(); >>> >> Properties props = new Properties(); >>> >> >>> >> props.put("python.home", "C:\\Dev\\Python27"); >>> >> props.put("python.console.encoding", "UTF-8"); >>> >> props.put("python.security.respectJavaAccessibility", "false"); >>> >> props.put("python.import.site", "false"); >>> >> >>> >> PythonInterpreter.initialize(preprops, props, arguments); >>> >> PythonInterpreter pyInterpreter = new PythonInterpreter(); >>> >> >>> >> try { >>> >> resource = new ClassPathResource("mypyscript.py"); >>> >> out = new ByteArrayOutputStream(); >>> >> err = new ByteArrayOutputStream(); >>> >> pyInterpreter.setOut(out); >>> >> pyInterpreter.setErr(err); >>> >> pyInterpreter.execfile(resource.getInputStream()); >>> >> result[0] = out.toString(); // reading the output >>> >> result[1] = err.toString(); // reading any error >>> >> } catch (Exception e) { >>> >> throw new Exception(e); >>> >> } finally { >>> >> try { >>> >> if (out != null) >>> >> out.close(); >>> >> if (err != null) >>> >> err.close(); >>> >> pyInterpreter.close(); >>> >> } catch (IOException e) { >>> >> e.printStackTrace(); >>> >> } >>> >> } >>> >> >>> >> Please help. >>> >> >>> >> Thanks, >>> >> >>> >> Deb >>> >> >>> >> >>> >> ------------------------------------------------------------ >>> ------------------ >>> >> 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 >>> >> Jyt...@li... >>> >> https://lists.sourceforge.net/lists/listinfo/jython-users >>> > >>> > >>> > ------------------------------------------------------------ >>> ------------------ >>> > 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 >>> > Jyt...@li... >>> > https://lists.sourceforge.net/lists/listinfo/jython-users >>> >>> ------------------------------------------------------------ >>> ------------------ >>> 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 >>> Jyt...@li... >>> https://lists.sourceforge.net/lists/listinfo/jython-users >>> >> > > ------------------------------------------------------------ > ------------------ > 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 > Jyt...@li... > https://lists.sourceforge.net/lists/listinfo/jython-users > > |
From: Jeff A. <ja...@fa...> - 2018-08-12 13:11:56
|
Hi Deb: By CPython I mean the implementation of the Python language written in C, which is the one most people mean when they just say "Python". Do not put the copy of the standard library that comes with CPython on the path for Jython. It may seem to work, but then bizarre things start to happen and no-one can help you. Jython has its own copy with many small adaptations, which (for you) is in the standalone JAR and need not be extracted. You probably don't need python.home. It is as easy as this to run Jython (in an empty directory that I just created): PS here> java -cp "C:\Jython\2.7.1-sa\jython-standalone-2.7.1.jar" org.python.util.jython Jython 2.7.1 (default:0df7adb1b397, Jun 30 2017, 19:02:43) [Java HotSpot(TM) 64-Bit Server VM (Oracle Corporation)] on java1.7.0_60 Type "help", "copyright", "credits" or "license" for more information. >>> import sys, colorsys >>> sys.path ['', 'C:\\Jython\\2.7.1-sa\\Lib', 'C:\\Jython\\2.7.1-sa\\jython-standalone-2.7.1.jar\\Lib', '__classpath__', '__pyclasspath__/', 'C:\\Users\\Jeff\\.local\\lib\\jython2.7\\site-packages'] I'm not sure why we have the second entry as well as the third on the path in this case as the library is in the JAR: >>> colorsys.__file__ 'C:\\Jython\\2.7.1-sa\\*jython-standalone-2.7.1.jar**\\Lib\\*colorsys.py' >>> exit() Now, if I define python.home to a folder that contains an alternate library: PS here> java "-Dpython.home=..\271-sa" -cp "C:\Jython\2.7.1-sa\jython-standalone-2.7.1.jar" org.python.util.jython Jython 2.7.1 (default:0df7adb1b397, Jun 30 2017, 19:02:43) [Java HotSpot(TM) 64-Bit Server VM (Oracle Corporation)] on java1.7.0_60 Type "help", "copyright", "credits" or "license" for more information. >>> import sys, colorsys >>> sys.path ['', 'C:\\Users\\Jeff\\Documents\\Jython\\271-sa\\Lib', 'C:\\Jython\\2.7.1-sa\\jython-standalone-2.7.1.jar\\Lib', '__classpath__', '__pyclasspath__/', 'C:\\Users\\Jeff\\.local\\lib\\jython2.7\\site-packages', 'C:\\Users\\Jeff\\Documents\\Jython\\271-sa\\Lib\\site-packages'] >>> colorsys.__file__ 'C:\\Users\\Jeff\\Documents\\Jython\\271-sa\\Lib\\colorsys.py' You see that Jython has looked there first and found the colorsys module. It's always worth exploring Python at the prompt first, but I'm aware you want to call interpreters from Java. I'm pretty sure argv is just: PyList argv = pyInterpreter.getSystemState().argv; This will be a copy of the default you supplied, that you can manipulate as you wish. Jeff Jeff Allen On 12/08/2018 10:53, Debashish wrote: > Sorry, I got confused by the term CPython, I guess if I have Python > installed its already CPython that I am using :) So the first bullet > in my reply should only read that "Indeed I set /python.home/ to my > local CPython installation". And that worked (somehow). > > On Sun, 12 Aug 2018 at 15:11, Debashish <deb...@gm... > <mailto:deb...@gm...>> wrote: > > Hi Jeff, Adam, > > Thanks a ton for the prompt reply. Few clarifications: > > 1. The /python.home/ path I gave is the /local/ Python 2.7 > installation path. I assume you are saying this should be > /CPython/ home rather. I will try this after installing > CPython locally. > 2. The problem is that I wish to deploy my code on Pivotal Cloud > Foundry (PCF) where I would not be able to install anything > else apart from the application JAR, no file-system access is > available as since the code runs inside PCF containers, I > cannot expect Python or CPython to be installed on that system. > 3. I tried several thing to make it work (for e.g. extracted the > /Lib/ folder from the JAR and added it on the classpath, also > renamed the JAR to /jython.jar/ and added it to classpath, > supplied the Lib folder path as /python.path/ as well), none > of these worked. It seems if there is no way to supply the > absolute path, then there is no way to make it work from > within a Java JAR. > 4. My Python script is current 400 LOCs and will keep on growing, > so I cannot possibly call its /functions/ from my Java code as > it would couple it to the Python code. I guess the only better > option would be to port this Python code to Java. > 5. I am using Jython Standalone JAR 2.7.1 from Maven central. I > think what you are saying is that instead of passing command > line arguments (argv) to the static /initialize/ method I can > pass it to the /PythonInterpreter/ object rather. I am not > sure how, as I do not such any such method in the API. Is > there a code example available? > > Thanks again for your help. > > Deb > > On Sun, 12 Aug 2018 at 03:26, Adam Burke <ada...@gm... > <mailto:ada...@gm...>> wrote: > > Hi Deb > > On top of that, depending on how the script you’re calling is > written, it might be useful to call one layer down instead of > using I/O. Jython lets you work with python objects fairly > directly from Java, and call Python functions directly as > well. So if your python script has internal functions and > classes, you could call straight into them. > > YMMV. > > Adam > > > 在 2018年8月12日,上午7:41,Jeff Allen <ja...@fa... > <mailto:ja...@fa...>> 写道: > > > > I don't know anything about Spring Boot, but the standalone > JAR must be on your path for you to be able to refer to > "PythonInterpreter" in your code. So by "not detected" I guess > you mean that Jython appear not to find its library (which is > in the standalone JAR). Jython guesses based on the path to > the JAR it seems to be running from (that org.python.core.Py > <http://org.python.core.Py> was loaded from) but telling it is > safer. > > > > This bit struck me as odd: > > > > props.put("python.home", "C:\\Dev\\Python27"); > > > > That's not the location of CPython is it? That would cause > you a world of confusion. > > > > However, none of that addresses your question about argv > (meaning sys.argv I suppose). The important observation here > is that "PythonInterpreter.initialize" is a static method that > sets a default argv that all interpreters will see as they are > created. It makes a big difference now what version you are > using. In 2.7.0, all interpreters were really the same > interpreter: you got a separate namespace for your main, but > the modules where all the same, in particular every > interpreter shared sys. In 2.7.1, each interpreter gets its > own sys, and so each module used is loaded again for each > interpreter. > > > > I cannot say off the top of my head what the behaviour of > the default argv and sys.argv is, but I'm pretty sure the > interpreter you make in the next line has its own sys and the > sys.argv you could set independently, although not in the > constructor. > > > > Jeff Allen > > > >> On 11/08/2018 20:16, Debashish wrote: > >> Hi, > >> > >> I am trying to call a Python Script from a Spring Boot > applications. There are two issues I am facing: > >> (1) The Jython Standalone JAR is not detected and I am > forced to supply the local install path as "python.home" to > make it work. > >> (2) Once I initialize the /PythonInterpreter/ class, it > seems it caches the argv I supply to it as for the subsequent > invocation it uses the same argv values. I do call the close() > method to do cleanup, but it doesn't help :( > >> > >> Properties preprops = System.getProperties(); > >> Properties props = new Properties(); > >> > >> props.put("python.home", "C:\\Dev\\Python27"); > >> props.put("python.console.encoding", "UTF-8"); > >> props.put("python.security.respectJavaAccessibility", "false"); > >> props.put("python.import.site", "false"); > >> > >> PythonInterpreter.initialize(preprops, props, arguments); > >> PythonInterpreter pyInterpreter = new PythonInterpreter(); > >> > >> try { > >> resource = new ClassPathResource("mypyscript.py"); > >> out = new ByteArrayOutputStream(); > >> err = new ByteArrayOutputStream(); > >> pyInterpreter.setOut(out); > >> pyInterpreter.setErr(err); > >> pyInterpreter.execfile(resource.getInputStream()); > >> result[0] = out.toString(); // reading the output > >> result[1] = err.toString(); // reading any error > >> } catch (Exception e) { > >> throw new Exception(e); > >> } finally { > >> try { > >> if (out != null) > >> out.close(); > >> if (err != null) > >> err.close(); > >> pyInterpreter.close(); > >> } catch (IOException e) { > >> e.printStackTrace(); > >> } > >> } > >> > >> Please help. > >> > >> Thanks, > >> > >> Deb > >> > >> > >> > ------------------------------------------------------------------------------ > >> 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 > >> Jyt...@li... > <mailto:Jyt...@li...> > >> https://lists.sourceforge.net/lists/listinfo/jython-users > > > > > > > ------------------------------------------------------------------------------ > > 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 > > Jyt...@li... > <mailto:Jyt...@li...> > > https://lists.sourceforge.net/lists/listinfo/jython-users > > ------------------------------------------------------------------------------ > 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 > Jyt...@li... > <mailto:Jyt...@li...> > https://lists.sourceforge.net/lists/listinfo/jython-users > |
From: Debashish <deb...@gm...> - 2018-08-12 09:53:49
|
Sorry, I got confused by the term CPython, I guess if I have Python installed its already CPython that I am using :) So the first bullet in my reply should only read that "Indeed I set *python.home* to my local CPython installation". And that worked (somehow). On Sun, 12 Aug 2018 at 15:11, Debashish <deb...@gm...> wrote: > Hi Jeff, Adam, > > Thanks a ton for the prompt reply. Few clarifications: > > 1. The *python.home* path I gave is the *local* Python 2.7 > installation path. I assume you are saying this should be *CPython* > home rather. I will try this after installing CPython locally. > 2. The problem is that I wish to deploy my code on Pivotal Cloud > Foundry (PCF) where I would not be able to install anything else apart from > the application JAR, no file-system access is available as since the code > runs inside PCF containers, I cannot expect Python or CPython to be > installed on that system. > 3. I tried several thing to make it work (for e.g. extracted the *Lib* > folder from the JAR and added it on the classpath, also renamed the JAR to > *jython.jar* and added it to classpath, supplied the Lib folder path > as *python.path* as well), none of these worked. It seems if there is > no way to supply the absolute path, then there is no way to make it work > from within a Java JAR. > 4. My Python script is current 400 LOCs and will keep on growing, so I > cannot possibly call its *functions* from my Java code as it would > couple it to the Python code. I guess the only better option would be to > port this Python code to Java. > 5. I am using Jython Standalone JAR 2.7.1 from Maven central. I think > what you are saying is that instead of passing command line arguments > (argv) to the static *initialize* method I can pass it to the > *PythonInterpreter* object rather. I am not sure how, as I do not such > any such method in the API. Is there a code example available? > > Thanks again for your help. > > Deb > > On Sun, 12 Aug 2018 at 03:26, Adam Burke <ada...@gm...> wrote: > >> Hi Deb >> >> On top of that, depending on how the script you’re calling is written, it >> might be useful to call one layer down instead of using I/O. Jython lets >> you work with python objects fairly directly from Java, and call Python >> functions directly as well. So if your python script has internal functions >> and classes, you could call straight into them. >> >> YMMV. >> >> Adam >> >> > 在 2018年8月12日,上午7:41,Jeff Allen <ja...@fa...> 写道: >> > >> > I don't know anything about Spring Boot, but the standalone JAR must be >> on your path for you to be able to refer to "PythonInterpreter" in your >> code. So by "not detected" I guess you mean that Jython appear not to find >> its library (which is in the standalone JAR). Jython guesses based on the >> path to the JAR it seems to be running from (that org.python.core.Py was >> loaded from) but telling it is safer. >> > >> > This bit struck me as odd: >> > >> > props.put("python.home", "C:\\Dev\\Python27"); >> > >> > That's not the location of CPython is it? That would cause you a world >> of confusion. >> > >> > However, none of that addresses your question about argv (meaning >> sys.argv I suppose). The important observation here is that >> "PythonInterpreter.initialize" is a static method that sets a default argv >> that all interpreters will see as they are created. It makes a big >> difference now what version you are using. In 2.7.0, all interpreters were >> really the same interpreter: you got a separate namespace for your main, >> but the modules where all the same, in particular every interpreter shared >> sys. In 2.7.1, each interpreter gets its own sys, and so each module used >> is loaded again for each interpreter. >> > >> > I cannot say off the top of my head what the behaviour of the default >> argv and sys.argv is, but I'm pretty sure the interpreter you make in the >> next line has its own sys and the sys.argv you could set independently, >> although not in the constructor. >> > >> > Jeff Allen >> > >> >> On 11/08/2018 20:16, Debashish wrote: >> >> Hi, >> >> >> >> I am trying to call a Python Script from a Spring Boot applications. >> There are two issues I am facing: >> >> (1) The Jython Standalone JAR is not detected and I am forced to >> supply the local install path as "python.home" to make it work. >> >> (2) Once I initialize the /PythonInterpreter/ class, it seems it >> caches the argv I supply to it as for the subsequent invocation it uses the >> same argv values. I do call the close() method to do cleanup, but it >> doesn't help :( >> >> >> >> Properties preprops = System.getProperties(); >> >> Properties props = new Properties(); >> >> >> >> props.put("python.home", "C:\\Dev\\Python27"); >> >> props.put("python.console.encoding", "UTF-8"); >> >> props.put("python.security.respectJavaAccessibility", "false"); >> >> props.put("python.import.site", "false"); >> >> >> >> PythonInterpreter.initialize(preprops, props, arguments); >> >> PythonInterpreter pyInterpreter = new PythonInterpreter(); >> >> >> >> try { >> >> resource = new ClassPathResource("mypyscript.py"); >> >> out = new ByteArrayOutputStream(); >> >> err = new ByteArrayOutputStream(); >> >> pyInterpreter.setOut(out); >> >> pyInterpreter.setErr(err); >> >> pyInterpreter.execfile(resource.getInputStream()); >> >> result[0] = out.toString(); // reading the output >> >> result[1] = err.toString(); // reading any error >> >> } catch (Exception e) { >> >> throw new Exception(e); >> >> } finally { >> >> try { >> >> if (out != null) >> >> out.close(); >> >> if (err != null) >> >> err.close(); >> >> pyInterpreter.close(); >> >> } catch (IOException e) { >> >> e.printStackTrace(); >> >> } >> >> } >> >> >> >> Please help. >> >> >> >> Thanks, >> >> >> >> Deb >> >> >> >> >> >> >> ------------------------------------------------------------------------------ >> >> 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 >> >> Jyt...@li... >> >> https://lists.sourceforge.net/lists/listinfo/jython-users >> > >> > >> > >> ------------------------------------------------------------------------------ >> > 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 >> > Jyt...@li... >> > https://lists.sourceforge.net/lists/listinfo/jython-users >> >> >> ------------------------------------------------------------------------------ >> 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 >> Jyt...@li... >> https://lists.sourceforge.net/lists/listinfo/jython-users >> > |
From: Debashish <deb...@gm...> - 2018-08-12 09:41:46
|
Hi Jeff, Adam, Thanks a ton for the prompt reply. Few clarifications: 1. The *python.home* path I gave is the *local* Python 2.7 installation path. I assume you are saying this should be *CPython* home rather. I will try this after installing CPython locally. 2. The problem is that I wish to deploy my code on Pivotal Cloud Foundry (PCF) where I would not be able to install anything else apart from the application JAR, no file-system access is available as since the code runs inside PCF containers, I cannot expect Python or CPython to be installed on that system. 3. I tried several thing to make it work (for e.g. extracted the *Lib* folder from the JAR and added it on the classpath, also renamed the JAR to *jython.jar* and added it to classpath, supplied the Lib folder path as *python.path* as well), none of these worked. It seems if there is no way to supply the absolute path, then there is no way to make it work from within a Java JAR. 4. My Python script is current 400 LOCs and will keep on growing, so I cannot possibly call its *functions* from my Java code as it would couple it to the Python code. I guess the only better option would be to port this Python code to Java. 5. I am using Jython Standalone JAR 2.7.1 from Maven central. I think what you are saying is that instead of passing command line arguments (argv) to the static *initialize* method I can pass it to the *PythonInterpreter* object rather. I am not sure how, as I do not such any such method in the API. Is there a code example available? Thanks again for your help. Deb On Sun, 12 Aug 2018 at 03:26, Adam Burke <ada...@gm...> wrote: > Hi Deb > > On top of that, depending on how the script you’re calling is written, it > might be useful to call one layer down instead of using I/O. Jython lets > you work with python objects fairly directly from Java, and call Python > functions directly as well. So if your python script has internal functions > and classes, you could call straight into them. > > YMMV. > > Adam > > > 在 2018年8月12日,上午7:41,Jeff Allen <ja...@fa...> 写道: > > > > I don't know anything about Spring Boot, but the standalone JAR must be > on your path for you to be able to refer to "PythonInterpreter" in your > code. So by "not detected" I guess you mean that Jython appear not to find > its library (which is in the standalone JAR). Jython guesses based on the > path to the JAR it seems to be running from (that org.python.core.Py was > loaded from) but telling it is safer. > > > > This bit struck me as odd: > > > > props.put("python.home", "C:\\Dev\\Python27"); > > > > That's not the location of CPython is it? That would cause you a world > of confusion. > > > > However, none of that addresses your question about argv (meaning > sys.argv I suppose). The important observation here is that > "PythonInterpreter.initialize" is a static method that sets a default argv > that all interpreters will see as they are created. It makes a big > difference now what version you are using. In 2.7.0, all interpreters were > really the same interpreter: you got a separate namespace for your main, > but the modules where all the same, in particular every interpreter shared > sys. In 2.7.1, each interpreter gets its own sys, and so each module used > is loaded again for each interpreter. > > > > I cannot say off the top of my head what the behaviour of the default > argv and sys.argv is, but I'm pretty sure the interpreter you make in the > next line has its own sys and the sys.argv you could set independently, > although not in the constructor. > > > > Jeff Allen > > > >> On 11/08/2018 20:16, Debashish wrote: > >> Hi, > >> > >> I am trying to call a Python Script from a Spring Boot applications. > There are two issues I am facing: > >> (1) The Jython Standalone JAR is not detected and I am forced to supply > the local install path as "python.home" to make it work. > >> (2) Once I initialize the /PythonInterpreter/ class, it seems it caches > the argv I supply to it as for the subsequent invocation it uses the same > argv values. I do call the close() method to do cleanup, but it doesn't > help :( > >> > >> Properties preprops = System.getProperties(); > >> Properties props = new Properties(); > >> > >> props.put("python.home", "C:\\Dev\\Python27"); > >> props.put("python.console.encoding", "UTF-8"); > >> props.put("python.security.respectJavaAccessibility", "false"); > >> props.put("python.import.site", "false"); > >> > >> PythonInterpreter.initialize(preprops, props, arguments); > >> PythonInterpreter pyInterpreter = new PythonInterpreter(); > >> > >> try { > >> resource = new ClassPathResource("mypyscript.py"); > >> out = new ByteArrayOutputStream(); > >> err = new ByteArrayOutputStream(); > >> pyInterpreter.setOut(out); > >> pyInterpreter.setErr(err); > >> pyInterpreter.execfile(resource.getInputStream()); > >> result[0] = out.toString(); // reading the output > >> result[1] = err.toString(); // reading any error > >> } catch (Exception e) { > >> throw new Exception(e); > >> } finally { > >> try { > >> if (out != null) > >> out.close(); > >> if (err != null) > >> err.close(); > >> pyInterpreter.close(); > >> } catch (IOException e) { > >> e.printStackTrace(); > >> } > >> } > >> > >> Please help. > >> > >> Thanks, > >> > >> Deb > >> > >> > >> > ------------------------------------------------------------------------------ > >> 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 > >> Jyt...@li... > >> https://lists.sourceforge.net/lists/listinfo/jython-users > > > > > > > ------------------------------------------------------------------------------ > > 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 > > Jyt...@li... > > https://lists.sourceforge.net/lists/listinfo/jython-users > > > ------------------------------------------------------------------------------ > 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 > Jyt...@li... > https://lists.sourceforge.net/lists/listinfo/jython-users > |