How to Install Python for .Net on Windows

How to install Python.NET for C# (VS2019) on Windows 10 and for Python 3.8?

As mentioned here, Anaconda (and Miniconda) do not works with Python.NET. All I had to do was to reinstall a fresh copy of Python with all the package I needed and replace the following piece of code with the new paths:

string pythonPath1 = @"C:\Python";
string pythonPath2 = @"C:\Python\Lib\site-packages";

Python.Net distribution with my application: online or offline install?

The upcoming Python.NET 3.0 won't need to be installed using pip to enable embedding of Python into .NET projects. You can build it from GitHub src/runtime directory or get the latest monthly preview build from NuGet.org.

Your app will need to set Runtime.PythonDLL to the full path of python39.dll and PythonEngine.PythonHome to Python home directory (on Windows this is usually the directory where python39.dll is located).

How to fix error during pythonnet installation

From the Python.NET docs I can see it doesn't support python 3.9. You can download wheel file from
here.

As your python version is 3.9, download pythonnet‑2.5.2‑cp39‑cp39‑win32.whl (for 32-bit python version) or pythonnet‑2.5.2‑cp39‑cp39‑win_amd64.whl (for 64-bit python version).

Then specify a full path to wheel file for installation.

Example:

pip install C:\Users\User\Downloads\pythonnet‑2.5.2‑cp39‑cp39‑win_amd64.whl

How do I distribute Python with a .Net application as one installation executable?

I do not have experience with C#, but you could try to compile the python script using
pyinstaller, which compiles python code to a stand-alone executable.

Then, you can try embedding this executable into your C# program, as discussed here.



Related Topics



Leave a reply



Submit