简体   繁体   English

Python Arcpy:库导入中的非ASCII字符

[英]Python Arcpy: Non-ASCII character in library import

I was debugging a basic GIS python script, when I randomly(?) got this error: 当我随机(?)收到此错误时,我正在调试基本的GIS python脚本:

Traceback (most recent call last):
  File "<module1>", line 13, in <module>
    import arcpy
  File "C:\Program Files (x86)\ArcGIS\Desktop10.5\ArcPy\arcpy\__init__.py", line 25, in <module>
    from arcpy.toolbox import *
  File "C:\Program Files (x86)\ArcGIS\Desktop10.5\ArcPy\arcpy\toolbox.py", line 371, in <module>
    from .management import Graph, GraphTemplate
  File "C:\Program Files (x86)\ArcGIS\Desktop10.5\ArcPy\arcpy\management.py", line 5694
SyntaxError: Non-ASCII character '\xc2' in file C:\Program Files (x86)\ArcGIS\Desktop10.5\ArcPy\arcpy\management.py on line 5695, but no encoding declared; see http://python.org/dev/peps/pep-0263/ for details

Tried just running import arcpy and the same error popped up. 尝试仅运行import arcpy并弹出相同的错误。 So far here's what I tried: 到目前为止,这是我尝试的操作:

  • Ran from Pyscripter and cmd. 来自Pyscripter和cmd。
  • Restarted my computer a couple times. 重新启动计算机几次。
  • Opened that management.py file out of curiosity but it's only a couple hundred lines? 出于好奇而打开了该management.py文件,但只有几百行? I'm a GIS/data analyst, not a programmer of any sort, so this realm is beyond what I know. 我是GIS /数据分析师,而不是任何类型的程序员,所以这个领域超出了我的了解。

I'm stumped. 我很沮丧 Yes, I could reinstall the library, but that's quite involved as this library is a tiny part of a massive software package. 是的,我可以重新安装该库,但这相当复杂,因为该库只是大型软件包的一小部分。

您可以尝试在第一行中添加“ #encoding:utf-8”

Add # -*- coding: utf-8 -*- at the top of your script. 在脚本顶部添加# -*- coding: utf-8 -*-

Probably the IDE that you are using, use the default encoding set. 可能您正在使用的IDE使用默认的编码集。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM