Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

IronPython visual studio console app: no module named clr

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?

like image 805
Robert Pawlak Avatar asked Jun 06 '26 16:06

Robert Pawlak


1 Answers

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.

like image 164
Robert Pawlak Avatar answered Jun 09 '26 05:06

Robert Pawlak



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!