jython.exe“2.7.0 最终版本”在我的 Windows OS 上执行失败

jython.exe "2.7.0 final release" failed execution on my Windows OS

OS: Windows 7, 64 位

Here 我了解到最新版本的 Jython(downloads/installs 为“2.7.0”)包含 "ensurepip" 模块,希望能安装 pip。

这就是我得到的...注意我的机器上没有驱动器"Z:"

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

实际上,如果我只是输入 "jython" [Return]!

,就会出现上述错误

在 readme.txt 文件中我看到了这个:

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.

我不知道 "you can use with bin/pip" 是什么意思...bin 目录(Windoze 上的 \bin)包含 2 个文件:jython.exe 和 python27.dll.

此外,我不知道如何获得 Jython 的交互式终端 运行 这个

15 分钟后 2票赞成!我没想到。我认为这可能是我在我的机器上所做的异常行为所造成的。现在我开始怀疑 Jython 团队(顺便说一句,他们是天才)是否对 Windoze 盒子不感兴趣,以至于他们只是把它打包并扔出去,根本没有在任何 Windoze 盒子上测试它!

几天后 遵循 Jim Baker 的建议:安装非常顺利。 "pip install" 工作正常!

JAVA_HOME 必须设置为 %JAVA_HOME%\bin\java.exe 是 Java 可执行文件,目标 java.exe 必须是 Java 7. 请参阅 this Jython bug.重要的是要注意该环境变量的一些其他可能设置不起作用 - 我们希望 bin\java.exe 可以连接到 JAVA_HOME(准确地说是使用 os.path.join)。此外,根据 Windows 在引用等方面的期望准确设置 JAVA_HOME 也很重要:

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

但不是

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

(完全不一样!试试看我的意思吧。)

调试这些问题的最简单方法是使用 jython --print;例如在我的系统上我得到以下信息:

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

接下来让我解释一下您看到的不透明错误。有两件事正在发生:

  1. jython.exe 实际上是 Jython 启动器;我们使用的真正的 Jython 可以在 jython --print 的输出中看到;它是 org.python.util.jython,加上一堆其他选项。但是我们需要一个 exe,这样 pip 和其他工具才能工作。在 Windows 上(或在其他 OSes 上,如果打开了分析),启动器使用子进程调用 Java 可执行文件。此子流程调用位于 line 435 of jython.py.

  2. 是的,那是 jython.py。它实际上使用 CPython 2.7(感谢围绕 CPython,我们喜欢你!),并由 PyInstaller 包装到可执行文件中。关于 "Z:\jythondev\jython27\src\shell\build\jython\out00-PYZ.pyz\subprocess" 的所有事情, 这是因为我在我的 Z: 驱动器上构建了 jython.exe,我在 VMWare 上安装的 Windows 8.1 映射了我的 OS X 主目录。 (是的,我完全负责这个构建。)接下来,out00-PYZ.pyz 指的是 PyInstaller 使用的一些内部方案。

我们需要完成我在该错误中提到的发行说明 wiki 更新!当然,还要修复该错误,以便它提供更好的错误消息,并且在某些情况下可能可以恢复。

我还安装了 Jython,但在将 JAVA_HOME 设置为 C:\Program Files\Java\jdk-10.0.2 后遇到了同样的错误。

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

jython