0

This question already has an answer here:

Whenever ArcGIS Desktop is installed, it installs its own installation of Python 2.7 plus Numpy. Yet, I already have many different versions of Python installed in my machine and do not want to have ArcGIS' redundant new version of Python installed (nonetheless, in as a high-level folder as `C:\Python27').

How could I configure ArcGIS to use a Python installation that is already present in the computer somewhere else and then uninstall the one that comes with ArcGIS?

marked as duplicate by KHibma, Andre Silva, HDunn, jbchurchill, xunilk Jan 2 at 15:49

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • 2
    You can, but it's not recommended. ArcGIS requires specific versions of numpy and you run into trouble if you try to use a different version. See this article for the required versions for your version of ArcGIS. You're not really using ArcGIS 10.0 are you? That version is ancient and long unsupported. – user2856 Jan 2 at 0:27
  • @KHibma The accepted and comments in that question end up being quite unrelated to my question. – blipblop Jan 2 at 2:17
  • @Luke Thanks for your input. I have read in multiple places that it is not recommended. Yet, I can't seem to find any instructions anywhere on how to do it. At the very least, is it possible to make ArcGIS install its own Python in a path I choose myself? This at least could mitigate my problem – blipblop Jan 2 at 2:20
  • The ArcGIS installer always installs Python in a user-specified location. – Vince Jan 2 at 13:40
1

This is definitely what you don't want to do but..

Option 1

When installing your python distribution you can select the option to set it as main python environment. This is definitely something that the Anaconda installer supports. Alternatively you can manually modify the registry keys pointing to the ArcGIS python executable. An example of those keys is Computer\HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Python.NoConFile\shell\open\command and you can find them by searching the "C:/Python27" path (default location for the ArcGIS python environment)

Option 2

You can install a new python environment in the expected path for the ArcGIS environment.

Please keep in mind that the ArcGIS products do modify the environment before running any python script. You can observe that by printing information like

import sys
print(sys.executable)
print(sys.path)
import os
print(os.environ)

But why would you want to do that?

Not sure why you are asking that, as any solution I can think of is hacky and inefficient, and as per comments will likely break your ArcGIS.

You could achieve a similar outcome by spawning a subprocess that uses your already existing python environment for example. Something like that would work nicely when executed from within the ArcGIS python:

import os
import subprocess

my_env = os.environ.copy()
# Do stuff with your environment if needed
py_exe = "C:/User/blabla/miniconda2/pythonw.exe"

startupinfo = subprocess.STARTUPINFO()
# the following may be needed to hide cmd windows spawning 
# startupinfo.dwFlags = subprocess.STARTF_USESHOWWINDOW
# startupinfo.wShowWindow = subprocess.SW_HIDE

cmd_line = ['python.exe', 'your_python_script.py', 'any', 'argparse', 'argument']
run = subprocess.Popen(cmd_line, executable=py_exe, env=myenv, stdout=subprocess.PIPE, stderr=subprocess.PIPE, startupinfo=startupinfo, cwd=os.getcwd())

output_stream, error_stream = run.communicate()
# if you want to print the output/error

if run.returncode > 0:
    raise RuntimeError('The process failed with the following error: {0}'.format(error_stream))

You may be able to get away with less, but I prefer to give you the choice to remove lines of code.

  • +1 for subprocess – Tom Jan 7 at 16:27

Not the answer you're looking for? Browse other questions tagged or ask your own question.