Installation (manual setup)
To get started with CSnakes manually, you need to:
Installing Python
CSnakes supports Python 3.9-3.13 and works on Windows, macOS, and Linux.
Option 1: Let CSnakes Download Python (Recommended)
The simplest option is to use the FromRedistributable
method, which will automatically download Python 3.12 and store it locally. This is compatible with Windows, macOS, and Linux.
builder.Services
.WithPython()
.WithHome(home)
.FromRedistributable(); // Downloads Python 3.12 automatically
Option 2: Use System Python
If you have Python installed on your system, you can use it directly:
builder.Services
.WithPython()
.WithHome(home)
.FromEnvironmentVariable("PYTHONHOME"); // Uses system Python
Option 3: Use Conda
If you're using Conda environments:
builder.Services
.WithPython()
.WithHome(home)
.FromConda("myenv"); // Uses specified Conda environment
Installing the NuGet Package
CSnakes is bundled into a single NuGet package: CSnakes.Runtime
.
Using Package Manager Console
Using .NET CLI
Using PackageReference
Add this to your .csproj
file:
This package includes both the source generator and runtime libraries.
Configuring a C# Project
To setup a C# project for CSnakes, you need to:
- Create a new C# project or open an existing one
- Add your Python files to the project
- Mark the Python files as "Additional Files" in the project file
- Install the
CSnakes.Runtime
NuGet package - Create a
PythonEnvironment
in C# and create an instance of the Python module
Requirements
- .NET 8 or 9
- Python 3.9-3.13
- Windows, macOS, or Linux