Hello - After running a conda update arcgis in my Pro3.1.3 envrionment 2 days ago (10/22/2023), I am suddenly getting an import error for datetime import.
In most cases, I'm just using datetime to set up datetime differences to get a script runtime email from the Python IDLE:
##ArcGIS api for starting and stopping services. Run in 3.9.16
#Import system modules
import sys, string, os, arcpy, time, smtplib
from datetime import date, timedelta
from arcpy import env
from arcgis.gis import GIS
# Local variables...
message = ""
current_time = time.asctime()
todaysDate = date.today()
priorYear = str(todaysDate - timedelta(days=547)) #547
starting_time = time.time()
try:
gis = GIS("https://sub.domian.net/portal", "myuser_", "mypwd")
gis_servers = gis.admin.servers.list()
print(gis_servers)
#message = message + "\n" + str(gis_servers)
agsfed = gis_servers[1]
print(agsfed)
#message = message + "\n" + str(agsfed)
scpaServicesList = agsfed.services.list(folder='ScpaServices')
for scpaService in scpaServicesList:
print(scpaService.properties.serviceName)
message = message + "\n" + str(scpaService.properties.serviceName)
scpaService.start()
print(scpaService.status)
message = message + "\n" + str(scpaService.status)
except Exception:
# If an error occurred, print line number and error message
import traceback, sys
tb = sys.exc_info()[2]
e = sys.exc_info()[1]
#print(e.args[0])
#print "Line %i" % tb.tb_lineno
message = message + "\n" + "Line %i" % tb.tb_lineno
message = message + "\n" + e.message
# Below is to send email message.
fromAddr = "dcoley@domain.net"
toAddr = ["dcoley@scgov.net"]
subject = "SCRIPT: Start Collector Services"
finish_time = time.asctime()
fininshing_time = time.time()
elapsed_time = fininshing_time - starting_time
total_time = str(timedelta(seconds=elapsed_time))
msgBody = current_time + "\n\n" + message + "\n\n" + "Thank you." + "\n\n" + finish_time + "\n\n" + "Total time elasped is: " + total_time
msg = 'From: {}\nTo: {}\nSubject: {}\n\n{}'.format(fromAddr, toAddr, subject, msgBody)
server = smtplib.SMTP("smtp.domain.net")
server.set_debuglevel(1)
server.sendmail(fromAddr,toAddr,msg)
server.quit()
And then I get the
ImportError: PyCapsule_Import could not import module "datetime".
So really just seems to be a bad conda udpdate. When I reverted back to the Default environment, I do not get the import error.
Is anyone else experiencing this? @KenBuja ?
Thanks,
David
Did you try installing the DateTime package directly into your site-packages in your virtual environment?
I did not but thanks the suggestion. I could try, but since the upgrade for the arcgis package at Pro 3.1.3 is from 2.1.0.2 to 2.1.0.3 - and the arcgis api is at 2.2, I think I'll wait for the next Pro release as I'm not doing anything that requires any of the other packages to be upgraded at this time.