Install PySTK in a Windows container#
This topic provides details on installing PySTK inside a Windows-based Docker container.
Download Dockerfiles#
Start by downloading the PySTK Docker images for Windows. The images contain the latest three stable versions of Python.
Artifact |
|
Size |
0.01 MB |
SHA-256 |
2b92ef812b091a6d9130d781d3361f2985b8fcdec8e5af6b27b566bebade4c41 |
Download STK artifacts#
Download the STK Engine and STK Engine Deployment Resources artifacts for
Windows platforms from the https://support.agi.com/downloads page.
Place the artifacts inside a directory named distributions. This directory
must be contained inside of the stk-engine directory.
windows/
├── docker-compose.yml
├── stk-engine
│ └── distributions/
│ └── Place STK Engine artifacts here
├── stk-engine-py311
├── stk-engine-py312
├── stk-engine-py313
└── stk-engine-pybase
Build Docker images#
Navigate to the windows directory and use Docker Compose to build the
image of your choice by running:
docker compose build stk-engine-py3<minor>
where <minor> is one of the minor versions of Python.
Download PySTK wheels#
Download the PySTK wheels for Windows.
Artifact |
|
Size |
1.93 MB |
SHA-256 |
9cd71cf0dbc92d986c1f181402a6136f3ef44866195914090bda37de7b4dcedd |
Next, create a working directory in your machine. This directory is used as a shared volume with future Docker containers. Place the PySTK wheels in this directory.
working-directory/
└── ansys_stk-0.2.0-py3-none-any.whl
Configure the license#
Open a terminal in your working directory. Make sure you have set the
ANSYSLMD_LICENSE_FILE environment variable by running:
set ANSYSLMD_LICENSE_FILE=<PORT>@<LICENSE_SERVER_IP>
$env:ANSYSLMD_LICENSE_FILE=<PORT>@<LICENSE_SERVER_IP>
where PORT usually takes the value of 1055 and LICENSE_SERVER_IP is
the Internet Protocol (IP) of the machine hosting the license server.
Start a container#
With the artifacts and the license in place, start a Docker container and share the working directory as a volume. This enables you to write scripts using the tools in the host machine while isolating their execution inside the container.
Syntax#
docker run \
--detach --interactive --tty \
--network="host" \
--env ANSYSLMD_LICENSE_FILE=$ANSYSLMD_LICENSE_FILE \
--name <container-name> \
--entrypoint <entrypoint> \
<image-name>
Command breakdown#
Use the docker run command to create and run a container from a Docker image. Various options are available to customize the container creation process.
--detachRuns the container in detached mode, enabling it to run in the background.--interactiveEnables interactive mode, providing a TTY session for connecting to the container.--ttyAllocates a pseudo-TTY, ensuring proper formatting and display of the container’s output.--network="host"Shares the host’s network stack with the container, enabling network connectivity.--env ANSYSLMD_LICENSE_FILE=$ANSYSLMD_LICENSE_FILESpecifies environment variable(s) to be shared with the container.--name <container-name>Assigns a name to the container for easy identification and reference.--entrypoint <entrypoint>Defines the command or script to be executed when the container starts.--volume <volume>Specifies the binding volume between the host and the container.<image-name>Specifies the name or ID of the Docker image to be used for creating the container.
Example#
docker run \
--detach --interactive --tty \
--network="host" \
--env ANSYSLMD_LICENSE_FILE=$ANSYSLMD_LICENSE_FILE \
--volume working-directory:/home/stk/pystk
--name stk-python3.12 \
--entrypoint /bin/bash \
ansys/stk:dev-ubuntu22.04-python3.12
Install PySTK in the container#
With a working directory containing the PySTK wheels and shared as a volume with the container, it is possible to install the package by running:
docker exec \
--interactive --tty \
stk-python-3.<minor> \
cmd /C "python -m venv .venv && cd pystk && chcp 65001 && call C:\Users\STK\.venv\Scripts\activate.bat && python -m pip install --upgrade pip && python -m pip install -e C:\Users\STK\pystk[tests,doc,visualization]"
where <minor> is the minor version of Python selected when building the
container.
Running scripts in the container#
Save your scripts inside the working directory. Then, execute them by running:
docker exec \
--interactive --tty \
stk-python-3.<minor> \
cmd /C "python /home/stk/pystk/<script>"
Where <script> is the name of the Python script you want to execute.