gpt4 book ai didi

python - 导入枚举文件与 Python 2.7 不兼容

转载 作者:行者123 更新时间:2023-12-01 09:29:24 25 4
gpt4 key购买 nike

我在运行使用“导入枚举”的 Python 文件时遇到问题,给了我这个问题:

Traceback (most recent call last):

File "lowest_common_ancestor.py", line 4, in <module>
from test_framework import generic_test, test_utils

File "/Users/linh/Documents/EPIJudge/epi_judge_python/test_framework/generic_test.py", line 6, in <module>
from test_framework.generic_test_handler import GenericTestHandler

File "/Users/linh/Documents/EPIJudge/epi_judge_python/test_framework/generic_test_handler.py", line 5, in <module>
from test_framework.binary_tree_utils import assert_equal_binary_trees, is_object_tree_type

File "/Users/linh/Documents/EPIJudge/epi_judge_python/test_framework/binary_tree_utils.py", line 5, in <module>
from test_framework.test_failure import TestFailure, PropertyName

File "/Users/linh/Documents/EPIJudge/epi_judge_python/test_framework/test_failure.py", line 2, in <module>
from enum import Enum, auto

ImportError: cannot import name 'auto'

我知道我有Python 2.7,并且“导入枚举”仅存在于Python 3中,但是我在如何创建两个同时拥有Python 2.7和Python 3的不同环境时遇到了麻烦。如何去做呢?在 Mac Unix 终端上,我对此也不是很熟悉。

最佳答案

auto 直到 Python 3.6 才出现,并且不在 enum34 向后移植中。如果您想要 2/3 兼容代码,您需要使用 aenum 1

我没有任何使用 Mac Unix 终端的经验。

<小时/>

1 披露:我是 Python stdlib Enum 的作者,enum34 backport ,以及 Advanced Enumeration (aenum)图书馆。

关于python - 导入枚举文件与 Python 2.7 不兼容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50092876/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com