Skip to content

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.

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

Install-Package CSnakes.Runtime

Using .NET CLI

dotnet add package CSnakes.Runtime

Using PackageReference

Add this to your .csproj file:

<PackageReference Include="CSnakes.Runtime" Version="1.*-*" />

This package includes both the source generator and runtime libraries.

Configuring a C# Project

To setup a C# project for CSnakes, you need to:

  1. Create a new C# project or open an existing one
  2. Add your Python files to the project
  3. Mark the Python files as "Additional Files" in the project file
  4. Install the CSnakes.Runtime NuGet package
  5. 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

Next Steps