<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: ModuleNotFoundError: No module named 'arcgis' in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/modulenotfounderror-no-module-named-arcgis/m-p/164901#M12651</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;A href="https://community.esri.com/blogs/dan_patterson/2016/08/14/script-formatting"&gt;/blogs/dan_patterson/2016/08/14/script-formatting&lt;/A&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;to rule out format issues and to provide line numbers for commentary&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 08 Jan 2019 19:11:08 GMT</pubDate>
    <dc:creator>DanPatterson_Retired</dc:creator>
    <dc:date>2019-01-08T19:11:08Z</dc:date>
    <item>
      <title>ModuleNotFoundError: No module named 'arcgis'</title>
      <link>https://community.esri.com/t5/python-questions/modulenotfounderror-no-module-named-arcgis/m-p/164900#M12650</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;I'm running Jupyter and trying to run this script to pull files from arcgis enterprise to a desktop folder and I am getting the following bolded error. What is needed to fix this?&amp;nbsp;&lt;/DIV&gt;&lt;DIV class=""&gt; &lt;/DIV&gt;&lt;DIV class=""&gt;# Version 1.2&lt;P&gt;&lt;/P&gt;import logging, os, re, datetime&lt;BR /&gt;from IPython.display import display&lt;BR /&gt;&lt;STRONG&gt;from arcgis.gis import GIS (&lt;SPAN class="" style="white-space: pre;"&gt;ModuleNotFoundError&lt;/SPAN&gt;&lt;SPAN style="white-space: pre;"&gt;: No module named 'arcgis')&lt;/SPAN&gt;&lt;/STRONG&gt;&lt;/DIV&gt;&lt;DIV class=""&gt; &lt;/DIV&gt;&lt;DIV class=""&gt;''' ********************** SCRIPT CONFIGURATION START ********************** '''&lt;P&gt;&lt;/P&gt;#What is the ID of the Feature Layer you want to download attachments from?&lt;BR /&gt;FeatureLayerId = 'XXXX'&lt;P&gt;&lt;/P&gt;#What are your ArcGIS Enterprise/ArcGIS Online credentials? This is case sensitive.&lt;BR /&gt;PortalUserName = 'XXXX'&lt;BR /&gt;PortalPassword = 'XXXX'&lt;BR /&gt;PortalUrl = 'XXXX'&lt;P&gt;&lt;/P&gt;#Where do you want your attachments stored?&lt;BR /&gt;SaveAttachmentsTo = 'S:\GIS\Pictures'&lt;BR /&gt;SaveLogsTo = 'Logging'&lt;P&gt;&lt;/P&gt;#How do you want your attachments stored? Options are GroupedFolder and IndividualFolder&lt;BR /&gt;#GroupedFolder - Attachments from every feature in each layer is stored in the same folder - attachments are renamed in the format OBJECTID-ATTACHMENTID-OriginalFileName&lt;BR /&gt;#IndividualFolder - A new folder is created for each OBJECTID, and associated attachments are stored in that folder - attachments are renamed in the format ATTACHMENTID-OriginalFileName&lt;BR /&gt;AttachmentStorage = 'GroupedFolder'&lt;P&gt;&lt;/P&gt;#Set to False if ArcGIS Enterprise cert is not valid&lt;BR /&gt;PortalCertVerification = True&lt;P&gt;&lt;/P&gt;#Setup logging - levels are DEBUG,INFO,WARNING,ERROR,CRITICAL&lt;BR /&gt;logging.basicConfig(level=logging.INFO)&lt;P&gt;&lt;/P&gt;''' ********************** SCRIPT CONFIGURATION END ********************** '''&lt;P&gt;&lt;/P&gt;&lt;SPAN&gt;#&lt;/SPAN&gt;&lt;A class="jive-link-external-small" href="https://community.esri.com/external-link.jspa?url=https%3A%2F%2Fstackoverflow.com%2Fquestions%2F273192%2Fhow-can-i-create-a-directory-if-it-does-not-exist" rel="nofollow" target="_blank"&gt;https://stackoverflow.com/questions/273192/how-can-i-create-a-directory-if-it-does-not-exist&lt;/A&gt;&lt;BR /&gt;def createFolder(folderPath):&lt;BR /&gt; if not os.path.exists(folderPath):&lt;BR /&gt; try:&lt;BR /&gt; os.makedirs(folderPath)&lt;BR /&gt; except OSError as e:&lt;BR /&gt; if e.errno != errno.EEXIST:&lt;BR /&gt; raise&lt;P&gt;&lt;/P&gt;def renameFile(currentAttachmentPath, newAttachmentPath):&lt;BR /&gt; #Rename file - ensure new attachment path does not exist already&lt;BR /&gt; if not os.path.exists(newAttachmentPath):&lt;BR /&gt; os.rename(currentAttachmentPath, newAttachmentPath)&lt;BR /&gt; logger.info('{} being renamed as {}'.format(currentAttachmentPath, newAttachmentPath))&lt;BR /&gt; else:&lt;BR /&gt; logger.warning('Not able to rename {} as {} because file already exists. Removing {}'.format(currentAttachmentPath, newAttachmentPath, currentAttachmentPath))&lt;BR /&gt; os.remove(currentAttachmentPath)&lt;P&gt;&lt;/P&gt;#Create specified folder if it does not exist already&lt;BR /&gt;createFolder(SaveAttachmentsTo)&lt;BR /&gt;createFolder(SaveLogsTo)&lt;BR /&gt; &lt;BR /&gt;#Logging level specified in script configuration&lt;BR /&gt;logger = logging.getLogger(__name__)&lt;BR /&gt;logFileName = datetime.datetime.now().strftime('%Y-%m-%d %H-%M-%S')&lt;BR /&gt;fileHandler = logging.handlers.RotatingFileHandler('{}/{}.log'.format(SaveLogsTo, logFileName), maxBytes=100000, backupCount=5)&lt;BR /&gt;formatter = logging.Formatter('%(asctime)s %(levelname)s %(relativeCreated)d \n%(filename)s %(module)s %(funcName)s %(lineno)d \n%(message)s\n')&lt;BR /&gt;fileHandler.setFormatter(formatter)&lt;BR /&gt;logger.addHandler(fileHandler)&lt;P&gt;&lt;/P&gt;logger.info('Script Starting at {}'.format(str(datetime.datetime.now())))&lt;P&gt;&lt;/P&gt;#Connect to GIS, and get Feature Layer information&lt;BR /&gt;if PortalUserName == '' and PortalPassword == '':&lt;BR /&gt; gis = GIS()&lt;BR /&gt;else:&lt;BR /&gt; gis = GIS(PortalUrl, PortalUserName, PortalPassword, verify_cert=PortalCertVerification)&lt;P&gt;&lt;/P&gt;downloadCounter = 0&lt;BR /&gt;nonDownloadCounter = 0&lt;BR /&gt;downloadSizeCounter = 0&lt;P&gt;&lt;/P&gt;itemObject = gis.content.get(FeatureLayerId)&lt;BR /&gt;logger.info('Iterating through layers in Feature Layer "{}"'.format(itemObject.name))&lt;BR /&gt;display(itemObject)&lt;P&gt;&lt;/P&gt;#Loop through layers in Feature Layer&lt;BR /&gt;for i in range(len(itemObject.layers)):&lt;BR /&gt; featureLayer = itemObject.layers&lt;I&gt;&lt;BR /&gt; &lt;BR /&gt; #Skip layer if attachments are not enabled&lt;BR /&gt; if featureLayer.properties.hasAttachments == True:&lt;BR /&gt; #Remove any characters from feature layer name that may cause problems and ensure it's unique...&lt;BR /&gt; featureLayerName = '{}-{}'.format(str(i), re.sub(r'[^A-Za-z0-9]+', '', featureLayer.properties.name))&lt;BR /&gt; featureLayerFolder = SaveAttachmentsTo + r'\\' + featureLayerName&lt;BR /&gt; createFolder(featureLayerFolder)&lt;P&gt;&lt;/P&gt;#Query to get list of object ids in layer&lt;BR /&gt; featureObjectIds = featureLayer.query(where='1=1', return_ids_only=True)&lt;P&gt;&lt;/P&gt;#Provide some updates to user...&lt;BR /&gt; logger.info('Time: {}'.format(str(datetime.datetime.now())))&lt;BR /&gt; logger.info('Currently looping through feature attachments in layer {} of {}: storing in folder named "{}"'.format(str(i + 1), str(len(itemObject.layers)), featureLayerName))&lt;BR /&gt; logger.info('There are {} features to iterate in this layer'.format(str(len(featureObjectIds['objectIds']))))&lt;P&gt;&lt;/P&gt;#Loop through features in layer&lt;BR /&gt; emptyAttachments = 0&lt;BR /&gt; for j in range(len(featureObjectIds['objectIds'])):&lt;BR /&gt; currentObjectId = featureObjectIds['objectIds']&lt;J&gt;&lt;BR /&gt; currentObjectIdAttachments = featureLayer.attachments.get_list(oid=currentObjectId)&lt;P&gt;&lt;/P&gt;if len(currentObjectIdAttachments) &amp;gt; 0:&lt;P&gt;&lt;/P&gt;#Loop through feature attachments and download to appropriate folder&lt;BR /&gt; for k in range(len(currentObjectIdAttachments)):&lt;BR /&gt; attachmentId = currentObjectIdAttachments&lt;K&gt;['id']&lt;BR /&gt; attachmentName = currentObjectIdAttachments&lt;K&gt;['name']&lt;BR /&gt; attachmentSize = currentObjectIdAttachments&lt;K&gt;['size']&lt;BR /&gt; &lt;BR /&gt; if AttachmentStorage == 'IndividualFolder':&lt;BR /&gt; currentFolder = featureLayerFolder + r'\\' + str(currentObjectId)&lt;BR /&gt; #Create a folder for attachments&lt;BR /&gt; createFolder(currentFolder)&lt;BR /&gt; fileName = '{}-{}'.format(attachmentId, attachmentName)&lt;BR /&gt; newAttachmentPath = '{}\\{}'.format(currentFolder, fileName)&lt;BR /&gt; if not os.path.isfile(newAttachmentPath):&lt;BR /&gt; logger.info('The size of the current attachment being downloaded is {}MB'.format((attachmentSize/1000000)))&lt;BR /&gt; currentAttachmentPath = featureLayer.attachments.download(oid=currentObjectId, attachment_id=attachmentId, save_path=currentFolder)&lt;BR /&gt; #Rename to ensure file name is unique&lt;BR /&gt; renameFile(currentAttachmentPath, newAttachmentPath)&lt;BR /&gt; downloadCounter += 1&lt;BR /&gt; downloadSizeCounter += attachmentSize&lt;BR /&gt; else:&lt;BR /&gt; logger.info('File {} already exists. Not downloading again!'.format(newAttachmentPath))&lt;BR /&gt; nonDownloadCounter += 1&lt;P&gt;&lt;/P&gt;elif AttachmentStorage == 'GroupedFolder':&lt;BR /&gt; fileName = '{}-{}-{}'.format(currentObjectId, attachmentId, attachmentName)&lt;BR /&gt; newAttachmentPath = '{}\\{}'.format(featureLayerFolder, fileName)&lt;BR /&gt; if not os.path.isfile(newAttachmentPath):&lt;BR /&gt; logger.info('The size of the current attachment being downloaded is {}MB'.format((attachmentSize/1000000)))&lt;BR /&gt; currentAttachmentPath = featureLayer.attachments.download(oid=currentObjectId, attachment_id=attachmentId, save_path=featureLayerFolder)&lt;BR /&gt; #Rename to ensure file name is unique&lt;BR /&gt; renameFile(currentAttachmentPath, newAttachmentPath)&lt;BR /&gt; downloadCounter += 1&lt;BR /&gt; downloadSizeCounter += attachmentSize&lt;BR /&gt; else:&lt;BR /&gt; logger.info('File {} already exists. Not downloading again!'.format(newAttachmentPath))&lt;BR /&gt; nonDownloadCounter += 1&lt;P&gt;&lt;/P&gt;else:&lt;BR /&gt; logger.error('AttachmentStorage option not valid: {}. Valid options are IndividualFolder and GroupedFolder'.format(AttachmentStorage))&lt;BR /&gt; else:&lt;BR /&gt; emptyAttachments += 1&lt;BR /&gt; &lt;BR /&gt; logger.info('{} of these features do not contain attachments'.format(str(emptyAttachments)))&lt;BR /&gt; else:&lt;BR /&gt; logger.info('Layer {} does not have attachments enabled'.format(featureLayer.properties.name))&lt;P&gt;&lt;/P&gt;logger.info('Summary: {} new files have been downloaded totalling {}MB in size'.format(downloadCounter, (downloadSizeCounter/1000000)))&lt;BR /&gt;logger.info('Summary: {} attachments already existed so were not downloaded again'.format(nonDownloadCounter))&lt;/K&gt;&lt;/K&gt;&lt;/K&gt;&lt;/J&gt;&lt;/I&gt;&lt;/DIV&gt;&lt;DIV class=""&gt;&lt;PRE&gt;&lt;SPAN class=""&gt;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 08 Jan 2019 16:52:41 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/modulenotfounderror-no-module-named-arcgis/m-p/164900#M12650</guid>
      <dc:creator>MarcoPretorius1</dc:creator>
      <dc:date>2019-01-08T16:52:41Z</dc:date>
    </item>
    <item>
      <title>Re: ModuleNotFoundError: No module named 'arcgis'</title>
      <link>https://community.esri.com/t5/python-questions/modulenotfounderror-no-module-named-arcgis/m-p/164901#M12651</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;A href="https://community.esri.com/blogs/dan_patterson/2016/08/14/script-formatting"&gt;/blogs/dan_patterson/2016/08/14/script-formatting&lt;/A&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;to rule out format issues and to provide line numbers for commentary&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 08 Jan 2019 19:11:08 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/modulenotfounderror-no-module-named-arcgis/m-p/164901#M12651</guid>
      <dc:creator>DanPatterson_Retired</dc:creator>
      <dc:date>2019-01-08T19:11:08Z</dc:date>
    </item>
    <item>
      <title>Re: ModuleNotFoundError: No module named 'arcgis'</title>
      <link>https://community.esri.com/t5/python-questions/modulenotfounderror-no-module-named-arcgis/m-p/164902#M12652</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;This has been solved. Had to update packages.&amp;nbsp;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 08 Jan 2019 19:25:46 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/modulenotfounderror-no-module-named-arcgis/m-p/164902#M12652</guid>
      <dc:creator>MarcoPretorius1</dc:creator>
      <dc:date>2019-01-08T19:25:46Z</dc:date>
    </item>
  </channel>
</rss>

