IronPython cannot import module os

2019-02-15 04:58发布

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

2条回答
甜甜的少女心
2楼-- · 2019-02-15 05:14

This must help:

import sys
sys.path.append("C:\\PythonXY\\Lib")
查看更多
孤傲高冷的网名
3楼-- · 2019-02-15 05:29

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.

查看更多
登录 后发表回答