Select to view content in your preferred language

python environment in bash git shell

3317
8
Jump to solution
02-16-2022 08:09 PM
GaryB
by
Occasional Contributor

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!

 

 

0 Kudos
1 Solution

Accepted Solutions
JoshKalovGIS
Occasional Contributor

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

 

View solution in original post

8 Replies
AzinSharaf
Frequent Contributor

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.

AzinSharaf_0-1645206468458.png

Let me know if it works in your environment. 

 

0 Kudos
JoshKalovGIS
Occasional Contributor

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

 

AzinSharaf
Frequent Contributor

yes propy.bat works as well. Forgot to mention that I have activated my clone env and then use the alias in bash.

0 Kudos
GaryB
by
Occasional Contributor

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. 

0 Kudos
AzinSharaf
Frequent Contributor

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. 

AzinSharaf_0-1645921408325.png

 

 

 

0 Kudos
GaryB
by
Occasional Contributor

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?

0 Kudos
AzinSharaf
Frequent Contributor

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)

 

0 Kudos
GaryB
by
Occasional Contributor

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)

0 Kudos