I want to have an Anaconda environment that will use the Python interpreter installed with ArcGIS Pro.
I am working in Windows. I have been using Anaconda Prompt to configure virtual environments, and this works fine. However, I would like to create an Anaconda virtual environment that uses the Python interpreter installed with ArcGIS Pro, so that I can import ArcPy and use ArcPy in that environment.
The Python interpreter that I think I should use is in C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\python.exe
When I run conda info --envs I get something like C:\Users\MyName\Anaconda3
for all of my environments. I think I would like to change that path to C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\python.exe
Is this the right approach, and is this possible? Is there another (or better) way to use ArcPy in conda environments if I installed Anaconda first?
2 Answers 2
I'm no expert on Anaconda, but I've been using my own (not ArcGIS's) install of Miniconda to activate and use the conda environment provided by ArcGIS Pro. My setup:
- ArcGIS Pro 3.1.2 (latest)
- Miniconda 23.1.0 (latest)
- Windows 11
- Powershell (via windows terminal) 7.3.5 (have to run
conda init powershell
to make it work with ps)
In the terminal, I run conda activate 'C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3'
to use activate the environment. I never run the silly special command prompt shortcuts that ArcGIS provides. I can run geoprocessing scripts directly from the terminal, without ArcGIS open. VSCode also sees the ArcGIS environment fine and can use it for autocomplete, though some of the arcpy packages don't 'appear' in autocomplete for some reason (that I suspect has to do with how Esri has constructed arcpy). I can also run Jupyter notebooks that use arcpy in VSCode, using the extension from microsoft.
I don't modify this environment though. If I did want to do that, I'd probably clone the ArcGIS environment and modify the clone. (Actually, I had made a clone with my own install of Miniconda for everyday use, until I realized I could just use the 'mother' copy.) I have, on occasion, used venv along with my conda env when I needed some random package.
I'm not sure if that will answer your question, but hopefully is at least helpful.
-
1You can add the path of the ArcGIS Pro
envs
folder to your existing conda config file to make your existing installation aware of Pro's environments:conda config --add envs_dirs "C:\Program Files\ArcGIS\Pro\bin\Python\envs"
Then you should be able to runconda activate arcgispro-py3
without having to specify the full path.jslatane– jslatane2023年11月20日 16:17:36 +00:00Commented Nov 20, 2023 at 16:17 -
1@jslatane Thanks! That's a super useful tip. I just made a powershell function
activateArcPy
to save myself typing, but having conda see the other envs in ArcGIS Pro would be helpful when using multiple envs.Benny Jobigan– Benny Jobigan2023年11月21日 09:51:25 +00:00Commented Nov 21, 2023 at 9:51
ArcGIS Pro already includes the conda
package management system. It's separate to the Anaconda conda that you installed.
ArcGIS Pro comes with a base read-only conda environment arcgispro-py3
.
To use the ArcGIS Pro conda
command, use the Python Command Prompt shortcut in your Start Menu -> ArcGIS Pro entry. You can also run c:\Program Files\ArcGIS\Pro\bin\Python\scripts\proenv.bat
from any command prompt.
To make changes (install packages etc.) to your ArcGIS Pro python env you need to clone your base env and modify that. Go into ArcGIS Pro -> settings -> python -> manage environments and clone your default arcgispro-py3 environment, then set the new clone as default.
Further information:
-
This isn't right, it is possible to do it as shown in @Benny Jobigan's answer.jslatane– jslatane2023年11月20日 16:20:27 +00:00Commented Nov 20, 2023 at 16:20
Explore related questions
See similar questions with these tags.
where conda
in the command prompt? Does it listC:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3
or something similar?