This site uses different types of cookies, including analytics and functional cookies (its own and from other sites). To change your cookie settings or find out more, click here. If you continue browsing our website, you accept these cookies.
04-24-2019 09:21 AM - edited 02-07-2020 07:06 AM
How To: Use Alteryx.installPackages() in Python tool
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().
Prerequisites
Background Information
First of all, don't get confused: you can use either Alteryx.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+
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 that 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
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 per https://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 and above]
Example:
logger = Alteryx.importPythonModule("C:\\ProgramData\\PythonLibs\\logger")
logger.logging.info("Logger installed successfully")
Remark: With this method, a module does not appear as installed in 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\<YOUR USERNAME>\Documents\Personal\PythonPckg).
Example:
Alteryx.installPackages(package="file: <your directory\filetoinstall.tar.gz>")
Alteryx.installPackages(package="file:C:\tsmithers\downloads\nlptoolkit-dictionary-1.0.4.tar.gz")
Procedure: Installation with a proxy in place
This allows the option of adding a 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="<mypackage>",install_type="install --proxy proxy.server:port")
#With password and username
Alteryx.installPackages(package="<mypackage>",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:
Additional Resources
This article is awesome! Thanks for all the help @PaulN
How would one adapt this
Alteryx.installPackages(package="wordcloud", install_type="install --no-index --find-links=C:\\ProgramData\\PythonWheels")
to a network drive that has spaces in some of the folder names...
So far I have
Alteryx.installPackages(package="hyperapi",
install_type='install --no-index --find-links="\\xyx.org.com\\d\\w\\Space Here\\Alteryx\\Systems\\For System Use\\Hyper API"')
But I get the error
Command '['c:\\users\\name\\appdata\\local\\alteryx\\bin\\miniconda3\\pythontool_venv\\scripts\\python.exe', '-m', 'pip', 'install', '--no-index', '--find-links="\\xyz.org.com\\dfs\\wtops\\Space', 'Here\\Alteryx\\Systems\\For', 'System', 'Use\\Hyper', 'API"', 'hyperapi']' returned non-zero exit status 1.
I tried multiple ways with quotes. Is using network drive even possible? I wish whoever made this didn't put spaces in file path names.
Thanks for the article. The machine I use doesn't have admin rights to intall any s/w.
In that case am not able to run my codes that were running in IDE to adapt to alteyx due to package unavailability.
Its practically not possible for us to freely develop codes using the Alteryx python module when we have user restrictions on installing the packages. Having admin rights is the only way to install the packages to miniconda in Alteryx?
Can anything be done on this?
If this is not doable, I would suggest to have all the basic packages for data analysis pre installed in the Alteryx bundle without which this feature is not gonna be of great value add to the tool.
errors
Installing collected packages: soupsieve, beautifulsoup4 ERROR: Could not install packages due to an EnvironmentError: [WinError 5] Access is denied: 'c:\\program files\\alteryx\\bin\\miniconda3\\envs\\jupytertool_venv\\Lib\\site-packages\\soupsieve' Consider using the `--user` option or check the permissions.
CalledProcessError: Command '['c:\\program files\\alteryx\\bin\\miniconda3\\envs\\jupytertool_venv\\python.exe', '-m', 'pip', 'install', 'beautifulsoup4']' returned non-zero exit status 1.
After going through the same things, yes you absolutely need t o have an admin install this for you. I tried every work around I could think of, and at the end of the day had to wait for the admin to get back from vacation so I could get some tools installed.
We seem to be hitting some kind of SSL error when trying to import packages:
from ayx import Alteryx
Package.installPackages(['beautifulsoup4'])
Error:
Collecting beautifulsoup4 Could not fetch URL https://pypi.python.org/simple/beautifulsoup4/: There was a problem confirming the ssl certificate: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:749) - skipping Could not find a version that satisfies the requirement beautifulsoup4 (from versions: ) No matching distribution found for beautifulsoup4
Does anyone have any insight or support with this?
Thanks in advance
Ciaran
Hi @CiaranA,
Could you please try the following:
[global]
trusted-host = pypi.python.org
pypi.org
files.pythonhosted.org
3. Install package again via Python tool
Best,
Paul Noirel
Sr Customer Support Engineer, Alteryx
When running a workflow on alteryx server I can't install dependencies using Alteryx.InstallPackages(). It always causes a CalledProcessError with the error message just being that the command returned non-zero exit status 1. Even with debug=True set I don't get more information or even the stack trace like I would when running locally within the notebook. Are there any known issues when attempting to install python dependencies on the server? or is there configuration that may be interfering?
For reference the alteryx server is a corporate one and I do not have administrative access to it.
Your last comment is exactly why. You have to have admin privileges. The only way at this point to get it installed is to email your admin and make that request.
Hi Paul,
This is very helpful. Also, Is there a way to inventory all python libraries installed including ones that did not come with Alteryx?
Thanks,
Tim
Hi @TimN,
Thanks for the comment! So if you are trying to list the libraries available to the Python tool, last section of the article will do the trick.It will list the different packages "visible" in the Python environment used for the tool.
Hope that helps,
PaulN
Hi Team,
We have proxy internal URL to download/ install packages as follows.
pip install PyPDF4 -i (Internal URL)
from cmd. How to achieve the same using alteryx.
Please assist. Where to point source URL in the following
Alteryx.installPackage("logger")
Hi @ganeshkumars82,
Thanks for posting!
As mentioned in the article, Alteryx.installPackage() is a wrapper to pip (pip install by default).
Please try the following:
Alteryx.installPackages(package="PyPDF4",
install_type="install -i (internal URL)")
Best,
PaulN
Hi PaulN,
Awesome! Got it. It is working in my designer.
Another input please.
The solution is working fine in our Designer.
we need to publish in our Alteryx Private Gallery Server.
By Default, those non-standard packages will not be available.
1) How to install those similar libraries in our Gallery server. Do we need to login into server or we can install from local Designer. Please suggest, if you have steps to move forward. Thanks.
Hence, we can publish the workflow and our user can trigger from Gallery.
Regards,
Ganeshkumar S
@ganeshkumars82 Yes, you need to login to the server and install them. I was screen sharing with our admin when he installed some stuff I needed, and he opened up the alteryx on the server and installed it from there using the same way that we installed it on our local alteryx machine.
I am facing the same issue as @joejoe317 :
How to pass a path of a network drive that has spaces in some of the folder names?
Eg.
Alteryx.installPackages(package="openpyxli",
install_type='install --no-index --find-links="C:\\Users\\[username]\\Desktop\\folder name with space\\subfolder"')
Also how to pass relative path in install_type when the workflow is saved at same location.
@NanChaw It's been a while now. I think I resolved it by using a different command. I also could have resolved it by moving my path, I really do not remember. I will see if I still have any of the testing workflows I created to see which path I chose.
EDIT: Quick answer is no spaces allowed.
Longer answer of different methods to get it to work.
I ended testing two things. I do not have access to our server, so I had to work with the server admin on this.
The first I already mentioned. I just moved it to a network drive that didn't have any spaces. On our alteryx server we have a public area that we can put files. The security is based on groups, so I can only see what I put in there. This did not have any spaces, and obviously that worked.
The second was working with our server admin.
I had him do the following...
These are the steps that it took to install the Python API for hyper data file manipulations.
RDP into the alteryx server
open ADMIN Command line window
c:> cd "%PROGRAMFILES%\Alteryx\bin\Miniconda3\PythonTool_venv\Scripts"
c:> pip install "\\server-path\DropBox\whl\tableauhyperapi-0.0.8953-py3-none-win_amd64.whl"
You can see that this path also does not have spaces, but we are installing using pip, so you can have spaces here. The problem I believe with alteryx is they use their own functional wrapper. It seems like that are using the space as a split into an array of items. You can kind of see this in the error you get.
I have tried it with an encoded path and other methods, but have not been successful.
The second method bypasses alteryx all together in order to install the python package. Once it is installed, you can use it in alteryx. Obviously if you go this route, make sure the paths are correct, they may be different than ours.
This is a wonderful write-up, @PaulN.
Just wanted to add this bit to upgrade packages only if needed so you can include this for every extra package you use in your workflow so when changing env (publishing to Server), all packages get properly installed:
# List all non-standard packages to be imported by your
# script here (only missing packages will be installed)
from ayx import Package
Package.installPackages(['pandas'],install_type="install --upgrade-strategy only-if-needed")