first off let me state I am not a programmer. My knowledge of programming is occasionally using R to help with data at my job. Recently I have been attempting to use python in order to automate several ArcGIS functions.
import arcpy
arcpy.env.workspace =
r"C:\Users\lscarney\Desktop\2020data_ArcScripting\2020_HessianFly_ShapeFileCreation.gdb"
print(arcpy.env.workspace)
I have been introducing myself to python and arcpy through different tutorials and I see this bit of code repeated often throughout those tutorials. However when I run this instead of "Finished with exit code 0" I have this mess.
Traceback (most recent call last):
File "C:\Users\lscarney\Desktop\ArcGIS Scripts\ArcGIS_Scripts\venv\RepairDataSource.py", line 1, in <module>
import arcpy
File "C:\Program Files (x86)\ArcGIS\Desktop10.6\ArcPy\arcpy\__init__.py", line 22, in <module>
from arcpy.geoprocessing import gp
File "C:\Program Files (x86)\ArcGIS\Desktop10.6\ArcPy\arcpy\geoprocessing\__init__.py", line 14, in <module>
from _base import *
File "C:\Program Files (x86)\ArcGIS\Desktop10.6\ArcPy\arcpy\geoprocessing\_base.py", line 612, in <module>
env = GPEnvironments(gp)
File "C:\Program Files (x86)\ArcGIS\Desktop10.6\ArcPy\arcpy\geoprocessing\_base.py", line 609, in GPEnvironments
return GPEnvironment(geoprocessor)
File "C:\Program Files (x86)\ArcGIS\Desktop10.6\ArcPy\arcpy\geoprocessing\_base.py", line 565, in __init__
self._refresh()
File "C:\Program Files (x86)\ArcGIS\Desktop10.6\ArcPy\arcpy\geoprocessing\_base.py", line 567, in _refresh
envset = (set(env for env in self._gp.listEnvironments()))
RuntimeError: NotInitialized
Process finished with exit code 1
Things I have done:
I have tried running a few simple lines of code (adding variables, printing variables ect) outside of arcpy and everything worked fine. I have checked the python interpreter and it is one located in arcgis so I'm fairly certain that is not the issue, especially since arcpy is not available using the other python interpreter path.
If anyone could help point me in the right direction It would be greatly appreciated. I just dont have enough experience with python and Pycharm to understand what is going wrong. Thanks.