I spend a lot of time writing arcpy Python scripts and executing them via the "Python Command Prompt" that gets installed with ArcGIS Pro, but I also spend a lot of time using the git bash shell for version control and other useful linux tools (e.g. sort, uniq, etc). "Python Command Prompt" is just a windows cmd window that runs a bat file to set up the conda pro environment and I was wondering how I might get this environment configured so I can execute my arcpy scripts from with the git bash window. Thanks!
Solved! Go to Solution.
The downside to this is that the conda environment is not getting activated.
Assuming you are in Windows and Pro is installed in the default location, you can use Pro's propy.bat file from a Git Bash window to call a script. That will activate Pro's conda environment and use its python.
"C:\Program Files\ArcGIS\Pro\bin\Python\Scripts\propy.bat" scriptname.py
Hi Gary,
One way that I use is to define an alias in ".bashrc" file for python3 interpreter. If you have a clone python environment point the alias to that python env.
alias python3='C:/Users/asharaf/AppData/Local/ESRI/conda/envs/arcgispro-py3-clone/python.exe'
and then in bash use python3 command.
Let me know if it works in your environment.
The downside to this is that the conda environment is not getting activated.
Assuming you are in Windows and Pro is installed in the default location, you can use Pro's propy.bat file from a Git Bash window to call a script. That will activate Pro's conda environment and use its python.
"C:\Program Files\ArcGIS\Pro\bin\Python\Scripts\propy.bat" scriptname.py
yes propy.bat works as well. Forgot to mention that I have activated my clone env and then use the alias in bash.
I tried this and it worked, but then I realized that you don't get any output until the script finishes. So my script that takes a minute to run and reports what it's doing every few seconds (something that gives me confidence that things are going well and it's not stuck anywhere) now just dumps all the output at the end. This is not really a workable solution. I would really love to stick to the git bash shell and dump the dos cmd shell forever but it still seems like that might not be possible.
Have you used print or addmessage for the status report? I can run the a simple script (see below) in Git Bash and it works fine.
I tried it with the both methods: 1) the one i always use (python3 alias) and 2) the one that Josh suggested. (using propy.bat file) and both works as expected.
What if you sleep for a few seconds after your two statements that ouput text, do you see the messages before the sleep or after?
yes it pauses after two print statements and then script ends.
import arcpy
import time
print(f"using print function...")
arcpy.AddMessage("using arcpy.add.message ...")
time.sleep(5)
my "arcpy.addmessage" statements are printed immediately but any and all simple print statements don't come out until the script ends (i.e. after the sleep statement)