pythonnet - Python.NET
Python.NET is a package that gives Python programmers nearly seamless integration with the .NET Common Language Runtime (CLR) and provides a powerful application scripting tool for .NET developers. It allows Python code to interact with the CLR, and may also be used to embed Python into a .NET application.
Calling .NET code from Python
Python.NET allows CLR namespaces to be treated essentially as Python packages.
import clr
from System import String
from System.Collections import *
To load an assembly, use the AddReference function in the clr module:
import clr
clr.AddReference("System.Windows.Forms")
from System.Windows.Forms import Form
Embedding Python in .NET
All calls to python should be inside a using (Py.GIL()) {/* Your code here */} block.
Import python modules using dynamic mod = Py.Import("mod"), then you can call functions as normal, eg mod.func(args).
Use mod.func(args, Py.kw("keywordargname", keywordargvalue)) or mod.func(args, keywordargname: keywordargvalue) to apply keyword arguments.
All python objects should be declared as dynamic type.
Mathematical operations involving python and literal/managed types must have the python object first, eg. np.pi * 2 works, 2 * np.pi doesn’t.
Example
static void Main(string[] args)
{
using (Py.GIL())
{
dynamic np = Py.Import("numpy");
Console.WriteLine(np.cos(np.pi * 2));
dynamic sin = np.sin;
Console.WriteLine(sin(5));
double c = np.cos(5) + sin(5);
Console.WriteLine(c);
dynamic a = np.array(new List<float> { 1, 2, 3 });
Console.WriteLine(a.dtype);
dynamic b = np.array(new List<float> { 6, 5, 4 }, dtype: np.int32);
Console.WriteLine(b.dtype);
Console.WriteLine(a * b);
Console.ReadKey();
}
}
Output:
1.0
-0.958924274663
-0.6752620892
float64
int32
[ 6. 10. 12.]
Resources
Information on installation, FAQ, troubleshooting, debugging, and projects using pythonnet can be found in the Wiki:
.NET Foundation
This project is supported by the .NET Foundation.
Release files for pythonnet 2.5.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| pythonnet-2.5.2.tar.gz | 1.9 MB | Details |
Built distributions (wheels)
| File | Reset | |||
|---|---|---|---|---|
| pythonnet-2.5.2-cp38-cp38-win_amd64.whl | CPython 3.8 | CPython 3.8 | Windows x86-64 | Details |
| pythonnet-2.5.2-cp38-cp38-win32.whl | CPython 3.8 | CPython 3.8 | Windows x86-32 | Details |
| pythonnet-2.5.2-cp37-cp37m-win_amd64.whl | CPython 3.7 | CPython 3.7 pymalloc | Windows x86-64 | Details |
| pythonnet-2.5.2-cp37-cp37m-win32.whl | CPython 3.7 | CPython 3.7 pymalloc | Windows x86-32 | Details |
| pythonnet-2.5.2-cp36-cp36m-win_amd64.whl | CPython 3.6 | CPython 3.6 pymalloc | Windows x86-64 | Details |
| pythonnet-2.5.2-cp36-cp36m-win32.whl | CPython 3.6 | CPython 3.6 pymalloc | Windows x86-32 | Details |
| pythonnet-2.5.2-cp35-cp35m-win_amd64.whl | CPython 3.5 | CPython 3.5 pymalloc | Windows x86-64 | Details |
| pythonnet-2.5.2-cp35-cp35m-win32.whl | CPython 3.5 | CPython 3.5 pymalloc | Windows x86-32 | Details |
| pythonnet-2.5.2-cp27-cp27m-win_amd64.whl | CPython 2.7 | CPython 2.7 pymalloc | Windows x86-64 | Details |
| pythonnet-2.5.2-cp27-cp27m-win32.whl | CPython 2.7 | CPython 2.7 pymalloc | Windows x86-32 | Details |
Total release size: 2.7 MB
Release files / pythonnet-2.5.2.tar.gz
| Download URL | pythonnet-2.5.2.tar.gz |
|---|---|
| Size | 1.9 MB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
b7287480a1f6ae4b6fc80d775446d8af00e051ca1646b6cc3d32c5d3a461ede3
|
|
BLAKE2b-256 checksum How to use checksums |
f718be276f27f649199563a59561623c0c008e72bbcb6ecb8b2ca0404a741ae1
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.9.1
|
Release files / pythonnet-2.5.2-cp38-cp38-win_amd64.whl
| Download URL | pythonnet-2.5.2-cp38-cp38-win_amd64.whl |
|---|---|
| Size | 82.0 kB |
| Tags | CPython 3.8 Windows x86-64 |
|
SHA-256 checksum How to use checksums |
00a4fed9fc05b4efbe8947c79dc0799cffbca4c89e3e068e70b6618f20c906f2
|
|
BLAKE2b-256 checksum How to use checksums |
71ec3480ddb32c76376596adc66a92a398e1cecd8f58bde784a624166ba534e6
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.9.1
|
Release files / pythonnet-2.5.2-cp38-cp38-win32.whl
| Download URL | pythonnet-2.5.2-cp38-cp38-win32.whl |
|---|---|
| Size | 82.0 kB |
| Tags | CPython 3.8 Windows x86-32 |
|
SHA-256 checksum How to use checksums |
41a607b7304e9efc6d4d8db438d6018a17c6637e8b8998848ff5c2a7a1b4687c
|
|
BLAKE2b-256 checksum How to use checksums |
e2e3ae95ae2f13a453c373274c9e4a53b8e07f5dcf7d086c62004ae343f9f144
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.9.1
|
Release files / pythonnet-2.5.2-cp37-cp37m-win_amd64.whl
| Download URL | pythonnet-2.5.2-cp37-cp37m-win_amd64.whl |
|---|---|
| Size | 82.0 kB |
| Tags | CPython 3.7 CPython 3.7 pymalloc Windows x86-64 |
|
SHA-256 checksum How to use checksums |
80c8f5c9bd10440a73eb6aedbbacb2f3dd7701b474816f5ef7636f529d838d38
|
|
BLAKE2b-256 checksum How to use checksums |
63bff39afc5a487399dfe72985d793e3c5726a6bc80ebb12561b696169fcac15
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.9.1
|
Release files / pythonnet-2.5.2-cp37-cp37m-win32.whl
| Download URL | pythonnet-2.5.2-cp37-cp37m-win32.whl |
|---|---|
| Size | 82.0 kB |
| Tags | CPython 3.7 CPython 3.7 pymalloc Windows x86-32 |
|
SHA-256 checksum How to use checksums |
cc77fc63e2afb0a80199ab44ced4fdfb78c19d8030063c345c80740d15380dd9
|
|
BLAKE2b-256 checksum How to use checksums |
b9fb7cd9cf8ae8ecccec0c048223e32a569a74b9cfc43ce28288d481ee709f48
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.9.1
|
Release files / pythonnet-2.5.2-cp36-cp36m-win_amd64.whl
| Download URL | pythonnet-2.5.2-cp36-cp36m-win_amd64.whl |
|---|---|
| Size | 82.0 kB |
| Tags | CPython 3.6 CPython 3.6 pymalloc Windows x86-64 |
|
SHA-256 checksum How to use checksums |
058e536062d1585d07ec5f2cf16aefcfc8eb8179faa90e5db0063d358469d025
|
|
BLAKE2b-256 checksum How to use checksums |
0cb3e136267c9299ac5572286ccb807f4b0a6bad9b882e7ca94691004a6acc83
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.9.1
|
Release files / pythonnet-2.5.2-cp36-cp36m-win32.whl
| Download URL | pythonnet-2.5.2-cp36-cp36m-win32.whl |
|---|---|
| Size | 82.0 kB |
| Tags | CPython 3.6 CPython 3.6 pymalloc Windows x86-32 |
|
SHA-256 checksum How to use checksums |
62645c29840c4a877d66e047f3e065b2e5a1a66431a99bce8d42a5af3a093ee1
|
|
BLAKE2b-256 checksum How to use checksums |
2619978dd055028cad9e9a0b32dad8818fc6a7072954e7ad84f2b83fc1fac619
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.9.1
|
Release files / pythonnet-2.5.2-cp35-cp35m-win_amd64.whl
| Download URL | pythonnet-2.5.2-cp35-cp35m-win_amd64.whl |
|---|---|
| Size | 82.0 kB |
| Tags | CPython 3.5 CPython 3.5 pymalloc Windows x86-64 |
|
SHA-256 checksum How to use checksums |
d8e5b27de1e2cfb69b88782ac5cdf605b1a73598a85d86570e46961126628dbb
|
|
BLAKE2b-256 checksum How to use checksums |
9d8dad965cd823c781234b69db1caf9fa9d1cac93e9804bbf6dcc0eefcb79ac5
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.9.1
|
Release files / pythonnet-2.5.2-cp35-cp35m-win32.whl
| Download URL | pythonnet-2.5.2-cp35-cp35m-win32.whl |
|---|---|
| Size | 81.9 kB |
| Tags | CPython 3.5 CPython 3.5 pymalloc Windows x86-32 |
|
SHA-256 checksum How to use checksums |
840bdef89b378663d73f74f18895b6d8630d1f5671457a1db5ffb68179d85582
|
|
BLAKE2b-256 checksum How to use checksums |
cc7f6259591d9aac8d31f4c2e08d23545921fdec6a80af69f11bed5382359fbe
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.9.1
|
Release files / pythonnet-2.5.2-cp27-cp27m-win_amd64.whl
| Download URL | pythonnet-2.5.2-cp27-cp27m-win_amd64.whl |
|---|---|
| Size | 81.5 kB |
| Tags | CPython 2.7 CPython 2.7 pymalloc Windows x86-64 |
|
SHA-256 checksum How to use checksums |
c02f53d0e61b202cddf3198fac9553d5b4ee0ea0cc4fe658c2ed69ab24def276
|
|
BLAKE2b-256 checksum How to use checksums |
86e72489af5b120d8ae764af66794527efd941d749d64401a6828eb36117ee5e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.9.1
|
Release files / pythonnet-2.5.2-cp27-cp27m-win32.whl
| Download URL | pythonnet-2.5.2-cp27-cp27m-win32.whl |
|---|---|
| Size | 81.4 kB |
| Tags | CPython 2.7 CPython 2.7 pymalloc Windows x86-32 |
|
SHA-256 checksum How to use checksums |
d519bbc7b1cd3999651efc594d91cb67c46d1d8466dad3d83b578102e58d05bd
|
|
BLAKE2b-256 checksum How to use checksums |
eaa6ca8ce58d6bde0f55ab0627ae257d0c8a51769e7c1e91dc680a349193b8b2
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.9.1
|