5

OS: Windows 7, 64-bit

Here I learn that the latest version of Jython (downloads/installs as "2.7.0") includes the "ensurepip" module, which hopefully installs pip.

This is what I get... NB there is no drive "Z:" on my machine

D:\apps\jython2.7.0\bin>jython -m ensurepip
Traceback (most recent call last):
  File "<string>", line 444, in <module>
  File "<string>", line 435, in main
  File "Z:\jythondev\jython27\src\shell\build\jython\out00-PYZ.pyz\subprocess",
line 522, in call
  File "Z:\jythondev\jython27\src\shell\build\jython\out00-PYZ.pyz\subprocess",
line 710, in __init__
  File "Z:\jythondev\jython27\src\shell\build\jython\out00-PYZ.pyz\subprocess",
line 958, in _execute_child
WindowsError: [Error 2] The system cannot find the file specified

In fact I get the above error if I simply enter "jython" [Return]!

In the readme.txt file I see this:

This is the final release of the 2.7.0 version of Jython. Along with language and runtime compatibility with CPython 2.7.0, Jython 2.7 provides substantial support of the Python ecosystem. This includes built-in support of pip/setuptools (you can use with bin/pip) and a native launcher for Windows (bin/jython.exe), with the implication that you can finally install Jython scripts on Windows.

I have no idea what they mean by "you can use with bin/pip"... the bin directory (\bin on Windoze) contains 2 files: jython.exe and python27.dll.

Furthermore I don't know how to get the interactive terminal for Jython running with this

15 mins later 2 up votes! I wasn't expecting that. I thought it was likely something anomalous I had done on my machine was to blame. Now I'm beginning to wonder whether the Jython team (who are geniuses by the way) are just so uninterested in Windoze boxes that they just packaged this up and flung it out there without testing it on any Windoze boxes at all!

a few days later Followed Jim Baker's advice: perfectly smooth installation. "pip install" working fine!

Community
  • 1
  • 1
mike rodent
  • 14,126
  • 11
  • 103
  • 157
  • Have set any [environment variables](http://www.jython.org/docs/using/cmdline.html#environment-variables) which could confuse jython? – mata May 23 '15 at 08:45
  • To answer your question, no, the only env var which I can imagine to be relevant is JAVA_HOME, which points to a perfectly valid JRE. But the evidence seems to show that there is fundamentally wrong with the executable jar from jython.org. I just tried running again and extracting to another directory... even "jython --version" in the \bin dir produces the abover error. The distro just appears to be messed up. – mike rodent May 23 '15 at 08:59
  • @mata ... turned out you were right (judging by my experience)... JAVA_HOME must be pointing to the dir which contains the dir \bin with java.exe in it. Seems mine was wrong in some way! – mike rodent May 29 '15 at 15:34

3 Answers3

5

JAVA_HOME must be set such that %JAVA_HOME%\bin\java.exe is the Java executable, and the target java.exe must be Java 7. See this Jython bug. It is important to note that some other possible settings for that environment variable do not work - we expect that bin\java.exe can be joined to JAVA_HOME (using os.path.join to be precise). Also it is important to set JAVA_HOME exactly per what Windows expects in terms of quoting, etc:

set JAVA_HOME=C:\Program Files\Java\jdk1.7.0_55

but not

set JAVA_HOME="C:\Program Files\Java\jdk1.7.0_55"

(Not at all the same! Just try it to see what I mean.)

The easiest way to debug these problems is with jython --print; for example on my system I get the following:

C:\jython2.7.0>set JAVA_HOME=C:\Program Files\Java\jdk1.7.0_55 C:\jython2.7.0>bin\jython.exe --print "C:\Program Files\Java\jdk1.7.0_55\bin\java" -Xmx512m -Xss1024k -classpath C:\jython2.7.0\jython.jar;. -Dpython.home=C:\jython2.7.0 -Dpython.executable=C:\jython2.7.0\bin\jython.exe -Dpython.launcher.uname=windows -Dpython.launcher.tty=true org.python.util.jython

Let me next explain the opaque error you are seeing. There are two things going on:

  1. jython.exe is actually the Jython launcher; the real Jython we use is seen in the output of jython --print; it is org.python.util.jython, plus a bunch of other options. But we need an exe so that pip and other tooling can work. On Windows (or on other OSes if profiling for example is turned on), the launcher uses subprocess to invoke the Java executable. This subprocess invocation is in line 435 of jython.py.

  2. Yes, that's jython.py. It actually uses CPython 2.7 (thanks for being around CPython, we like you!), and is wrapped into an executable by PyInstaller. The whole thing about "Z:\jythondev\jython27\src\shell\build\jython\out00-PYZ.pyz\subprocess", is due to the fact that I built jython.exe on my Z: drive, onto which my install of Windows 8.1 on VMWare has mapped my OS X homedir. (Yes, I'm completely responsible for this build.) Next, out00-PYZ.pyz refers to some internal scheme used by PyInstaller.

We need to complete the release notes wiki update I mention on that bug! And of course fix that bug so it provides a better error message and possibly can recover in certain cases.

Jim Baker
  • 399
  • 1
  • 5
  • thanks... perfectly smooth installation, "pip install requests" worked fine. Must have been the Java path (I changed it a few days ago in connection with sthg else) ... Honoured to have this chance to say how wonderful Jython is, by the way. Could I just ask though: any chance we could please please have an official Jython forum? The mailing list is kind of clunky... is it because newbies are wont to ask repetitive and/or stupid questions so a forum is likely to be a pain? – mike rodent May 29 '15 at 15:31
  • ... and one other thing if I may (while you're here!)... my brain is extremely exercised with the question of comprehensive trapping Python Exceptions and Java Throwables... if you have a mo could you glance at this SO question I've just put up? http://stackoverflow.com/questions/30534136/trap-exceptions-comprehensively-in-jython – mike rodent May 29 '15 at 16:18
  • Mike, any details on what you mean by an official Jython forum, beyond being tagged "jython" here? I think SO is reasonably convenient, and this is a certainly an intended usage http://meta.stackexchange.com/a/133526 – Jim Baker Jun 04 '15 at 03:35
  • Jim, at the moment I am trying to understand a couple of things like how you use Maven in a Jython context, and the best approach to unit testing in a Jython context... "Forbidding" is too strong a word, but I suspect if there were a Jython forum with different levels, including newbies, you might create more converts to the best language ever. Apart from that SO works OK, yes, undoubtedly. – mike rodent Jun 06 '15 at 09:00
0

I also installed the Jython and was facing the same error after setting the JAVA_HOME to C:\Program Files\Java\jdk-10.0.2 works for me.

0

set JAVA_HOME=C:\Program Files\Java\jre1.8.0_281

jython

  • 1
    As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Nov 12 '21 at 09:42