Hey! I'm parcially new in programing and currently I am making a script in Python for ArcGis Pro. This script has to convert coords from WGS84 to UTM, globally of course. For said cript I started using a library named 'utm' and until then didn't had any problem either with syntax nor the functions from python or arcgis. But when I went to run the script it showed me the error among the words of 'module 'utm' not found'. So I checked thee possible reasons for it and ended up modifying the Enviroment, Path, cheking the python installation and version and the library installation (via PIP) but no joy.
If anyone knows or had this same problem and solved it please let me know.
Thanks in advance!
was 'utm' installed in the python environment that Pro uses?
check in the site-packages folder of your environment to see if it is installed there.
Also show your script in case it is a scripting error
Code formatting ... the Community Version - Esri Community
import arcpy
import utm
import pyproj
arcpy.env.workspace = r"C:\Users\Usuario\Desktop\DocsUSACH\SIG_TAREA1"
print('Bienvenido al convertidor de coordenadas GEO-UTM, donde podrá hacer conversiones de coordenadas Geográficas, con SIRGAS como Datúm, a coordenadas UTM con huso definido')
#Toma de Datos
formato= str(input('Por favor elija el tipo de coordenadas que quiere convertir, (G)eográficas o (U)TM:' ))
if formato== 'G':
long= float(input('Introduzca la longtitud de su coordenada, en formato númerico (No grados) y con un punto (.) en vez de coma (,):' ))
lat= float(input('Introduzca la latitud de su coordenada, en formato númerico (No grados) y con un punto (.) en vez de coma (,):' ))
#Convertir coordenadas geográficas a UTM
coordenadas_utm= utm.from_latlon(lat,long)
#Extraer valores individuales
este_UTM = coordenadas_utm[0]
norte_UTM = coordenadas_utm[1]
zona_UTM = coordenadas_utm[2]
hemisferio_UTM = coordenadas_utm[3]
#Mostrar las coordenadas UTM
print('Este UTM(x):',este_UTM)
print('Norte UTM(y):',norte_UTM)
print('Zona UTM:',zona_UTM)
print('Hemisferio UTM:',hemisferio_UTM)
#Para ver la coordenada en el mapa
project = arcpy.mp.ArcGISProject("CURRENT")
coord=arcpy.Point(long,lat)
coord_entrada = arcpy.SpatialReference(4326) #Código correspondiente a WGS84
coord_geometry = arcpy.PointGeometry(coord, coord_entrada)
mapa_activo=project.activeMap
# Crear una capa temporal y agregar la geometría al mapa
capa_temporal = mapa_activo.createLayer(None, coord_geometry, 'Coordenada_usuario')
arcpy.RefresActiveView()
#Inicio Segunda opción
elif formato == 'U':
#Recolección de Datos
este_utm = float(input('Introduzca la coordenada EsteUTM:' ))
norte_utm = float(input('Introduzca la coordenada NorteUTM:' ))
zona_utm = int(input('Introduzca el Huso correspondiente a la CoordenadaUTM:' ))
hemisferio_utm = str(input('Introduzca el Hemisferio correspondiente a la coordenada, ya sea (N)orte o (S)ur:' ))
#Utilizar UTM para tener la coordenada completa
zona_completa_utm = str(zona_utm) + hemisferio_utm
#Crear objeto en librería pyproj para hacer la conversión
utm_a_geográfica = pyproj.Proj(proj='utm', zone = zona_completa_utm, datum = 'WGS84')
#Conversión
long, lat= utm_a_geográfica(este_utm, norte_utm)
print('Latitud resultante:' , lat)
print('Longitud resultante:' , long)
Thanks for your reply! Here's the script; I checked the folder of the enviroment and 'utm' it's there, but in a 'blank' format when the rest are a .exe file.
I look foward to your Reply, thanks.
A basic arcgis pro environment will be
C:\...install folder ...\bin\Python\envs\arcgispro-py3
packages, like utm should be in
C:\...install folder ...\bin\Python\envs\arcgispro-py3\Lib\site-packages
The python executable and where python will look for packages can be determined using the sys module
import sys
sys.executable
'C:\\arc_pro\\bin\\Python\\envs\\spyarc\\python.exe'
sys.path
['C:\\arc_pro\\Resources\\ArcPy',
'C:\\arc_pro\\bin\\Python\\envs\\spyarc\\python39.zip',
'C:\\arc_pro\\bin\\Python\\envs\\spyarc\\DLLs',
'C:\\arc_pro\\bin\\Python\\envs\\spyarc\\lib',
'C:\\arc_pro\\bin\\Python\\envs\\spyarc',
'',
'C:\\arc_pro\\bin\\Python\\envs\\spyarc\\lib\\site-packages',
'C:\\arc_pro\\bin',
'C:\\arc_pro\\Resources\\ArcToolbox\\Scripts',
'C:\\arc_pro\\bin\\Python\\envs\\spyarc\\lib\\site-packages\\win32',
'C:\\arc_pro\\bin\\Python\\envs\\spyarc\\lib\\site-packages\\win32\\lib',
'C:\\arc_pro\\bin\\Python\\envs\\spyarc\\lib\\site-packages\\Pythonwin',
'C:\\arc_pro\\bin\\Python\\envs\\spyarc\\lib\\site-packages\\pywin32security',
'C:\\arcpro_npg\\npg',
'C:\\arcpro_npg']
In the above example the last two lines are paths I have added for extra packages, .... you can add to the path, as I did, or install your package in the listed site-packages folder in your environment. In my case Pro is installed in the c:\\arc_pro folder