Community Spring Cleaning week is here! Join your fellow Maveryx in digging through your old posts and marking comments on them as solved. Learn more here!

Alteryx Server Discussions

Find answers, ask questions, and share expertise about Alteryx Server.

Setting up Python on Server

StephenR
Alteryx
Alteryx

What are the steps that are necessary to run a Python script on Alteryx Server?  I've installed the correct version of Python (2.7.13 in this case) and set the Environmental Variables (PATH = C:\Python27\).  The server permissions are set to allow the Run Command tool to work, I just need to get it to call out to Python properly.

Regards,
Stephen Ruhl
Principal Customer Support Engineer

3 REPLIES 3
DanS
9 - Comet

Hello, 

 

There's a great post on this here which instructs on how to get the Run Command tool working with Python. 

 

Also has a related blog post in the Solution for R scripts which would have a similar setup. 

 

 

StephenR
Alteryx
Alteryx

@DanS that's the post that I've been working off of.  Everything is working perfectly on my computer, and I've set up the environmental variables on my computer, and my co-workers computers, but it's not finding Python for them.  The environmental variables seem to be what everyone points to, but they are set up the same way.  On my system I've added C:\Python27\ArcGIS6410.4\ and C:\Python27\.  My co-worker has as well.  The server doesn't have ArcGIS so the path there is just C:\Python27\.  

Regards,
Stephen Ruhl
Principal Customer Support Engineer

_bo_licalzi
6 - Meteoroid

here a few more considerations on this that may help you.  When you set an environment variable, be sure you take not on whether you set the variable as a "user" or "system" environment variable.  On an alteryx server, there's setting for the scheduler to "Run As" a specific user, or the default user context in which the Alteryx server 'service' is running is as a system user (i.e. Local or Network Service).  This means you must have 'system' environment variables.

 

Also, I dont believe C:\python27 is enough.  you may also need to reference so scripts, libraries, and your bin executables can be found in the environment as well.

C:\[yourpythonversion]
C:\[yourpythonversion]\Scripts
C:\[yourpythonversion]\Library\bin

After creating or modifying and environment variable - either a system reboot is needed, or do what I refer to as, defibrillate your explorer.exe (i.e. task manager > processes > restart explorer.exe) - which will then be able to see the newly set vars.

 

Make sure to not add conflicting path entries as well.  For example, what if you're running python27 and python36?  Your path entries are different, but now there's multiple ways to reference python.exe

A consideration here, is to build either .bat files or powershell scripts, which then have the appropriate code to temporarily set the relevant environment variables for the session executing the script, so there no system level conflict.  In powershell, setting a temporary addition to the PATH variable is:

$RootPath = "C:\[yourpythonversion]"
$ScriptsPath = "C:\[yourpythonversion]\Scripts"
$BinPath = "C:\[yourpythonversion]\Library\bin"

$NewPath = $env:Path += ";$RootPath;$ScriptsPath;$BinPath"

 

Now...alteryx doesnt necessarily have a RunPowershell tool.  but that can be invoked in the RunCommand tool anyways, because a .bat file can easily do powershell execution.  Alteryx calls the .bat file as its 'run command', when then calls and executes a powershell script.

https://stackoverflow.com/questions/16436405/how-to-run-powershell-in-cmd

 

Temp environment variables can be set by command line syntax too of course.

 

Last but certainly not least - consider using the anaconda distro of python, especially if you plan to execute anything from scientific libraries such as SciPy, pandas, etc.  Anaconda will also take care of creating all the environment vars I listed too!

 

The other post everyone seems to refer to related to this topic is good - but still lacks some of the subtle system level considerations I mentioned that can definitely make things a bit painful in deployments.