Engine Works

Under the hood of Alteryx: tips, tricks and how-tos.
Felipe_Ribeir0
16 - Nebula

Tired of asking for admin rights to install Python libraries in Alteryx? Discover a simple way to manage your packages without needing admin access—and make it work across all machines and servers. No more 'it works on my machine' excuses!

 

If it works on my machine, it should work everywhere… right?

 

When running Alteryx locally, installing Python libraries requires admin privileges. The same issue applies to coworkers who need to run your workflow. On Alteryx Server, even if the libraries are installed locally, you still need to ask server admins to install them on the server. This can be a hassle for everyone. But what if you could manage Python packages in Alteryx without needing admin access, and make it work everywhere?

 

works on my machine.png

Source: The "Works on My Machine" Certification Program

 

A Simple Trick to Make Python Packages Work Everywhere

 

To skip the admin privileges step (but hey, check with your server admin and manager before setting this up), here's a solution: set up a shared network folder for your Python libraries. This way, you can easily access and import the necessary libraries without needing to install them on every machine or server. Plus, the best part is everyone will be using the same exact library version—no more “it works on my machine” excuses.

 

First, let's take the baby steps

 

Using the Alteryx Python component and Alteryx.installPackages function, install the required libraries to a shared network folder accessible to all users.

 

# Step 1: Install packages in a shared folder (run this once)
from ayx import Alteryx

# Replace the target folder in the code below!
Alteryx.installPackages(['selenium', 'openpyxl', 'pyautogui'],
install_type= r'install --target=\\network_folder_path\shared_libraries')

 

 Now, you can append this network folder to Python’s module search path, enabling Alteryx to import the libraries from there. Your folder will be shown in the last position of the printed list.

 

# Step 2: Append the shared folder to Python's path
import sys
sys.path.append(r'\\network_folder_path\shared_libraries')
print(sys.path)

 

Finally, you can import your libraries from any machine that has access to the folder. This will happen automatically because of the previous step:

 

# Step 3: Import modules
# Import the installed libraries
import selenium, openpyxl, pyautogui

 

Building momentum

 

Instead of hardcoding the packages path, you can parametrize the location on your code and use text inputs to pass it.

 

building momentum.png

 

Using Alteryx.read, import the dataframe containing the path. With iloc and os.path, turn the dataframe into a path for Python.

 

# Step 1: Transform a Python package path from a DataFrame cell
from ayx import Alteryx
import os

df_pythonPackages = Alteryx.read("#pythonPackages")
newPythonPackagePath = os.path.abspath(str(df_pythonPackages.iloc[0, 0]))
print(newPythonPackagePath)

 

Now, assign the variable that contains the package location to the target.

 

# Step 2: Install packages in a shared folder (run this once)
# Install packages into a shared folder (run this once)
Alteryx.installPackages(package=["pdfplumber", "beautifulsoup4"], install_type=f"install --target={newPythonPackagePath}")

 

Then assign this same variable to the sys path append method.

 

# Step 3: Append the shared folder to Python's path
import sys
sys.path.append(f"{newPythonPackagePath}")
print(sys.path)

 

Finally, you can import your libraries from any machine that has access to the folder. This will happen automatically because of the previous step:

 

# Step 4: Import the installed libraries
import pdfplumber, beautifulsoup4

 

Tip: You can also parametrize the libraries to import/install in the same way that you did for the package!

 

Mastering the game

 

You can even share workflows with the Python library already packed. Just export your workflow as a package, open the package with a zip manager (I use 7-zip, it's an open-source software), and add the Python Packages folder inside of it. The workflow must be parametrized to import the libraries with relative paths. By doing this, the end user can just run the workflow, and everything will run on the first try.

 

I did this for this community gallery workflow; you can download and take a look: Community Gallery - Convert .xls, .xlsm and .xlsb into .xlsx and parse the input.

 

Tip: You can do almost everything I've done here with R as well. You can do almost everything I've done here with R as well. Maybe in the future I'll do a post for R :).

Comments
BS_THE_ANALYST
14 - Magnetar
14 - Magnetar

@Felipe_Ribeir0 I've never clicked on an article faster! I love the proposed solutions. 

 

If a user selects a target folder, I suppose this will also allow them to select the Package Version for downloading? Kind of like a virtual environment almost? 

 

Also, great tip on zipping the python packages when sending a workflow and adding that into the exported workflow. There's definitely use cases there! 👏

Felipe_Ribeir0
16 - Nebula

@BS_THE_ANALYST thanks :)

Yes, you can also select the package version (this other article is great for getting this type of command https://knowledge.alteryx.com/index/s/article/How-To-Use-Alteryx-installPackages-in-Python-tool-1583...):

Screenshot 2025-01-28 123435.png


 
hora
5 - Atom

@Felipe_Ribeir0  Hi, do I need admin privileges initially to install the python package to the network folder initially? I.e. Step 1

installpythonpackages.png

Thanks 

Felipe_Ribeir0
16 - Nebula

Hi @hora 

 

No, write privileges are enough.

hora
5 - Atom

Hi @Felipe_Ribeir0 , Thanks for getting back to me. But looks like in order to use the Install Package method, I need to first open Designer with Administrator Rights. Is this correct? Thanks.

 

adminrightspythoninstall.png