Virtual Environment and Dependencies

To mitigate against conflicting dependencies, each tool created with the Python SDK can have an independent Python virtual environment. This allows tools to independently manage a list of dependencies, removing the need to consider other Python SDK tools that could be installed on a user's system.

This process uses the pip command, and thus requires an internet connection.

Shared libraries

Each virtual environment has a Python binary, allowing environment creation with multiple Python versions, and can have independent Python packages installed in its site directories. The environment still shares the standard library with the base-installed Python.

By default, a virtual environment is isolated from system-level site-packages directories.

Virtual environment creation

A virtual environment can be created before or after a Python SDK tool is developed. If a tool does not use additional third-party Python libraries, a virtual environment is not needed.

The following steps detail the recommended process for installing a virtual environment. Consistent installation methods prevent issues with virtual environment replication for end users.

  1. Create a folder to hold the tool for either admin or non-admin access.
    • Tools using the Program directory require admin permissions:

    • Tools can also be installed on a per-user basis:

  2. Use a command prompt to run the command python -m venv <path name>. Execute the command from the Python install location.
  3. C:\Program Files\Alteryx\bin\Miniconda3>python -m venv 

    For more information about Python virtual environments, refer to Python3 documentation.

  4. Verify that a Python virtual environment is installed in the specified folder.

Additional 3rd party library installation

Use the following steps to install each third-party dependency required by your tool.

  1. Use a command prompt to access the \Scripts folder, located in the installed virtual environment path of your tool.
  2. C:\ProgramData\Alteryx\Tools\ExamplePythonSDKTool\Scripts
  3. Use the pip installer to install an additional library.
  4. C:\ProgramData\Alteryx\Tools\ExamplePythonSDKTool\Scripts>pip install numpy
  5. Verify that the library is available in the virtual environment path.

Best practices

Test and manage a virtual environment for development and distribution, ensuring compatibility and portability, by adhering to the following standards.

  • Only include third-party libraries that are used by the tool.
    • Remove libraries that were installed but not used. This ensures a clean list of dependencies for installs on end-user systems.
  • Python SDK Tool files, such as the GUI HTML file, are in the root of the virtual environment directory path, not in:
    • \Scripts
    • \Lib
    • \Include
  • If a library requires additional configuration steps, such as NLTK library, try to automate the steps from within the Python SDK script.