In this tutorial, we demonstrate how to create a Python virtual environment and install the numpy module within it. A virtual environment allows us to isolate Python packages from the system-wide installation, ensuring that dependencies do not interfere with other projects.
First, we choose a directory where we want to create our virtual environment. We then call setupVirtualEnvironment with that directory. This command initializes a new virtual environment, which includes a dedicated Python interpreter and an isolated package installation directory.
|
|
|
Next we restart Macaulay2 so we can initialize the Python binary in the new virtual environment.
|
To ensure that the Python interface uses the newly created virtual environment, we load the Python package while specifying the virtual environment’s Python interpreter. This is done by setting the "executable" configuration option to point to the python3 binary inside our virtual environment.
|
At this point, all Python commands will use the virtual environment's interpreter rather than the system-wide Python installation.
Next, we install the NumPy module using pipInstall. This downloads and installs NumPy into the virtual environment.
|
Once this step completes, NumPy is fully installed and ready for use.
Now that NumPy is installed, we can call installNumPyMethods and begin using it. Let's verify that it works by multiplying two matrices.
|
|
|
|
The source of this document is in Python/doc/tutorials.m2:132:0.