ansys-pythonnet

raw JSON →
3.1.0rc6 verified Fri May 01 auth: no python

Ansys fork of pythonnet providing .NET and Mono integration for Python. Version 3.1.0rc6, targeting Python 3.7-3.13. Active development with release candidate status.

pip install ansys-pythonnet
error ImportError: No module named clr
cause Missing ansys-pythonnet package or mistakenly installed old pythonnet package which does not expose clr.
fix
Install ansys-pythonnet: pip install ansys-pythonnet
error AttributeError: module 'clr' has no attribute 'AddReference'
cause Using 'import clr' but not loading the module correctly; possibly a namespace conflict or incomplete install.
fix
Ensure ansys-pythonnet is installed and imported as 'import clr'. Check for clr files shadowing from other packages.
error System.BadImageFormatException: Could not load file or assembly ...
cause Mismatch between Python architecture (32-bit vs 64-bit) and .NET assembly target.
fix
Ensure both Python and .NET runtime use the same bitness. Use 64-bit Python with 64-bit .NET assemblies.
breaking The PythonNET (pythonnet) fork renamed to ansys-pythonnet. Import statements remain 'import clr' but package name changed. Existing code using 'pythonnet' package will not work; reinstall with 'pip install ansys-pythonnet'.
fix Replace 'pythonnet' with 'ansys-pythonnet' in requirements.txt and environment.
deprecated clr.AddReference works, but the newer recommended approach uses 'import clr' and then 'clr.AddReference' with assembly names. Avoid loading assemblies via absolute paths if possible.
fix Use assembly name without extension: clr.AddReference('System.Windows.Forms') instead of path.
gotcha Python 3.13 is not fully supported yet; current version supports <3.14,>=3.7 but only tested up to 3.12. Use Python 3.12 or earlier for stable behavior.
fix Use Python 3.12 or earlier. Check official repo for updates.
pip install ansys-pythonnet==3.1.0rc6

Basic usage: import clr, add a .NET assembly reference, and import .NET namespaces.

import clr
# Add reference to a .NET assembly
clr.AddReference('System.Windows.Forms')
from System.Windows.Forms import MessageBox
MessageBox.Show('Hello from .NET!')