IronPython 无法导入模块操作系统

发布于 2024-09-26 21:47:04 字数 437 浏览 1 评论 0原文

所以我有一个基本的 ZIPPED IronPython(2.6 或 2.6.1),我只需解压缩,启动 ipy.exe,输入“import os”并按 Enter 键。 出现以下输出:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named os

即使我先导入 clr,它也不起作用。要做什么呢?

我用谷歌搜索过这个问题,但没有相关答案。最接近的想法是这个(但不起作用):

import clr
clr.AddReference("IronPython")
clr.AddReference("IronPython.Modules")
import os

So I have a basic ZIPPED IronPython (2.6 or 2.6.1) that I just unzip, start ipy.exe, type "import os" and hit enter.
The following output happens:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named os

It doesn't work even if I import clr first. What's it to be done ?

I've googled this issue but no relevant answer. The closest idea was this (which didn't work):

import clr
clr.AddReference("IronPython")
clr.AddReference("IronPython.Modules")
import os

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

沙沙粒小 2024-10-03 21:47:05

问题可能不是 zip 中的问题,而是操作系统模块位置中的问题。

您需要安装 CPython 并且您的脚本应该能够到达 CPython Lib 目录。为此,您可以将所有操作系统必需的文件复制到 Lib 目录下,也可以将环境变量 IRONPYTHONPATH 设置为指向 Lib > CPython 下的目录。

Likely, the problem is not the in zip, but in os module location.

You need to have CPython installed and your script should be able to reach the CPython Lib directory. To get this you can either copy all the os necessary files under your Lib directory, or you can set the environment variable IRONPYTHONPATH to point to the Lib directory below CPython.

趴在窗边数星星i 2024-10-03 21:47:05

这一定有帮助:

import sys
sys.path.append("C:\\PythonXY\\Lib")

This must help:

import sys
sys.path.append("C:\\PythonXY\\Lib")
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文