Importing CLR using IronPython

10,337

Imports in python are case sensitive (PEP 235) even on case-insensitive platforms like (in your case) Windows. (There may be ways around that, but for the sake of compatibility I would not recommend using them.)

If you change your code to the correct, lower case spelling everything should work.

import clr

If that is not the issue a wrong (non-IronPython) interpreter/implementation might be the cause. If running through python tools for Visual Studio the setting at the project properties/General/Interpreter should show IronPython... and not the standard python implementation (Python...).

Share:
10,337
XVirtusX
Author by

XVirtusX

Updated on June 04, 2022

Comments

  • XVirtusX
    XVirtusX about 2 years

    I wanted to give IronPython a try since I want to learn more about both Python and the .Net underlay. I installed last version (2.7.3) and trying to import clr, on my first line, I can't run and throws the error "No module named CLR". I googled but didn't find anything on that matter. The IronPython install is pretty much straight forward, like all windows apps commonly are, so I can't find what did I miss here. Any clues?

  • Simon Opelt
    Simon Opelt about 11 years
    Please provide a minimal code sample and information on how you are running it (e.g. through python tools for Visual Studio, through ipy.exe ...). I testes on IronPython 2.7.3 and the exception "No module named CLR" provides the module name exactly in the spelling/casing provided during import and only the all lowercase version works.
  • XVirtusX
    XVirtusX about 11 years
    I was trying to run a simple form. I installed IronPython and the latest Python Tools for VS. Here is the sample: pastebin.com/GaC9A6Sn
  • Simon Opelt
    Simon Opelt about 11 years
    Are you sure that you are using IronPython and no other python implementation (e.g. standard python.org)? Your sample works for me unless I change the project properties/General/Interpreter from IronPython to python at which point clr is obviously no longer recognized.
  • XVirtusX
    XVirtusX about 11 years
    In interpreter says its is Python 64 bits 2.7. I also have installed Active State Python. Maybe thats messing up...
  • Simon Opelt
    Simon Opelt about 11 years
    Yep. You are probably using active state's implementation. You should also see IronPython 2.7 and IronPython 64-bit 2.7 as possible options if IronPython is correctly installed.
  • XVirtusX
    XVirtusX about 11 years
    I installed IronPython and then PTVS. When I create a project, I just have the option "Python Project", it doesn't say anything about Iron Python. Will I really have to uninstall Active State to get it working? When you create a IronPython project, what references it have by default?
  • Simon Opelt
    Simon Opelt about 11 years
    You should have New Project/Templates/Other Languages/Python/IronPython Application as an option. In any case you should be able to go through Tools/Options/Python Tools/Interpreter Options and just add one if IronPython is missing as discussed here.
  • XVirtusX
    XVirtusX about 11 years