Select to view content in your preferred language

Conda Powershell

2494
4
03-08-2023 08:39 AM
Status: Implemented
Labels (1)
ZacharyStauber1
Occasional Contributor

Vanilla Anaconda supports starting a Python environment in a Powershell window by running a script called conda-hook.ps1.  Since ArcGIS Pro conda runs different scripts to set up its environment for ArcGIS, the Powershell Shortcut module does not install properly (nor does Miniconda Powershell Shortcut), so it looks like Esri would have to create their own version of Powershell Shortcut in the "esri" channel.

Powershell is becoming much more popular than the old Command Prompt window, and I started writing scripts to automate GIS tasks using Python with 10.x, but I can't use it with Pro 3.x yet until there is a script that does what proenv.bat and conda-hook.ps1 does in a Powershell.

4 Comments
DanPatterson

are you referring to the files in this folder?

C:\... install folder ...\bin\Python\shell\condabin
ZacharyStauber1

Well, if I create a Conda environment with Anaconda or Miniconda, and open the shortcut from start, I get:

(base) PS C:\Users\zachary.stauber>

Ready for business.

But if I install the Powershell Shortcut module from ArcGIS Pro for an environment created from within Pro I get

& : The term 'C:\Users\ZACHAR~1.STA\AppData\Local\Temp\ArcGISProTemp17332\_MEI194722\shell\condabin\conda-hook.ps1' is
not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or
if a path was included, verify that the path is correct and try again.
At line:1 char:3
+ & 'C:\Users\ZACHAR~1.STA\AppData\Local\Temp\ArcGISProTemp17332\_MEI19 ...
+   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (C:\Users\ZACHAR...\conda-hook.ps1:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

conda : The term 'conda' is not recognized as the name of a cmdlet, function, script file, or operable program. Check
the spelling of the name, or if a path was included, verify that the path is correct and try again.
At line:1 char:108
+ ... roTemp17332\_MEI194722\shell\condabin\conda-hook.ps1' ; conda activat ...
+                                                             ~~~~~
    + CategoryInfo          : ObjectNotFound: (conda:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

And indeed there is a conda-hook.ps1 file in the vanilla Anaconda installation, but none under Pro's version.  Instead when Pro starts up a Conda command prompt, it runs something like proenv.bat or propy.bat, and they're quite complex so I don't know how to turn them into Powershell scripts that do the same thing.

Luke_Pinner

Should be available in Pro 3.1 since conda init has been implemented.  https://community.esri.com/t5/arcgis-pro-ideas/enhance-isolated-conda-installation-to-support/idc-p/...

ShaunWalbridge
Status changed to: Implemented

Powershell support was added with Pro 3.1 as @Luke_Pinner mentioned. It can be used by first configuring it with conda init, see this blog post for further details: https://www.esri.com/arcgis-blog/products/arcgis-pro/developers/conda-init-and-arcgis-pro/

If there's something else that you'd like to see on this front, feel free to add a comment and we can work to understand how it'd fit in.

Cheers, Shaun