Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am working on a Python package that has a mixture of command line tools and ArcToolbox tools. For Python development it is really useful to use VirtualEnv, especially when working with installers. Is there a way to have either ArcMap or ArcCatalog recognize a current VirtualEnv session in Python, so that when a custom tools is executed it is using the VirtualEnv Python paths and packages instead of the default Python paths and packages at c:\Python26\ArcGIS10.0?

share|improve this question
up vote 9 down vote accepted

That's not built into the application, but I assume running the batch file that sets up the virtualenv in a cmd.exe session and then running arcmap.exe from the same DOS box should get you your virtualenv. ArcMap and friends will modify the path slightly to include the install's arcgisscripting and arcpy.

Edit: you will need to explicitly call the activate_this script from within the Python window in desktop apps to get this to work. If I have a VirtualEnv in c:\Users\jason\myenv I will issue execfile(r'C:\Users\jason\myenv\Scripts\', {'__file__': r'C:\Users\jason\myenv\Scripts\'}) from the Python window in an ArcGIS desktop app to get it running.

share|improve this answer
That doesn't appear to work. I created a VirtualEnv workspace, activated it, then installed a package that I want to test inside of ArcCatalog. So far so good. If I open a Python shell inside this VirtualEnv session and import the newly installed packages - the import works. If I then launch ArcCatalog and try to call one of these packages from a toolbox script - it does not work. If I look at sys.path from the Python shell inside of ArcCatalog, it is showing the default Python directory for ArcGIS 10.0 (C:\Python26\ArcGIS10.0). – SagebrushGIS Mar 22 '11 at 17:24
Look into using the script also in the same Scripts directory of your VirtualEnv from the Python window in ArcCatalog and friends. I was able to execute execfile(r'C:\Users\jason\myenv\Scripts\', {'__file__': r'C:\Users\jason\myenv\Scripts\'}) and get my VirtualEnv bootstrapped from within ArcMap. – Jason Scheirer Mar 22 '11 at 19:43
Awesome! That did the trick. – SagebrushGIS Mar 22 '11 at 20:01

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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