首先让我说我不是程序员。我对编程的了解偶尔会使用R来帮助我的工作数据。最近,我一直在尝试使用Python来自动化几个ArcGIS函数。
import arcpy
arcpy.env.workspace =
r"C:\Users\lscarney\Desktop\2020data_ArcScripting\2020_HessianFly_ShapeFileCreation.gdb"
print(arcpy.env.workspace)
我一直在通过不同的教程向Python和Arcpy介绍自己,在这些教程中,我经常看到这种代码经常重复。但是,当我运行它而不是“完成退出代码0”时,我会有这个混乱。
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
我已经做过的事情:
我尝试在Arcpy之外运行一些简单的代码行(添加变量,打印变量ECT),并且一切正常。我已经检查了Python解释器,它位于Arcgis中,因此我可以肯定的是,这不是问题,尤其是因为使用其他Python解释器路径无法使用Arcpy。
如果有人可以帮助我朝正确的方向指出,那将不胜感激。我只是没有足够的经验,可以在Python和Pycharm上了解出了什么问题。谢谢。
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.
发布评论
评论(1)
我弄清楚了如何使它起作用,但是我不确定为什么....如果有人能提供一些澄清,这将不胜感激。在此之前,我将尽我所能解释。
我正在使用的Python解释器是
c:\ python27 \ arcgis10.6
我认为这会起作用,因为从默认情况下切换到它后,Pycharm开始识别Arcpy函数。显然这无效。在阅读这篇文章时,注意到他们使用的路径并在我的计算机上尝试了。 -
什么有效 - &gt;
c:\ program Files \ arcgis \ pro \ bin \ python \ envs \ etcgispro-py3
,因此,似乎为了使其起作用,解释器必须来自您的Arcgispro-py3文件夹, ArcGIS安装。我不明白这与我首先使用的路径有何不同,因为这两个识别的Arcpy功能。无论如何,我可以确认新路径可以执行代码,而无例外。
I figured out how to make it work, but I am not entirely sure why.... If anyone could provide some clarification it would be appreciated. Until then I will explain to the best of my ability.
The Python interpreter I was using was
C:\Python27\ArcGIS10.6
I thought that would work because after switching to it from the default, pycharm began to recognize ArcPy functions. Obviously that didn't work.While reading this Noticed that path they used and tried it on my computer. -- https://community.esri.com/t5/python-documents/pycharm-setup-for-arcgis-desktop/ta-p/1125129
What works -->
C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3
So it seems that in order for it to work the interpreter has to be from the arcgispro-py3 folder located in your ArcGIS install. I don`t understand how this differs from the path I used first because both recognized ArcPy functions. Regardless I can confirm that the new path can execute the code with no exceptions.