Python SDK Dependency Settings

Setting the Globally Dependent Python SDK

  1. In the project dialog box, choose File > Project Structure. The Project Structure dialog box is displayed.
  2. On the left menu bar, choose Platform Settings > SDKs and add a Python library. For details, see Figure 1.
    Click next to Interpreter to select an interpreter version. The Python 3 version is recommended.
    Figure 1 Adding the global Python library

  3. (Optional) In the Add Python Interpreter window, select a proper Python interpreter. You can configure a Python interpreter or use the default one. Figure 2 shows the available interpreters.
    Figure 2 Adding a Python interpreter
    Table 1 Python interpreter options

    Interpreter

    Description

    Virtualenv Environment

    Integrates the Virtual Environment tool to create an independent virtual environment.

    Conda Environment

    Uses the Python interpreter contained in Anaconda.

    System Interpreter

    Specifies the local interpreter in the system.

    Pipenv Environment

    Pipenv is a tool that provides all the necessary means to create a virtual environment for Python projects.

    Poetry Environment

    Uses the Poetry tool to create a virtual environment based on project dependencies.

    SSH Interpreter

    Specifies a remote interpreter. You can add the Python SDK of a remote device in SSH mode and use the Deployment function to synchronize the files and folders in a specified project to a specified directory on the remote device. For details, see Deployment. (If you select this option, MindStudio remotely runs a project.)

  4. Ensure that corresponding Python libraries exist.

    The following figure shows an example.

    Figure 3 Viewing the Python libraries

  5. In the Project Structure window, click Apply.
  6. Click OK to close the Project Structure window.

Setting a Custom Globally Dependent Python SDK

During code development, if a third-party Python library or custom Python library is linked, perform the following steps to add the corresponding Python SDK to the project:

  1. In the project dialog box, choose File > Project Structure. The Project Structure dialog box is displayed.
  2. On the left menu bar, choose Platform Settings > SDKs.
  3. Select the corresponding Python library and click + in the Classpath column to add a custom Python library, as shown in Figure 4.

    Notes:

    • The Python libraries on the Platform Settings tab page are globally configured and take effect for all operator projects.
    Figure 4 Adding a custom Python library

  4. Click OK to close the Project Structure window.

Set the Python SDK on which the current project depends.

During code development, if a third-party Python library or custom Python library is linked, perform the following steps to add the corresponding Python SDK to the project:

  1. In the project dialog box, choose File > Project Structure. The Project Structure dialog box is displayed.
  2. On the left menu bar, choose Project Settings > Project.
    In Project SDK, select the Python SDK configured in Python SDK Dependency Settings from the drop-down list box and click Apply, as shown in Figure 5.
    Figure 5 Selecting the Project SDK

  3. Choose Project Settings > Modules from the menu bar on the left.
    On the Dependencies tab page, select the Python SDK configured in Setting the Globally Dependent Python SDK from the drop-down list box and click Apply, as shown in Figure 6.
    Figure 6 Selecting the Modules SDK

  4. Click OK to close the Project Structure window.
    A message is displayed on the menu bar at the bottom of the project, as shown in Figure 7.
    Figure 7 Update page

  5. After the update is successful, the Python code can be automatically interpreted, as shown in Figure 8. Click the imported Python module code and press Ctrl+Q. The corresponding tips are displayed. You can press Ctrl and click to open the corresponding module definition file.
    Figure 8 Example of auto interpretation of Python code

    If the problem persists, close the project and open it again.