Discussion:
[Python.NET] Python.NET and VS2001/.NET 4.0
Oleksii Bidiuk
2011-01-17 16:06:16 UTC
Permalink
Hi All,

I hope this will help some people like me searching for an answer. Several
steps were mentioned by other people as well, but I haven't seen a
step-by-step guide. It is not my intention to duplicate other posts in that
sense, but rather have all-in-one post.

Here is how I've got VS2010 and .NET 4.0 working with the revision 119 of
the Python.NET having Python 2.6 installed. Note that the latest trunk
(revision 122) gave me some problems, so I have basically reverted changes
to match 119 for the time being.

1. Get the sources (tarball from sourceforge or directly from SVN)
2. Open the pythonnet.sln with VS2010 and convert to 2010 format (will
happen automagically)
3. Change the target framework to 4. Follow the following step for EACH
project
3.1. Right-click on the project name and select "Properties"
3.2. Select the "Application" tab on the left (if not selected yet)
3.3. Change the "Target framework" to ".NET Framework 4"
4. Open the clrmodule.il and change the lines with the version number in the
following piece of code

.assembly extern mscorlib { .publickeytoken = (B7 7A 5C 56 19 34 E0 89 )
.ver 2:0:0:0 }

to have

.ver 4:0:0:0

5. Open the buildclrmodule.bat and change the

%windir%\Microsoft.NET\Framework\v2.0.50727\ilasm /nologo /quiet /dll
%ILASM_EXTRA_ARGS% /include=%INCLUDE_PATH% /output=%OUTPUT_PATH%
%INPUT_PATH%

to

%windir%\Microsoft.NET\Framework\v4.0.30319\ilasm /nologo /quiet /dll
%ILASM_EXTRA_ARGS% /include=%INCLUDE_PATH% /output=%OUTPUT_PATH%
%INPUT_PATH%

5. Recompile the whole solution, ignore the deprecation warnings.

Now you have all necessary files under the pythonnet folder where you have
the sources. You need clr.pyd, python.exe and Python.Runtime.dll.

Test
Run the newly comiled python.exe
Type the following
import System >>> print System.Environment.Version 4.0.30319.1
The last line proves that you're using hte 4.0 runtime. The precomiled
binaries available from Sourceforge would show
2.0.50727.3615

This is also posted with somewhat better formatting under
blog.bidiuk.com/2011/01/python-net-and-vs2010-net-4/

Comments and suggestions are welcome!
--
oleksii
Tribble, Brett
2011-01-18 18:08:50 UTC
Permalink
Thanks Biduik,

I will need this in a few short weeks.

From: pythondotnet-bounces+btribble=***@python.org [mailto:pythondotnet-bounces+btribble=***@python.org] On Behalf Of Oleksii Bidiuk
Sent: Monday, January 17, 2011 8:06 AM
To: ***@python.org
Subject: [Python.NET] Python.NET and VS2001/.NET 4.0

Hi All,

I hope this will help some people like me searching for an answer. Several steps were mentioned by other people as well, but I haven't seen a step-by-step guide. It is not my intention to duplicate other posts in that sense, but rather have all-in-one post.

Here is how I've got VS2010 and .NET 4.0 working with the revision 119 of the Python.NET having Python 2.6 installed. Note that the latest trunk (revision 122) gave me some problems, so I have basically reverted changes to match 119 for the time being.

1. Get the sources (tarball from sourceforge or directly from SVN)
2. Open the pythonnet.sln with VS2010 and convert to 2010 format (will happen automagically)
3. Change the target framework to 4. Follow the following step for EACH project
3.1. Right-click on the project name and select "Properties"
3.2. Select the "Application" tab on the left (if not selected yet)
3.3. Change the "Target framework" to ".NET Framework 4"
4. Open the clrmodule.il<http://clrmodule.il> and change the lines with the version number in the following piece of code

.assembly extern mscorlib
{
.publickeytoken = (B7 7A 5C 56 19 34 E0 89 )
.ver 2:0:0:0
}

to have


.ver 4:0:0:0

5. Open the buildclrmodule.bat and change the

%windir%\Microsoft.NET\Framework\v2.0.50727\ilasm /nologo /quiet /dll %ILASM_EXTRA_ARGS% /include=%INCLUDE_PATH% /output=%OUTPUT_PATH% %INPUT_PATH%

to

%windir%\Microsoft.NET\Framework\v4.0.30319\ilasm /nologo /quiet /dll %ILASM_EXTRA_ARGS% /include=%INCLUDE_PATH% /output=%OUTPUT_PATH% %INPUT_PATH%

5. Recompile the whole solution, ignore the deprecation warnings.

Now you have all necessary files under the pythonnet folder where you have the sources. You need clr.pyd, python.exe and Python.Runtime.dll.

Test
Run the newly comiled python.exe
Type the following
import System >>> print System.Environment.Version 4.0.30319.1
The last line proves that you're using hte 4.0 runtime. The precomiled binaries available from Sourceforge would show
2.0.50727.3615

This is also posted with somewhat better formatting under blog.bidiuk.com/2011/01/python-net-and-vs2010-net-4/<http://blog.bidiuk.com/2011/01/python-net-and-vs2010-net-4/>

Comments and suggestions are welcome!
--
oleksii
Oleksii Bidiuk
2011-01-21 09:06:45 UTC
Permalink
Hi All,

A small correction to my post. Revision 122 seem to contain all the code,
only the reference to the constructorbinding.cs is missing in
the Python.Runtime.csproj. Simply adding a reference solves the problem!
Post by Oleksii Bidiuk
Hi All,
I hope this will help some people like me searching for an answer. Several
steps were mentioned by other people as well, but I haven't seen a
step-by-step guide. It is not my intention to duplicate other posts in that
sense, but rather have all-in-one post.
Here is how I've got VS2010 and .NET 4.0 working with the revision 119 of
the Python.NET having Python 2.6 installed. Note that the latest trunk
(revision 122) gave me some problems, so I have basically reverted changes
to match 119 for the time being.
1. Get the sources (tarball from sourceforge or directly from SVN)
2. Open the pythonnet.sln with VS2010 and convert to 2010 format (will
happen automagically)
3. Change the target framework to 4. Follow the following step for EACH
project
3.1. Right-click on the project name and select "Properties"
3.2. Select the "Application" tab on the left (if not selected yet)
3.3. Change the "Target framework" to ".NET Framework 4"
4. Open the clrmodule.il and change the lines with the version number in
the following piece of code
.assembly extern mscorlib { .publickeytoken = (B7 7A 5C 56 19 34 E0 89 )
.ver 2:0:0:0 }
to have
.ver 4:0:0:0
5. Open the buildclrmodule.bat and change the
%windir%\Microsoft.NET\Framework\v2.0.50727\ilasm /nologo /quiet /dll
%ILASM_EXTRA_ARGS% /include=%INCLUDE_PATH% /output=%OUTPUT_PATH%
%INPUT_PATH%
to
%windir%\Microsoft.NET\Framework\v4.0.30319\ilasm /nologo /quiet /dll
%ILASM_EXTRA_ARGS% /include=%INCLUDE_PATH% /output=%OUTPUT_PATH%
%INPUT_PATH%
5. Recompile the whole solution, ignore the deprecation warnings.
Now you have all necessary files under the pythonnet folder where you have
the sources. You need clr.pyd, python.exe and Python.Runtime.dll.
Test
Run the newly comiled python.exe
Type the following
import System >>> print System.Environment.Version 4.0.30319.1
The last line proves that you're using hte 4.0 runtime. The precomiled
binaries available from Sourceforge would show
2.0.50727.3615
This is also posted with somewhat better formatting under
blog.bidiuk.com/2011/01/python-net-and-vs2010-net-4/
Comments and suggestions are welcome!
--
oleksii
--
oleksii
Loading...