python Jython 2.5.1:“导入错误:没有名为 os 的模块”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1639294/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-11-03 22:46:01  来源:igfitidea点击:

Jython 2.5.1: "ImportError: No Module named os"

pythonimportjython

提问by Leonidas

I looked through the other posts and bug reports and couldn't figure out what's causing this. I'm using Jython 2.5.1, in a Java project in Eclipse (Ubuntu 8.10). It has been added to the project as a standalone .jar file (I just replaced the old Jython 2.1 jar with this one).

我查看了其他帖子和错误报告,但无法弄清楚是什么原因造成的。我在 Eclipse (Ubuntu 8.10) 的 Java 项目中使用 Jython 2.5.1。它已作为独立的 .jar 文件添加到项目中(我只是用这个文件替换了旧的 Jython 2.1 jar)。

I'm running a script that uses the threading.py class. At some point the statement "import os" is evaluated from linecache.py and I get this error, which I can't seem to figure out how to fix:

我正在运行一个使用 threading.py 类的脚本。在某些时候,从 linecache.py 评估语句“import os”,我收到此错误,我似乎无法弄清楚如何修复:

'Execution failed.  Traceback (most recent call last):
 File "<string>", line 1, in <module>
 File "../lib/python/threading.py", line 6, in <module>
 import traceback
 File "../lib/python/traceback.py", line 3, in <module>
 import linecache
 File "../lib/python/linecache.py", line 9, in <module>
 import os
 ImportError: No module named os'

采纳答案by jitter

What do you mean with "the jar that comes with the 2.5 download"? Did you extract the contents and use jython.jaror did you run the installer? If you just extracted and didn't run the installer your jython.jarwill miss the whole LIBfolder.

2.5下载自带的jar包什么意思?您是提取内容并使用jython.jar还是运行了安装程序?如果您刚刚解压缩并且没有运行安装程序,您jython.jar将错过整个LIB文件夹。

Can you check if jython.jarcontains a LIB folder? (e.g. open jython.jarwith 7zor WinZip).

你能检查一下是否jython.jar包含 LIB 文件夹吗?(例如,jython.jar使用7z或 WinZip打开)。

Or try copying the LIBfolder in the same folder where jython.jarresides.

或者尝试将LIB文件夹复制到jython.jar所在的同一文件夹中。



Did you try setting these properties. Jython Registry. e.g. via -Dpython.home in the eclipse run configuration.

您是否尝试设置这些属性。Jython 注册表。例如通过 -Dpython.home 在 eclipse 运行配置中。

python.cachedir
python.path
python.home

How is the jar named? If similar to jython-complete.jartry renaming it to jython.jar

罐子是怎么命名的?如果类似jython-complete.jar尝试将其重命名为jython.jar

回答by Andre Holzner

If you are getting maven, using the dependency jython-standaloneinstead of jythonmay help (at least it did for me in a maven project with jython-standalone-2.5.3)

如果您正在使用 maven,则使用依赖项jython-standalone而不是jython可能会有所帮助(至少在使用 jython-standalone-2.5.3 的 maven 项目中对我有用)

回答by Ned Batchelder

Something is wrong at a very deep level, but it's probably easy to fix. You are seeing an error that happens while trying to report some other error.

在很深的层面上出了点问题,但可能很容易修复。您看到在尝试报告其他错误时发生的错误。

Probably you have your PYTHONPATH misconfigured. I don't know the details of Jython or Eclipse running Jython, but it looks like you have no standard library available to you.

可能您的 PYTHONPATH 配置错误。我不知道运行 Jython 的 Jython 或 Eclipse 的详细信息,但看起来您没有可用的标准库。