PROBLEM

Unable to import ArcPy in ArcMap

Last Published: September 16, 2022

Description

Users are unable to import or load ArcPy in ArcMap with the installed version of Python.

Cause

There are several possible causes:

  • A problem occurred during the installation of Python while installing ArcGIS Desktop.
  • The incorrect path to the default Python installation is being provided in the Windows Environment Variables.
  • An incorrect folder is used for the PythonWin installation (if applicable).
Note:
Users can install different versions or bit versions of Python. As of version 10.1, ArcMap requires Python 2.7.x (32-bit). For more information, refer to the following article, FAQ: What version of Python is used in ArcGIS?

Using a version of Python other than the version expected with ArcGIS can lead to compatibility issues.

Solution or Workaround

Use one or all of the following solutions to resolve this issue.

Change the association of Python to use 32-bit Python
For more information, refer to the following FAQ: Why do Python scripts fail on a machine with both ArcGIS for Server and Desktop Installed?

Change the path to the python.exe file in the Windows Environment Variables Path variable

  1. Access the Environment Variables. The location of the Environment Variables differs based on the operating system.
  2. Under the System variables column, find the Path variable, select it, and click the Edit button.
  3. In the Variable value text box, locate and remove any existing path(s) to any python.exe file(s). Remove only the text between the semicolons.
  4. At the end of the Variable value text box, add a new semicolon and add the path to the Python.exe file installed by ArcGIS for Desktop, found here: C:\Python27\ArcGIS10.x
  5. Click OK to save the changes.

Add the path needed by modifying the .pth file

  1. Navigate to C:\Python27\ArcGIS10.x\Lib\site-packages.
  2. Using a text editor, such as Notepad, open the Desktop10.x.pth file.
  3. Verify the following lines are present in the text file:
    • C:\Program Files (x86)\ArcGIS\Desktop10.x\bin
    • C:\Program Files (x86)\ArcGIS\Desktop10.x\ArcPy
    • C:\Program Files (x86)\ArcGIS\Desktop10.x\ArcToolbox\Scripts
  4. Add any missing paths to the file.
  5. Save the .pth file.

Repair the ArcGIS for Desktop installation

  1. Remove any ArcGIS10.x folders from the following directory: C:\Python27.
  2. Repair ArcMap using one of the following steps:
    • Rerun the installation tool, and click the Repair radio button.
      [O-Image] Repair
    • Navigate to the Control Panel > Programs > Programs and Features > Uninstall a program, and double-click ArcGIS for Desktop. Click the Repair radio button.

If using PythonWin:
Without ArcMap, the default installation path for PythonWin is:

C:\Python27\Lib\site-packages\pythonwin\Pythonwin.exe

Instead, PythonWin must be installed in the following path:

C:\Python27\ArcGIS10.x\Lib\site-packages\pythonwin\Pythonwin.exe

To ensure the correct default path is used during installation, uninstall PythonWin, follow Step 4 to repair ArcMap, and reinstall PythonWin.

Note:
If users have ArcGIS for Server installed on the same machine, a 64-bit Python is also installed. This leads to the script calling the wrong bit version of Python.
Users are unable to select the default installation path for PythonWin during installation. The steps to repair ArcMap are crucial to ensure the correct destination path.

Article ID:000012334

Software:
  • ArcMap 10 x

Get help from ArcGIS experts

Contact technical support

Download the Esri Support App

Go to download options

Related Information

Discover more on this topic