
Security News
Open Source Maintainers Feeling the Weight of the EU’s Cyber Resilience Act
The EU Cyber Resilience Act is prompting compliance requests that open source maintainers may not be obligated or equipped to handle.
pythonnet
is a package that gives .NET programmers ability to
integrate Python engine and use Python libraries.
Runtime.PythonDLL
property or PYTHONNET_PYDLL
environment variable,
otherwise you will receive BadPythonDllException
(internal, derived from MissingMethodException
) upon calling Initialize
.
Typical values are python38.dll
(Windows), libpython3.8.dylib
(Mac),
libpython3.8.so
(most other *nix). Full path may be required.PythonEngine.Initialize()
. If you plan to use Python objects from
multiple threads,
also call PythonEngine.BeginAllowThreads()
.using (Py.GIL()) {/* Your code here */}
block.dynamic mod = Py.Import("mod")
, then
you can call functions as normal, eg mod.func(args)
.
You can also access Python objects via PyObject
and dervied types
instead of using dynamic
.mod.func(args, Py.kw("keywordargname", keywordargvalue))
or
mod.func(args, keywordargname: keywordargvalue)
to apply keyword
arguments.np.pi * 2
works,
2 * np.pi
doesn't.using var _ = Py.GIL();
dynamic np = Py.Import("numpy");
Console.WriteLine(np.cos(np.pi * 2));
dynamic sin = np.sin;
Console.WriteLine(sin(5));
double c = (double)(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.]
Information on installation, FAQ, troubleshooting, debugging, and projects using pythonnet can be found in the Wiki:
https://github.com/pythonnet/pythonnet/wiki
Mailing list https://mail.python.org/mailman/listinfo/pythondotnet Chat https://gitter.im/pythonnet/pythonnet
This project is supported by the .NET Foundation.
FAQs
Python and CLR (.NET and Mono) cross-platform language interop
We found that pythonnet demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 3 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
The EU Cyber Resilience Act is prompting compliance requests that open source maintainers may not be obligated or equipped to handle.
Security News
Crates.io adds Trusted Publishing support, enabling secure GitHub Actions-based crate releases without long-lived API tokens.
Research
/Security News
Undocumented protestware found in 28 npm packages disrupts UI for Russian-language users visiting Russian and Belarusian domains.