Welcome to the Alteryx Knowledge Base
Created/Edited -
Installing a package from the Python tool is an important task. In this article, we will review all the possible functionality included with the Python method Alteryx.installPackages().
- Alteryx Designer
- Version 2018.3+
Background Information
First of all, don't get confused: you can use eitherAlteryx.installPackage(), Alteryx.installPackages(), or Package.installPackages() to achieve same result.
By default, packages are installed under:
%ALTERYX%\bin\Miniconda3\PythonTool_venv\Lib\site-packages until 2019.2
%ALTERYX%\bin\Miniconda3\envs\JupyterTool_vEnv\Lib\site-packages for 2019.3.1 to 2021.1.3
%ALTERYX%\bin\Miniconda3\envs\DesignerBaseTools_vEnv\Lib\site-packages for 2021.1.4+
Example:
C:\Program Files\Alteryx\bin\Miniconda3\PythonTool_venv
As a result, you may need to start Designer with administrator rights if the installation folder does not allow write access to a standard account, like for an admin version for example.
Typically, people use installPackage() with a single argument (the package name(s)). But, looking at the method itself, there are in fact 3 parameters:
| Parameter | Comment |
| package | A string or list of strings of package name(s) |
| install_type | Optional: default value: "install". Pip command to use. |
| debug |
Optional: default value: False Add some details to the output |
Function signature:
Alteryx.installPackages(package, install_type=None, debug=None, **kwargs)
In reality, Alteryx.installPackages() is nothing more than a wrapper for the pip (Python Package Manager) command.
This means the following command:
Alteryx.installPackage(package="logger")
is interpreted as:
up to 2019.2:
%ALTERYXDIR%\bin\miniconda3\pythontool_venv\scripts\python.exe -m pip install logger
for 2019.3+:
%ALTERYXDIR%\bin\miniconda3\envs\jupytertool_venv\python.exe -m pip install logger
This can be seen using debug parameter:
Alteryx.installPackage(package="logger",debug=True)
Output (duplicates due to debug mode):
Executing subprocess: install logger [Executing subprocess: c:\users\xxxx\appdata\local\alteryx\bin\miniconda3\pythontool_venv\scripts\python.exe -m pip install logger ] [Subprocess success!] Collecting logger Installing collected packages: logger Successfully installed logger-1.4 Collecting logger Installing collected packages: logger Successfully installed logger-1.4 Alteryx.installPackage(package="logger",debug=True) Output (duplicates due to debug mode): Executing subprocess: install logger [Executing subprocess: c:\users\xxxx\appdata\local\alteryx\bin\miniconda3\pythontool_venv\scripts\python.exe -m pip install logger ] [Subprocess success!] Collecting logger Installing collected packages: logger Successfully installed logger-1.4 Collecting logger Installing collected packages: logger Successfully installed logger-1.4
Procedure: Standard Installation
In this case, only the package argument is specified.
Examples:
# With one package Alteryx.installPackage("logger")
Alteryx.installPackage(package="logger")
# With multiple packages
Alteryx.installPackage(["logger","wordcloud"])
Alteryx.installPackage(package=["logger","wordcloud"])
# With a specific version
Alteryx.installPackage("logger==1.3")
# Without cache enable to ensure that package is downloaded before installation
Alteryx.installPackage(package="logger",install_type="install --no-cache-dir")
Procedure: Installation from GitHub
Git must be installed on the machine to use this method. It could be downloaded from https://git-scm.com/downloads.
Instead of the package name, specify git URL prefixed with git+.
Example:
Alteryx.installPackages(package="git+https://github.com/alteryx/promote-python.git")
Procedure: Installation of a Module in the User Folder
This method uses parameter --user to specify that package must be installed in user folder (%APPDATA%/Python/Python36 as perhttps://www.python.org/dev/peps/pep-0370/#windows-notes).
Example:
Alteryx.installPackages(package="logger", install_type="install --user")
Now, in order to use it, package location must be added to default path: %APPDATA%\Python\Python36\site-packages.
Example:
import os,sys
sys.path.insert(1,os.path.join(os.environ['APPDATA'],"Python",f"Python{sys.version_info.major}{sys.version_info.minor}","site-packages"))
import logger
Procedure: Installation of a Module in a Different Folder
This method uses parameter --target to specify the destination and creates it if needed.
Example:
Alteryx.installPackages(package="logger", install_type="install --target=C:\\ProgramData\\PythonLibs")
Now, in order to use it, the package needs to be imported using Alteryx.importPythonModule(%MODULE_PATH%) [2018.4+].
Example:
logger = Alteryx.importPythonModule("C:\\ProgramData\\PythonLibs\\logger") logger.logging.info("Logger installed successfully")
Note: With this method, a module does not appear as installed in the PythonTool environment.
Procedure: Installation from local directory or tar.gz
The package must exist in a place accessible by the machine (such as C:\Users\\Documents\Personal\PythonPckg).
Example:
Alteryx.installPackages(package="file:C:\tthers\downloads lptoolkit-dictionary-1.0.4.tar.gz")
Procedure: Installation with a proxy in place
This allows the option of adding proxy and proxy credentials to the installation argument. Credentials can be left off or included depending on the environment.
Example:
#No password and username Alteryx.installPackages(package="",install_type="install --proxy proxy.server:port") #With password and username Alteryx.installPackages(package="",install_type="install --proxy [user:passwd@]proxy.server:port")
Procedure: Installation from Wheels
In this case, we use --no-index and --find-links with the local repository to ensure that package is not going to be downloaded.
Example:
Here, C:\ProgramData\PythonWheels contains following files (numpy and Pillow are dependencies of wordcloud):
numpy-1.16.3-cp36-cp36m-win_amd64.whl
Pillow-6.0.0-cp36-cp36m-win_amd64.whl
wordcloud-1.5.0-cp36-cp36m-win_amd64.whl
Alteryx.installPackages(package="wordcloud", install_type="install --no-index --find-links=C:\\ProgramData\\PythonWheels")
Procedure: Uninstall Package(s)
Specify uninstall as the install_type parameter and either a string with the package name or a list of strings with package names.
Example:
# For a single package Alteryx.installPackages(package="wordcloud", install_type="uninstall") # For multiple packages Alteryx.installPackages(package=["wordcloud","pillow"], install_type="uninstall")
Procedure: Download Wheels or Archive Files
In this case, the command to use is download instead of the default install. One may also specify a destination folder with parameter --dest
Example:
Alteryx.installPackages(package="wordcloud",install_type="download --dest=C:\\ProgramData\\PythonWheels")
Procedure: List the Currently Installed Modules
The following procedure provides a basic way to list the module names and versions installed along with Python tool.
from ayx import Alteryx
import re
from pandas import DataFrame
import io
from contextlib import redirect_stdout
with io.StringIO() as current_output, redirect_stdout(current_output):
Alteryx.installPackages(package='',install_type='freeze')
packages = ( (item for item in out_row.split("=") if item)
for out_row in re.split(string=current_output.getvalue(),pattern=r"\r*\n") if out_row)
output_df = DataFrame(packages ,columns=["package","version"])
Alteryx.write(output_df,1)
Example of result: