当我尝试使用python3.6执行以下代码时,我遇到了一个问题,但它在python2.7上运行良好:
from distributed.compatability import FileExistsError
try:
os.mkdir(name)
logging.info("dir created")
except FileExistsError:
logging.info("dir already exists")
Error:
======
from distributed.compatability import FileExistsError
ImportError: cannot import name 'FileExistsError'
我已经使用conda安装了分布式软件包,但仍然收到相同的错误。我错过什么了吗?有人能帮我使它与python3.6一起工作吗
正如@rozumir提到的,
FileExistsError
是在Python 3中添加的。因此,只需要在Python2中导入它如果你查看他们的Github,你会发现它只是出于兼容性的原因添加的。因此命名为
distributed.compatibility
它是在2016年10月的this提交中添加的,但是在2019年7月Python 2 support was dropped,消除了对^{中大部分内容的需要
所以本质上,在Python3版本中,比如Python3.6,
FileExistsError
就在那里,不需要导入它来使用它不要从
distributed.compatibility
导入FileExistError
,请删除它,因为FileExistError
是标准库的一部分相关问题 更多 >
编程相关推荐