Using Python from Analytica/Setting up a Python environment

< Using Python from Analytica
Revision as of 15:53, 25 August 2025 by Calvin.lu (talk | contribs) (→‎Installing Conda)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

This page explains how to prepare a Conda-based Python environment and configure Analytica to use it. Python 3.8+ is recommended for better compatibility and support. Other Python installations can be used if you provide the full Python home directory path in Analytica’s Python system variables.

Overview of Conda and distributions

Conda is a cross-platform package and environment manager that creates isolated Python environments and installs packages with precise dependency control.

Anaconda and Miniconda

Anaconda and Miniconda are distributions that include Conda.

Anaconda bundles many scientific packages and tools out of the box and includes the Anaconda Navigator GUI.

Miniconda is a minimal installer that provides only Conda and Python so that you add exactly the packages you need.

Selecting a Conda distribution

Choose Anaconda for convenience when a GUI is preferred and many packages should be available immediately; the trade-off is a heavier download and larger disk footprint.

Choose Miniconda for a lightweight installation that starts small and grows only as needed using conda install.

The example below use the Conda command line which are included in both Anaconda and Miniconda.

Installing Conda

Download and run the Anaconda or Miniconda installer.

AnacondaInstaller.png

Creating and managing an environment

Open the Anaconda Prompt and create an environment named MyEnv with commonly used libraries:

conda create -n MyEnv python=3.11 pandas numpy

Python 3.8+ is recommended; selecting a newer version such as python=3.12 is acceptable.

Package sources and managers

About conda-forge: conda-forge is a community-maintained collection of Conda packages. Install from it when required, for example:

conda install -n MyEnv -c conda-forge matplotlib

Mixing channels can sometimes introduce dependency conflicts or larger downloads, so prefer a consistent channel strategy.

Installing some packages with pip inside the environment can be acceptable, but prefer conda install when possible for better dependency management.

Activating the environment and installing more packages

Analytica does not require shell activation to use the environment, but activation is useful when installing or testing packages interactively.

To work inside the existing environment and add packages:

conda activate MyEnv

conda install requests

pip install some_package_only_on_pip

Packages can be added or updated at any time after the environment is created.

Configuring Analytica to use the environment

Open the Definition / Application integration / Python submenu. Set either Python Model Environment or Python Environment. Python Model Environment is saved with the model file, while Python Environment is saved in Analytica. Enter the environment name (e.g., MyEnv) or the full Python home folder path (e.g., C:\Users\username\anaconda3\envs\MyEnv).

When only a name is provided, Analytica searches the default Anaconda and Miniconda environment locations. If none of the Python system variables are set, Analytica looks first in the Windows User registry and then the Machine registry for a Python home. When both settings are present, Python Model Environment takes precedence over Python Environment.

If Python was already initialized in this session, close and reopen the model or restart Analytica after changing the environment.

Verifying from within Analytica

After setting Python Model Environment, run a minimal verification that reports the NumPy version:

import numpy as np
np.__version__

Troubleshooting

If the specified environment name or path is not found, an error is raised.

For package availability or dependency issues, try installing with conda install first; if a package is not available on the default channels, try using an alternative channel like conda-forge while keeping channel usage consistent. As a last resort, use pip install inside the environment, recognizing that this mixes package managers.

Comments


You are not allowed to post comments.