Error in importing arcgis.gis module

07-19-2018 07:25 AM
New Contributor III

My python script for ArcGIS API work perfect in jupyter notebook. But to automate the task, I downloaded it as a python script and run from a bat file on Windows 7. But the call  "from arcgis.gis import GIS" fails with these errors. Any idea?

Traceback (most recent call last):
  File "W:\gis_data_admin\Admin\Scripts\BHP_AGOL\", line 8, in <module>
    from arcgis.gis import GIS
  File "C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\Lib\site-packages\arcgis\", line 3, in <module>
    from . import features, geoanalytics, geocoding, geometry, geoprocessing, network, raster, realtime, schematics, mapping
  File "C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\Lib\site-packages\arcgis\features\", line 21, in <module>
    from .feature import Feature, FeatureSet, FeatureCollection
  File "C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\Lib\site-packages\arcgis\features\", line 16, in <module>
    from arcgis.gis import Layer
  File "C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\Lib\site-packages\arcgis\gis\", line 929
SyntaxError: Non-ASCII character '\xe2' in file C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\Lib\site-packages\arcgis\gis\ on
line 930, but no encoding declared; see for details

Tags (2)
0 Kudos
4 Replies
MVP Esteemed Contributor

Can you share the contents of the Windows batch file?

0 Kudos
New Contributor III

set PATH=C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3;C:\Program Files\ArcGIS\Pro\bin\Python\Scripts;C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\Scripts;%PATH%
set PYTHONPATH=C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\Lib\site-packages;%PYTHONPATH%

set WORK_DIR=W:\gis_data_admin\Admin\Scripts\BHP_AGOL

python --version

----- below is the content of this py file generated from jupyter download -------

# coding: utf-8

# In[1]:

from arcgis.gis import GIS   # failed here


0 Kudos
New Contributor III

Ok, don't know why, but if I replace my python script call with

"C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\python.exe"

Then everything works fine, both arcgis.gis and pandas

0 Kudos
MVP Esteemed Contributor

As Jeff Bigos suggests in your related question ,  see Run stand-alone scripts—ArcPy Get Started | ArcGIS Desktop .  The documented way to run a stand-alone script using ArcGIS Pro Python distribution is:

How do I run a stand-alone script?

"c:\Program Files\ArcGIS\Pro\bin\Python\scripts\propy.bat"

Here, propy.bat acts as a replacement for calling python.exe.

Why would I want to use propy.bat?

While working in an ArcGIS Pro project, you could create and use the new conda environment with specific sets and versions of Python packages. For example, when running stand-alone scripts, if you run c:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\python.exe (the default conda environment for ArcGIS Pro), you would not necessarily have the same set of packages as you are using inside the ArcGIS Pro application. This is why you would want to use propy.bat: it determines the application’s active conda environment and activates it in your stand-alone script.

0 Kudos