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.
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.
- 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:
- Use a command prompt to run the command python -m venv <path name>. Execute the command from the Python install location.
- 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.
C:\ProgramData\Alteryx\Tools\ExamplePythonSDKTool\Scripts>pip install numpy
- Use a command prompt to access the \Scripts folder, located in the installed virtual environment path of your tool.Best Practices
- Use the pip installer to install an additional library.
- Verify that the library is available in the virtual environment path.
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.