Arcpy scripts keep giving an error "TypeError: expected string or bytes-like object"

Arcpy scripts keep giving an error "TypeError: expected string or bytes-like object"

我是 arcpy 的新手,也是 python 的大部分新手。我的新组织有 arcpy 脚本(由 ex-employee 编写),可以将 TAB 文件转换为 shp 并在 shp 中创建缓冲区。在我们将 ArcGIS Pro 升级到 2.8.3 之前,它一直运行良好。有了 python 的基本技能,我有望调试此脚本。 这是我们正在使用的脚本 -

#Import libraries
import geopandas as gpd

#Set directory as the same path as where this file is saved/pasted
abspath=os.path.abspath
abspath = os.path.abspath(__file__)
dname = os.path.dirname(abspath)
os.chdir(dname)

#Create a subfolder within the directory, folder called siteboundary
ProjectFolder=dname


#Locate the tab file and set as variable
#The script is locating a file that ends with "Site Boundary.TAB"
files=os.listdir(ProjectFolder)
Tabfile=[i for i in files if i.endswith('Site Boundary.TAB')]
def listToString(s): 
    
    # initialize an empty string
    str1 = " " 
    
    # return string  
    return (str1.join(s))
TabfilePath=ProjectFolder+'\'+listToString(Tabfile)



#This creates the site boundary shapefile
Tabdata=gpd.read_file(TabfilePath,driver="MapInfo File")
ShapefilePath=ProjectFolder+r"\siteboundary.shp"
Tabdata.to_file(ShapefilePath)


#This creates the site's multiring buffer

#set arcpy environment
arcpyenv=ProjectFolder

#Allow arcpy to overwrite
arcpy.env.workspace=arcpyenv
arcpy.env.overwrite=True
arcpy.env.overwriteOutput = True

#Set multi ring buffer parameters 
distances=[200,500,1000,2000]
bufferunit="meters"
arcpy.analysis.MultipleRingBuffer('siteboundary.shp','sitebuffer.shp',distances,bufferunit,"distance","NONE")


#Print end message when done
arcpy.AddMessage("Conversion done,your file is located in"+arcpyenv)
print("Conversion done,your file is located in "+arcpyenv)'```

我们在所有 PC 和/或所有脚本(json 到 shp 和缓冲区以及缓冲区创建脚本)中遇到相同的错误。 我们正在使用脚本来 semi-automate 流程,因为我们一天必须做很多事情。

我尝试通过其他来源的解决方案解决此问题,但其中 none 是相关的。 有关更多详细信息,在更新 ArcGIS Pro 之后我不得不将环境克隆到 运行 脚本,我假设那里可能发生了一些事情,但是当我检查已安装的库时它同时具有 arcpy 2.8 和 geopandas 0.8.1 运行 这些脚本必不可少。

另一件事是,脚本 运行 仅在 ArcGIS 未更新的一个系统中以及机器配置文件的主机中和 none 其他系统中。

我发现在 ArcGIS Pro Python 包管理中以及通过 anaconda 提示安装 geopandas 时出现问题。所以,我在 esri https://support.esri.com/en/technical-article/000024177 上找到了这个解决方法。您可以使用此命令行 conda install geopandas libtiff=4.0.10 通过 Python 命令提示符安装 geopandas。 但这样一来,ArcGIS Pro 中的笔记本将无法使用。 所以你必须在同一个 python 命令提示符下执行这个命令 conda install -c anaconda jupyter_client=5.3.1

运行克隆环境中的这两个代码解决了所有问题。