5

Really sorry guys! But for the life of me I am nearing the breaking point of going mad trying to install Python for .NET. I read the instructions meticulously below and still can't seem to get the installation to work. I am running python on an Spyder IDE, I a have windows 7. I downloaded the files pythonnet-2.0-Beta0-clr4.0_140_py27_UCS2_x86. I found my python directory by using the following commands:

>>> import os
>>> os.getcwd()
'C:\\Users\\Jessica'

I dragged all the unziped files into the directory and tried to load CLR

>>> import clr as ccllrr

Unhandled Exception: System.BadImageFormatException: Could not load file or assembly 'clr.pyd' or one of its dependencies. This assembly is built by a runtime newer than the currently loaded runtime and cannot be loaded.
File name: 'clr.pyd'

But I keep getting this error message. What am I doing wrong? Did a miss a step somewhere?

Here are the instructions I have been following: How to install Python for .NET on Windows

and

http://pythonnet.github.io/

Community
  • 1
  • 1
jessica
  • 1,325
  • 2
  • 21
  • 35
  • 1
    From the error message and looking at that linked answer, could it be related to "Make sure no old stuff is left from PythonNET in Python installation folder (e.g. C:\Python27). In my case I had legacy clr.pyd in one of folders." –  Dec 13 '14 at 05:37
  • 1
    I don't know how to use that :( – jessica Dec 13 '14 at 05:37
  • 1
    Thanks for the suggestions Edgar, I looked in my C:\Python27 I found no clr file. – jessica Dec 13 '14 at 05:39
  • 1
    I am trying to run this program file. https://tda.codeplex.com/releases/view/111069. Problem it can be accessed only through .Net.So I thought if I installed .Net on Python I can access the data for analysis purpose. – jessica Dec 13 '14 at 05:47
  • 1
    I know I am lost, I am just trying to load data into python so I can use some of the other numrical data modules such as numpy. – jessica Dec 13 '14 at 05:49

1 Answers1

7

The short answer is that you need to install .NET Framework 4.0 or later.

I actually don't have .Net installed.

Yes you do. Windows 7 comes with .NET built in—but it normally comes with only 2.0, 3.0, and 3.5. (This question gives some info on that.) And you need 4.0.

I didn't think I need it to e installed as this module was a substitute that allowed me to use .Net through Python.

Yes, it allows you to use .NET through Python—but you still have to have .NET for it to use.


Anyway, instead of installing .NET 4.0, you could build Python for .NET from source to use .NET 3.5, or look for a version pre-built against 3.5 or 4.0. But installing .NET 4.0 is probably the simplest way to get yourself working.


How did I know you need 4.0?

Well, first, this error message:

Unhandled Exception: System.BadImageFormatException: Could not load file or assembly 'clr.pyd' or one of its dependencies. This assembly is built by a runtime newer than the currently loaded runtime and cannot be loaded.

… means the clr.pyd file is built for some newer version of .NET than the one you have. But which one? That comes from the name of the you downloaded:

pythonnet-2.0-Beta0-clr4.0_140_py27_UCS2_x86

The clr4.0 part means that it's for CLR version 4.0. If you knew that CLR (aka "Common Language Runtime") and ".NET Framework Runtime" were the same thing, this would be obvious, but most people don't actually know that unless they're already .NET programmers, so… not exactly your fault for not guessing.

Community
  • 1
  • 1
abarnert
  • 354,177
  • 51
  • 601
  • 671