ArcGIS 10.2.2 comes with Python 2.7.5 install pip, and configure gdal and arcpy tutorial

premise

ArcGIS 10.2.2 has been installed (with Python 2.7.5)

Add environment variables to Path for Python (set to D:\Python 2.7\ArcGIS10.2)

Insert picture description here

Install pip for Python 2.7.5 that comes with ArcGIS

        Because Python2 does not come with pip like Python3, in order to install pip for ArcGIS's own Python, two steps are required: the first step is to install setuptools; the second step is to install pip .
1. First go to the official website of setuptools: https://pypi.org/project/setuptools/42.0.2/ . Check whether the version supports Python2.7, then download the setuptools-42.0.2.zip and unzip it to the Python2.7.5 directory.
Insert picture description here
Insert picture description here

Insert picture description here
Then in the D:\Python 2.7\ArcGIS10.2\setuptools-42.0.2 directory, hold down shift and right-click to open the cmd command line window, enter the following:

python setup.py install

The result after setuptools is installed:
Insert picture description here
2. First go to the pip official website: https://pypi.org/project/pip/19.3.1/ . Check whether the version supports Python2.7, and then you need to download the file pip-19.3 required for pip installation .1.tar.gz (the version used here is 19.3.1 ), the decompressed folder pip-19.3.1 is placed here in the Python2.7.5 directory. Then in the Python 2.7.5 directory, hold down shift and right-click to open the cmd window, enter the following:

python setup.py install

Insert picture description here
Insert picture description here

Insert picture description here

Insert picture description here

Insert picture description here
Then there will be pip.exe program in the D:\Python 2.7\ArcGIS10.2\Scripts directory.
Insert picture description here

Pip install gdal in python environment

Open the link of Unofficial Windows Binaries for Python Extension Packages: https://www.lfd.uci.edu/~gohlke/pythonlibs/ .
Insert picture description here
Use Ctrl+F to find GDAL, and then find the whl file corresponding to the python version, here we will GDAL Download the -2.2.4-cp27-cp27m-win32.whl file and place it in the D:\Python 2.7\ArcGIS10.2\Scripts directory, then hold down shift in this directory and click the right mouse button to open the cmd command line window , Enter the following in the command line:

pip install GDAL-2.2.4-cp27-cp27m-win32.whl

The result after running is shown in the figure below, gdal is installed successfully;
Insert picture description here

View all libraries installed by Python 2.7.5

You can go to the file directory D:\Python 2.7\ArcGIS10.2\Lib\site-packages to view the packages we have installed
Insert picture description here

Python import arcpy problem solving

In the D:\Python 2.7\ArcGIS10.2\Lib\site-packages directory, open desktop10.2.pth to view the directory corresponding to ArcGIS Desktop.
Insert picture description here
Insert picture description here

Method 1: Add the environment variable PYTHONPATH, set it to directly create a new "PYTHONPATH" in the environment variable and add three directories corresponding to ArcGIS Desktop to
D:\ArcGIS 10.2.2\Desktop10.2\bin
D:\ArcGIS 10.2 .2\Desktop10.2\arcpy
D:\ArcGIS 10.2.2\Desktop10.2\ArcToolbox\Scripts
Insert picture description here

Method 2: Install pywin32 in pip mode (using the pywin32-228-cp27-cp27m-win32.whl file), first download the files required by pywin32 (note that it corresponds to the Python version): https://pypi.org/project/pywin32/ #files ., download the pywin32-228-cp27-cp27m-win32.whl file and store it in the D:\Python 2.7\ArcGIS10.2\Scripts directory, also in this directory, hold down shift and click the right mouse button to open the cmd command line Window, input

pip install pywin32-228-cp27-cp27m-win32.whl

Insert picture description here
Insert picture description here
After the installation is successful, go to the python installation directory (which comes with GIS). Generally, find the file with the suffix "pywin32.pth" in D:\Python 2.7\ArcGIS10.2\Lib\site-packages. This file is used for When telling python to import the package, you can also search the path from here, and add the three directories corresponding to ArcGIS Desktop to the end.
Insert picture description here
Insert picture description here

PyCharm instance running (check whether the arcpy and gdal libraries can be called)

Insert picture description here

Install P with Charm, create a new project, select ArcGIS Python 2.7.5 as the Python compiler, and then create a new Python file in the project, enter the content, and you can view

Insert picture description here
Insert picture description here

Insert picture description here

Guess you like

Origin blog.csdn.net/jing_zhong/article/details/108873363