Macaulay2 » Documentation
Packages » Python :: Python
next | previous | forward | backward | up | index | toc

Python -- interface to Python

Description

This package provides a basic interface to run Python code within Macaulay2 and to convert back and forth between Python and Macaulay2 objects.

i1 : toPython {1, 2/3, "foo", (1, 2, 3), hashTable {"foo" => "bar"}}

o1 = [1, 0.6666666666666666, 'foo', (1, 2, 3), {'foo': 'bar'}]

o1 : PythonObject of class list
i2 : value pythonValue "[1, 2/3, 'foo', (1, 2, 3), {'foo' : 'bar'}]"

o2 = {1, .666667, foo, (1, 2, 3), HashTable{"foo" => bar}}

o2 : List
i3 : math = import "math"

o3 = <module 'math' (built-in)>

o3 : PythonObject of class module
i4 : math@@sqrt 2

o4 = 1.4142135623730951

o4 : PythonObject of class float

The loadPackage(...,Configuration=>...) option accepts an "executable" option to specify the path to the Python executable, e.g., for working with virtual environments. At least Python version 3.8 is required for this feature to work.

Menu

tutorials

evaluating code

working with modules

classes

getting help

Authors

Version

This documentation describes version 1.0 of Python, released November 8, 2025.

Citation

If you have used this package in your research, please cite it as follows:

@misc{PythonSource,
  title = {{Python: interface to Python. Version~1.0}},
  author = {Daniel R. Grayson and Doug Torrance},
  howpublished = {A \emph{Macaulay2} package available at
    \url{https://github.com/Macaulay2/M2/tree/stable/M2/Macaulay2/packages}}
}

Exports

For the programmer

The object Python is a package, defined in Python.m2, with auxiliary files in Python/.


The source of this document is in Python/doc.m2:47:0.