IronPython: import random crashes into IronPython Interactive

In Visual Studio 2010, IronPython Interactive fails to do this:

Β» import random Traceback (most recent call last): File "<string>", line 1, in <module> ImportError: No module named random 

The same thing works fine in IronPython code in Visual Studio. It also works great if I run ipy.exe inside the ipy.exe command prompt. What is the problem with IronPython Interactive and import? How to fix Python Interactive so that it can import Python modules?

sys.path in IronPython Interactive gives the following:

 Β» import sys Β» sys.path ['.', 'C:\\PROGRAM FILES (X86)\\MICROSOFT VISUAL STUDIO 10.0\\COMMON7\\IDE\\EXTENSIONS\\MICROSOFT\\IRONSTUDIO\\0.4\\Lib', 'C:\\PROGRAM FILES (X86)\\MICROSOFT VISUAL STUDIO 10.0\\COMMON7\\IDE\\EXTENSIONS\\MICROSOFT\\IRONSTUDIO\\0.4\\DLLs'] 

The sys.path in ipy.exe at the Windows command prompt gives the following:

 >>> import sys >>> sys.path ['.', 'C:\\Users\\MyName\\Desktop', 'C:\\Program Files (x86)\\IronPython 2.7\\Lib', 'C:\\Program Files (x86)\\IronPython 2.7\\DLLs', 'C:\\Program Files (x86)\\IronPython 2.7', 'C:\\Program Files (x86)\\IronPython 2.7\\lib\\site-packages'] 

I am using IronPython 2.7, Visual Studio 2010 and Windows 7 64-bit.

+6
source share
1 answer

As you can see, sys.path directories are different,
I suspect that the random module is implemented in IronPython.Modules.dll , then you should check if such a DLL is present in the paths of the IronPython interactive interface.

If he is present, the problem is different, and I do not know what could be ...

otherwise, in Ironpython interactive mode, before import random do:

 sys.path.append(path) 

with path is the IronPython.Modules.dll folder (I think C: \ Program Files (x86) \ IronPython 2.7 ') and it should work.

+5
source

Source: https://habr.com/ru/post/888735/


All Articles