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.
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.
- 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:
C:\Program Files\Alteryx\bin\Miniconda3>python -m venv C:\ProgramData\Alteryx\Tools\ExamplePythonSDKTool
For more information about Python virtual environments, refer to Python3 documentation.
Additional 3rd party library installation
Use the following steps to install each third-party dependency required by your tool.
- Use a command prompt to access the \Scripts folder, located in the installed virtual environment path of your tool.
- Use the pip installer to install an additional library.
- Verify that the library is available in the virtual environment path.
C:\ProgramData\Alteryx\Tools\ExamplePythonSDKTool\Scripts>pip install numpy
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:
- If a library requires additional configuration steps, such as NLTK library, try to automate the steps from within the Python SDK script.