How to install additional Python modules in PLAXIS


Application PLAXIS 2D
PLAXIS 3D
Version PLAXIS 2D CONNECT Edition V20 and later
PLAXIS 3D CONNECT Edition V20 and later
Date created 13 October 2020
Date modified 3 September 2024

 

When using the PLAXIS scripting environment it is common to use Python modules allowing for extending the functionality of a Python script. An example of a Python module is easygui, which offers an easy-to-use interface for simple GUI interaction with the user.

With the PLAXIS installer a PLAXIS-Python Distribution is provided and stored in a dedicated versioned location within the ProgramData folder (see release notes for PLAXIS 2D and 3D), including various Python modules.

This allows both PLAXIS 2D and PLAXIS 3D applications to access this shared distribution when using Python Scripting facilities, keeping all the modules up to date and fully compatible with PLAXIS.

This article will explain the available options in PLAXIS applications on how to install and use any Python modules required when scripting.

 

Using the modules in the installed PLAXIS-Python Distribution

Since the release of PLAXIS CONNECT Edition V20 Update 3, a separation is made of the deliverable Python environment: one that can be used for user-created Python scripts and the editor, and one trimmed-down environment intended for all PLAXIS extensions implemented using Python language, e.g. the PLAXIS 2D to 3D converter and the structural Coupling tool, the parameter optimization tool for UDCAM-S constitutive model.

The PLAXIS-Python Distribution which can be used in automations includes various modules, such as easygui, matplotlib, numpy, pyperclip and it is placed in a dedicated versioned location within the ProgramData folder.
By default, this is stored in the folder: C:\ProgramData\
Depending on the installed version it can be different, for example:

To confirm which exact folder to use, go to PLAXIS Input, menu option Expert > Python > Configure Python Interpreter and see what is used as Default.

 

Using a custom Python distribution

Since PLAXIS CONNECT Edition V20 Update 3 it is possible to configure PLAXIS to use a custom Python version, which is installed in the computer. To do so, the following steps are required:

  1. Start the PLAXIS Input as administrator from the Windows Start menu.
    It is important to have proper rights to install the required PLAXIS modules in the custom Python directory.
  2. Go to menu option Expert > Python > Configure Python Interpreter, select the option Use the following Python interpreter and browse to the custom Python distribution folder
  3. Select the option to Install required components.
    This will make sure all required modules and files for the PLAXIS scripting environment are installed in the custom Python directory.
  4. A popup window will provide information on the progress of the installation of the Python packages.

Figure 1. Configure and use a custom Python distribution

 

Note: changing to a different Python interpreter means that all options for Python, such as Run Python Script/Tool, Interpreter, Editor will use the custom Python interpreter as configured.

Any errors encountered during the installation of the required components may be linked to the custom Python version.

 

Install Python modules in the PLAXIS-Python Distribution

It is possible to install various Python modules that are not already available in the PLAXIS-Python Distribution via the Command prompt window.

To do so, the following steps are required:

  1. Start the PLAXIS Input as administrator from the Windows Start menu.
    This is important in order to have proper rights to proceed with installing/updating any Python modules in the local Python directory.
    Note: you can also directly launch the Command prompt of Windows, and then move to step #3.
  2. Go to the menu option Expert > Python > Command prompt
    This will open the familiar Windows Command prompt with the PLAXIS set as the current directory.
  3. If needed, change the directory to the PLAXIS-Python Distribution, where the Python packages are installed. This can be done by running the command - depending on the location based on your version in C:\ProgramData:
    cd C:\ProgramData\Seequent\PLAXIS Python Distribution V3\python\Lib\site-packages
  4. In the Command prompt you can now install any new Python modules using the command shown in the example below.
    For instance, if you want to install the pandas module:
    python -m pip install pandas

Figure 2. Example of installing pandas module using the PLAXIS Command prompt for PLAXIS CONNECT Edition V20 Update 3

Note that the installation of a Python module may require an updated version of another Python module. This may affect other modules that are available in the PLAXIS-Python Distribution, therefore, make sure to understand the changes made during the installation of any Python module.

Using a Python Integrated Development Environment

In the case that one of the various Python IDEs is used, such as PyCharm, Spyder, etc., the way of installing a Python module depends on each IDE.

Note that it is important in all cases to provide administrative rights to the application in order to allow for installing Python modules in the selected Python environment.