3
votes

I have problem with Iron-Python Console Application in Visual Studio 2017 Community. When I tired debug/run the program by clicking F5 or execute in Python Interactive, visual Studio calls an exist message:

Traceback (most recent call last): File "d:\userdata\myAccount\my documents\visual studio 2017\Projects\IronPythonApplication3\IronPythonApplication3\ IronPythonApplication3.py", line 6, in import clr ImportError: No module named clr

Here is the code I'm running:

import sys;
print("testMsg");
print("anotherMsg");
import clr;
clr.AddReference('System.Threading')
from System.Threading import Thread
world = "world"
print('Hello ' + world)
Thread.CurrentThread.Sleep(5000)

The first two print functions call correctly.

Intelisense also casts a popup that may be missing for this module.

I saw other topics on stack-overflow, and I tired to refresh the database and remove python environments but yet to get it working.

Someone could help me find solution for this problem?

1
When searching for "no module named clr" on stackoverflow the following comes up as the top result: stackoverflow.com/a/13183325/468244 ... does that help? Do you have the IronPython runtime+interpreter installed in a way that is picked up by VS? - Simon Opelt
Yes, when i installed visual studio 2017 i also installed full support for Python. - Robert Pawlak
I had IronPython(.NET) launcher be default, but where can i find path to ironpython interpreter in visual studio directory? - Robert Pawlak
I also put into system environment variables, precisely, into PATH: C:\Program Files (x86)\Python36-32 Still doesn't work - Robert Pawlak
You won't be able to run IronPython-specific code against CPython 3.6. The path for IronPython should look like C:\Program Files (x86)\IronPython 2.7. - Simon Opelt

1 Answers

4
votes

Solution

Follow these steps:

  • Download IronPython-2.7.7.msi from this site

and install these file.

  • After this add

    C:\Program Files (x86)\IronPython 2.7

into system environment PATH variables, and restart visual studio.

  • In Solution -> IronPythonProject -> Python Environments -> add/remove python environments i marked IronPython 2.7 (64-bit) Finally program running Thanks a lot Simon Opelt

  • Change interpreter in: Solution ->IronPythonProject-> Properties -> Interpreter and set to IronPython 2.7(64-bit)

  • Refresh intelliSense database: Solution -> IronPythonProject -> PythonEnvironments -> view all python environments -> IntelliSense and click Refresh DB

Conclusion

Basic installation of IronPython in Visual Studio 2017 (and IronPython application templates) seems to be incorrect, because we need to install modules from external sources. Visual studio installation is not sufficient.