I have a Python3/ArcPy script that must be moved from Windows to be run on a Linux system. From what I understand the only option is to run it on ArcGIS Server. So I had a system set with with Ubuntu and Arcgis Server 11 (putty/ssh access only). Now I'm trying to figure out how to run my script. Reading the documentation a number of questions came up.
Solved! Go to Solution.
Thanks @Brian_Wilson. I only have a single script that I have to run and I don't foresee having to install additional packages so I was hoping to avoid everything related to conda (not sure if that is even possible).
That said, I was able to get my script running. Here is how I did it.
This is what the modified file looks like
#!/bin/bash
installDir=$(cd $(dirname $0)/.. && pwd);export installDir
installer=$(stat -c %U $installDir)
arcenv=$installDir/framework/etc/arcenv
if [ -f $arcenv ]; then
. $arcenv
if [ "x$DISPLAY" = "x" ]; then
. $installDir/framework/runtime/xvfb/init_Xvfb.sh
StartXvfb > /dev/null 2>&1
fi
# don't preload libjsig.so for standalone app
unset LD_PRELOAD
export CONDA_PREFIX="C:\Program Files\ArcGIS\Server\framework\runtime\ArcGIS\bin\Python\envs\arcgispro-py3"
export CONDA_DEFAULT_ENV="$CONDA_PREFIX"
wine64 "$CONDA_PREFIX\python.exe" "/home/dmorrison/cw/test_linkage_mapper.py"
else
echo "Unable to set up environment. Cannot find $arcenv"
fi
I have not used the Linux version of Server in a few years now, they might have a group (ie in /etc/group) so if you don't want to run as "root" or user "arcgis" you might get better access if you add your normal user to that group. I think some Esri Windows programmers read a book and then declare themselves Linux programmers but they might have learned more since then. (I did the opposite, I read a Windows book once... 🙂
I am stuck running Esri software on Windows only but rely extensively on Conda in Debian for related work.
Running as myself I would use the Esri copy of Conda to clone the Python that Esri installed and then use the clone. It might endlessly battle you over authorization when you "import arcpy" and you will give up and run as "arcgis" and say "this is really not so bad."
I like to have a separate Conda environment so I can add packages to it and have a "fall back" position instead of contaminating the Esri install with packages that might trigger dependencies and break their version.
I also tend to set up special environments for different projects, like, one for Flask apps and one for GDAL and one just for ArcGIS API and one for automated COVID19 data collection (oh halcyon days of yore).
When I want to run a script standalone (for example from crontab) I put a shebang line in it instead of messing with "conda activate" in wrapper scripts. For example, this runs once a day to check on links and files for me
#!/usr/bin/env -S conda run -n arcgis_tools --no-capture-output python
# Remember to set credentials etc in the .conda/envs/arcgis_tools/etc/conda/activate.d/ files.
"""
Check for missing taxmap PDF files.
Use the -v option to get output even when nothing is missing.
Default is to be quiet for running from crontab.
This script is part of arcgis_tools.
"""
It's using the 'env' tool to find my copy of conda and then using it to run the python in the file using the arcgis_tools conda environment. I can move Conda or put it on a different machine and as long as I have it in the PATH it will still run the correct python.
This depends on you setting your PATH to include "conda". I do that manually by adding CONDA_PATH="something" and PATH="$PATH:$CONDA_PATH" in my .bashrc file. Conda can help you by making you run "conda init" which will edit your .bashrc. You can try that. After you figure out where your "conda" lives so you can run it. 🙂 I prefer to simply edit the .bashrc file myself.
Thanks @Brian_Wilson. I only have a single script that I have to run and I don't foresee having to install additional packages so I was hoping to avoid everything related to conda (not sure if that is even possible).
That said, I was able to get my script running. Here is how I did it.
This is what the modified file looks like
#!/bin/bash
installDir=$(cd $(dirname $0)/.. && pwd);export installDir
installer=$(stat -c %U $installDir)
arcenv=$installDir/framework/etc/arcenv
if [ -f $arcenv ]; then
. $arcenv
if [ "x$DISPLAY" = "x" ]; then
. $installDir/framework/runtime/xvfb/init_Xvfb.sh
StartXvfb > /dev/null 2>&1
fi
# don't preload libjsig.so for standalone app
unset LD_PRELOAD
export CONDA_PREFIX="C:\Program Files\ArcGIS\Server\framework\runtime\ArcGIS\bin\Python\envs\arcgispro-py3"
export CONDA_DEFAULT_ENV="$CONDA_PREFIX"
wine64 "$CONDA_PREFIX\python.exe" "/home/dmorrison/cw/test_linkage_mapper.py"
else
echo "Unable to set up environment. Cannot find $arcenv"
fi
Hello,
What's the purpose of this part of the code?
/home/dmorrison/cw/test_linkage_mapper.py