|
1 | | -# pythonnet - Python for .NET |
| 1 | +This is just simple build fix for c# developer without much knowledge of python |
| 2 | +(based on [amos's fork of python.net](https://github.com/amos402/pythonnet) which is believed memory leak issues have been resolved) |
2 | 3 |
|
3 | | -[](https://gitter.im/pythonnet/pythonnet?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) |
| 4 | +# How To Get Python.Runtime.dll(Either DEBUG/RELEASE) |
4 | 5 |
|
5 | | -[![appveyor shield][]](https://ci.appveyor.com/project/pythonnet/pythonnet/branch/master) |
6 | | -[![travis shield][]](https://travis-ci.org/pythonnet/pythonnet) |
7 | | -[![codecov shield][]](https://codecov.io/github/pythonnet/pythonnet) |
8 | | -[![coverity shield][]](https://scan.coverity.com/projects/pythonnet) |
| 6 | +- Open pythonnet.sln in visual studio 2015 |
| 7 | +- Choose "ReleaseWin"/"DebugWin" (If you use Python2.7), or "ReleaseWinPy3"/"DebugWinPy3"(for Python3.x) with AnyCpu Platform |
| 8 | +- When built, copy ./src/runtime/bin/Python.Runtime.dll to your own project. |
9 | 9 |
|
10 | | -[![license shield][]](./LICENSE) |
11 | | -[![pypi package version][]](https://pypi.python.org/pypi/pythonnet) |
12 | | -[![python supported shield][]](https://pypi.python.org/pypi/pythonnet) |
13 | | -[![stackexchange shield][]](http://stackoverflow.com/questions/tagged/python.net) |
14 | | -[![slack][]](https://pythonnet.slack.com) |
| 10 | +Please also refer to original [Python.Net repo](https://github.com/pythonnet/pythonnet) |
15 | 11 |
|
16 | | -Python for .NET is a package that gives Python programmers nearly |
17 | | -seamless integration with the .NET Common Language Runtime (CLR) and |
18 | | -provides a powerful application scripting tool for .NET developers. |
19 | | -It allows Python code to interact with the CLR, and may also be used to |
20 | | -embed Python into a .NET application. |
21 | 12 |
|
22 | | -## Calling .NET code from Python |
23 | | - |
24 | | -Python for .NET allows CLR namespaces to be treated essentially |
25 | | -as Python packages. |
26 | | - |
27 | | -```python |
28 | | -import clr |
29 | | -from System import String |
30 | | -from System.Collections import * |
31 | | -``` |
32 | | - |
33 | | -To load an assembly, use the `AddReference` function in the `clr` module: |
34 | | - |
35 | | -```python |
36 | | -import clr |
37 | | -clr.AddReference("System.Windows.Forms") |
38 | | -from System.Windows.Forms import Form |
39 | | -``` |
40 | | - |
41 | | -## Embedding Python in .NET |
42 | | - |
43 | | -- All calls to python should be inside |
44 | | - a `using (Py.GIL()) {/* Your code here */}` block. |
45 | | -- Import python modules using `dynamic mod = Py.Import("mod")`, |
46 | | - then you can call functions as normal, eg `mod.func(args)`. |
47 | | -- Use `mod.func(args, Py.kw("keywordargname", keywordargvalue))` or `mod.func(args, keywordargname: keywordargvalue)` |
48 | | - to apply keyword arguments. |
49 | | -- All python objects should be declared as `dynamic` type. |
50 | | -- Mathematical operations involving python and literal/managed types must |
51 | | - have the python object first, eg. `np.pi * 2` works, `2 * np.pi` doesn't. |
52 | | - |
53 | | -### Example |
54 | | - |
55 | | -```csharp |
56 | | -static void Main(string[] args) |
57 | | -{ |
58 | | - using (Py.GIL()) |
59 | | - { |
60 | | - dynamic np = Py.Import("numpy"); |
61 | | - Console.WriteLine(np.cos(np.pi * 2)); |
62 | | - |
63 | | - dynamic sin = np.sin; |
64 | | - Console.WriteLine(sin(5)); |
65 | | - |
66 | | - double c = np.cos(5) + sin(5); |
67 | | - Console.WriteLine(c); |
68 | | - |
69 | | - dynamic a = np.array(new List<float> { 1, 2, 3 }); |
70 | | - Console.WriteLine(a.dtype); |
71 | | - |
72 | | - dynamic b = np.array(new List<float> { 6, 5, 4 }, dtype: np.int32); |
73 | | - Console.WriteLine(b.dtype); |
74 | | - |
75 | | - Console.WriteLine(a * b); |
76 | | - Console.ReadKey(); |
77 | | - } |
78 | | -} |
79 | | -``` |
80 | | - |
81 | | -Output: |
82 | | - |
83 | | -```c |
84 | | -1.0 |
85 | | --0.958924274663 |
86 | | --0.6752620892 |
87 | | -float64 |
88 | | -int32 |
89 | | -[ 6. 10. 12.] |
90 | | -``` |
91 | | - |
92 | | -Information on installation, FAQ, troubleshooting, debugging, and projects using pythonnet can be found in the Wiki: |
93 | | - |
94 | | -https://github.com/pythonnet/pythonnet/wiki |
95 | | - |
96 | | -[appveyor shield]: https://img.shields.io/appveyor/ci/pythonnet/pythonnet/master.svg?label=AppVeyor |
97 | | - |
98 | | -[codecov shield]: https://img.shields.io/codecov/c/github/pythonnet/pythonnet/master.svg?label=Codecov |
99 | | - |
100 | | -[coverity shield]: https://img.shields.io/coverity/scan/7830.svg |
101 | | - |
102 | | -[license shield]: https://img.shields.io/badge/license-MIT-blue.svg?maxAge=3600 |
103 | | - |
104 | | -[pypi package version]: https://img.shields.io/pypi/v/pythonnet.svg |
105 | | - |
106 | | -[python supported shield]: https://img.shields.io/pypi/pyversions/pythonnet.svg |
107 | | - |
108 | | -[slack]: https://img.shields.io/badge/chat-slack-color.svg?style=social |
109 | | - |
110 | | -[stackexchange shield]: https://img.shields.io/badge/StackOverflow-python.net-blue.svg |
111 | | - |
112 | | -[travis shield]: https://img.shields.io/travis/pythonnet/pythonnet/master.svg?label=Travis |
0 commit comments