Select to view content in your preferred language

Run ArcGIS Desktop (Python 2x), Pro (Python 3x), and Anaconda Python 2.7 all on the same machine?

3956
18
Jump to solution
11-28-2018 08:35 AM
SamGuilford
Regular Contributor

I posted this as a comment on this thread, but as the OP's answer involved messing around copying and pasting files, I think it warrants a new question:

I'm currently running ArcGIS Desktop 10.6 (python 2.7) and ArcGIS Pro 2.2.4 (python 3x) on the same machine. I have also installed the Anaconda Python 2.7 32-bit distribution so I can use arcpy in the Spyder IDE. However, this means that some basic tools in Pro now throw errors when I try to run them - I assume because it's trying to access the older version of Python. Does Esri have any official suggestions?

Thank you.

0 Kudos
18 Replies
DanPatterson_Retired
MVP Emeritus

To reiterate Curtis Price‌'s comment

sys.exec_prefix
'C:\\ArcGISPro\\bin\\Python\\envs\\arcgispro-py3'

sys.executable
'C:\\ArcGISPro\\bin\\Python\\envs\\arcgispro-py3\\pythonw.exe'

#---- ArcGIS Pro install folder 'C:\\ArcGISPro ... yours will differ
ShaunWalbridge
Esri Regular Contributor

OK, yes those entries for 10.6 are causing the problem -- you can see on sys.path that they precede the actual places you want to be finding Pro DLLs, which causes the crash. Can you report what the below reports?

import glob
import os
import site

print("PYTHONPATH: {}".format(os.environ.get("PYTHONPATH", "undefined")))
print("PYTHONHOME: {}".format(os.environ.get("PYTHONHOME", "undefined")))

for loc in site.getsitepackages():
    for pth in glob.glob(os.path.join(loc, "*.pth")):
        print(pth)
        with open(pth, 'r') as f:
            print(f.read())

That should help debug things.

Thanks,

Shaun

SamGuilford
Regular Contributor

Hi Shaun - here's what I got:

0 Kudos
ShaunWalbridge
Esri Regular Contributor

OK, thanks. The issue is that the PYTHONPATH variable is set. PYTHONPATH is tricky, because it is used in the initialization of Python and will preempt other settings on the machine. We fixed a bug for ignoring PYTHONPATH in Pro 2.3, but unsetting this variable should be enough to fix your machine. You can find the environment variables by pressing Win+Break > Advanced System Settings > Environment variables and removing PYTHONPATH entries from the user and system variable panes if it exists. This page on modifying environment variables may be helpful: https://www.computerhope.com/issues/ch000549.htm 

Once you've unset that, you can check that its correct by closing and reopening. You'll have to fully close e.g. a Python Command Prompt session for these to be flushed, but if it works, your Pro should work again and you shouldn't see any 10.6 references when checking sys.path.

Cheers,

Shaun

curtvprice
MVP Esteemed Contributor

Shaun: great solution having Pro's environment ignore PYTHONPATH, that should save a lot of trouble for users! Color me pleased.

0 Kudos
ShaunWalbridge
Esri Regular Contributor

Yes, I'm happy to see this fix go in too! One thing I should note -- it actually retains the PYTHONPATH value, but makes them a lower priority than the DLLs for the environment that is driving Pro. This ensures that Pro will work correctly, but will still allow someone who relied on PYTHONPATH for sharing e.g. a Python module to show up in Pro. The PYTHONPATH fix won't help on the command line, because that's a setting built into the python.exe. For posterity, if anyone hits this on the command line, you can start Python with `python -E` to ignore Python environment variables, or better yet unset PYTHONPATH. If you do need to inject additional locations for Python to find modules, add a .pth file which includes the path into Lib\site-packages.

SamGuilford
Regular Contributor

This did it - simple, yet I never thought to check there. Thanks!

0 Kudos
ShaunWalbridge
Esri Regular Contributor

Great! Glad we figured it out.

0 Kudos
curtvprice
MVP Esteemed Contributor

I'm guessing what's going on is you installed your non-ArcGIS Python and used the installer's defaults to mess with the global windows system paths. This will definitely break Esri's Python instances because the Python sys.path includes folders that conflict with the Python you are using. From Pro, try this to see what's in the python path.

import sys
print(sys.executable)
print("\n".join(sys.path)‍‍)‍‍

Maybe the best solution here is to totally remove Anaconda, repair install ArcGIS Desktop and ArcGIS Pro.

Using Anaconda modules from the ESRI python environment - USGS OEI/Enterprise GIS - myUSGS Confluenc...