[Python.NET] Python.NET and VS2010/.NET 4.0

Tribble, Brett btribble at ea.com
Tue Feb 8 22:10:50 CET 2011


Has anyone been able to get this working on Windows 7 as 64 bit “all the way down”?
I’m about to have this thrown on my plate I think…

From: pythondotnet-bounces+btribble=ea.com at python.org [mailto:pythondotnet-bounces+btribble=ea.com at python.org] On Behalf Of Oleksii Bidiuk
Sent: Tuesday, February 08, 2011 7:50 AM
To: Bart Jonkers
Cc: pythondotnet at python.org
Subject: Re: [Python.NET] Python.NET and VS2010/.NET 4.0

Hi Bart,

thanks for sharing the results! Indeed, you have to make sure the complete stack is compiled for the same platform. I hope this will help other people as well!
2011/2/8 Bart Jonkers <jonkersbart at gmail.com<mailto:jonkersbart at gmail.com>>
Hi Oleskii,

I was able to solve the issue.

I had to change the Platform target to x86 instead of Any CPU for
every project in the solution.

It seems that Any CPU will result in an executable that will run as
64-bit application on a 64-bit system and as 32-bit on a 32-bit
system.
As I have a 64-bit system and have the 32-bit version of python
installed it will not load the python dll.

By forcing a 32 - bit build the python executable was able to load the
python dll.

Thanks for your support,
Bart

On Tue, Feb 8, 2011 at 2:34 PM, Oleksii Bidiuk <oleksii.bidiuk at gmail.com<mailto:oleksii.bidiuk at gmail.com>> wrote:
> Hi Bart,
>
> I am no way an expert on this question, but it seem that your PythonNET is
> trying to load a different version of runtime than the one he was compiled
> against. You need to make sure the same runtime is built and used for
> python.exe. To make sure the 4.0 is used, you can create / edit the
> python.exe.config file (located in the same folder from where you start the
> newly compiled python.exe) with the following contents
> <?xml version="1.0"?>
> <configuration>
> <startup useLegacyV2RuntimeActivationPolicy="true">
> <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
> </startup>
> </configuration>
> This will make sure the 4.0 is loaded (search
> on useLegacyV2RuntimeActivationPolicy for more info, normally 2.0 will be
> loaded).
> If the above does not help here are a few questions that may point further
> direction:
> - Have you compiled for 32 or 64 bits (there is an .il for 64 bits, but I
> haven't tried it myself)?
> - Which version of runtime (2.0, 3.0/3.5, 4.0; x32 or x64 bits) do you have
> installed?
> - Do you start on the same machine where your development environment is
> started or in a separate environment?
> Regarding the startup time, do you experience slow start of pythonNET
> version one time or every time it is started? I can imagine it is slow the
> first time (as it has to load CLR), but the consequent starts have to be
> reasonably fast.
> 2011/2/8 Bart Jonkers <jonkersbart at gmail.com<mailto:jonkersbart at gmail.com>>
>>
>> Hi Oleskii,
>>
>> Thanks for the quick response.
>>
>> I searched on my system for the python26.dll and I found it in
>> C:\Windows\SysWOW64.
>> I copied it to c:\windows\system32\ and now I'm getting the following
>> error:
>>
>> Unhandled Exception: System.BadImageFormatException: An attempt was made
>> to load
>>  a program with an incorrect format. (Exception from HRESULT: 0x8007000B)
>>   at Python.Runtime.Runtime.Py_Initialize()
>>   at Python.Runtime.Runtime.Initialize()
>>   at Python.Runtime.PythonEngine.Initialize()
>>   at Python.Runtime.PythonConsole.Main(String[] args)
>>
>> Anny idea?
>>
>> I have installed python 2.6.6 (32-bit) on a 64-bit version of Windows 7.
>>
>> The problem that we have with the .NET version of python.exe is that
>> it takes some time before it starts.
>> As we use python in our build environment, it significantly slows down
>> our build process.
>>
>> Regards,
>> Bart
>>
>> On Tue, Feb 8, 2011 at 11:08 AM, Oleksii Bidiuk
>> <oleksii.bidiuk at gmail.com<mailto:oleksii.bidiuk at gmail.com>> wrote:
>> > Hi Bart,
>> > the python26.dll is installed to the c:\windows\system32\ folder
>> > regardless
>> > of where your main Python installation goes to. I've seen similar
>> > problem
>> > when I have copied the Python26 folder to a new machine and forgot to
>> > take
>> > the python26.dll along. Check if you have the python26.dll in place and
>> > make
>> > sure you use the newly built python.exe interpreter.
>> >
>> > It is indeed recommended to use the python.exe compiled with PythonNET
>> > as it
>> > does some additional initialization (see the implementation of the
>> > Initialize() method in pythonengine.cs code).
>> > 2011/2/8 Bart Jonkers <jonkersbart at gmail.com<mailto:jonkersbart at gmail.com>>
>> >>
>> >> Hi,
>> >>
>> >> I followed the instructions from oleskii to build Python.NET for
>> >> .NET4.0.
>> >> Compilation wend fine but when I try to run python.exe I get the
>> >> following error:
>> >>
>> >> Unhandled Exception: System.DllNotFoundException: Unable to load DLL
>> >> 'python26':
>> >>  The specified module could not be found. (Exception from HRESULT:
>> >> 0x8007007E)
>> >>   at Python.Runtime.Runtime.Py_Initialize()
>> >>   at Python.Runtime.Runtime.Initialize()
>> >>   at Python.Runtime.PythonEngine.Initialize()
>> >>   at Python.Runtime.PythonConsole.Main(String[] args)
>> >>
>> >> I have installed Python in C:\Python26.
>> >> Does any one an idea?
>> >>
>> >> Is it necessary to use the python.exe build by the project or is it
>> >> also possible to use the original python executable?
>> >> When I try to use the original python executable I get the following
>> >> error:
>> >> Python 2.6.6 (r266:84297, Aug 24 2010, 18:46:32) [MSC v.1500 32 bit
>> >> (Intel)] on
>> >> win32
>> >> Type "help", "copyright", "credits" or "license" for more information.
>> >> >>> import clr
>> >> Traceback (most recent call last):
>> >>  File "<stdin>", line 1, in <module>
>> >> SystemError: dynamic module not initialized properly
>> >> >>>
>> >>
>> >> Regards,
>> >> Bart
>> >> _________________________________________________
>> >> Python.NET mailing list - PythonDotNet at python.org<mailto:PythonDotNet at python.org>
>> >> http://mail.python.org/mailman/listinfo/pythondotnet
>> >
>> >
>> >
>> > --
>> > oleksii
>> >
>
>
>
> --
> oleksii
>



--
oleksii
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/pythondotnet/attachments/20110208/2b921ec4/attachment-0001.html>


More information about the PythonDotNet mailing list