enum34未正确安装-Python 2.7
运行命令enum34未正确安装-Python 2.7,python,python-2.7,Python,Python 2.7,运行命令pip2.7 show enum34输出正确安装的版本和位置: Name: enum34 Version: 1.1.2 Summary: Python 3.4 Enum backported to 3.3, 3.2, 3.1, 2.7, 2.6, 2.5, and 2.4 Home-page: https://pypi.python.org/pypi/enum34 Author: Ethan Furman Author-email: ethan@stoneleaf.us License:
pip2.7 show enum34
输出正确安装的版本和位置:
Name: enum34
Version: 1.1.2
Summary: Python 3.4 Enum backported to 3.3, 3.2, 3.1, 2.7, 2.6, 2.5, and 2.4
Home-page: https://pypi.python.org/pypi/enum34
Author: Ethan Furman
Author-email: ethan@stoneleaf.us
License: BSD License
Location: /usr/lib/python2.7/dist-packages
Requires:
Required-by:
尽管如此,我在使用enum
时仍出现以下错误:
AttributeError: 'enum' object has no attribute 'IntFlag'
如果在python2.7
中没有安装enum34
,但它已经安装,则会发生此错误
我可以导入enum
并运行enum.\u_文件\u_
输出路径:
/usr/lib/python2.7/dist-packages/enum/__init__.pyc
- 如果安装了
,为什么enum34
在IntFlag
中缺失enum
IntFlag
不存在。那是因为它是
因此,您看到的错误确实是正确的,enum34
安装没有问题
pypi中的enum
包似乎也没有IntFlag
通过复制源代码,您可以非常轻松地对其进行修补:
我怀疑在您的代码中,您可能正在执行以下操作:
import enum
class Foo(enum.Enum):
BAR = 1
enum = Foo.Bar # or something like this
class Baz(enum.Enum): # failure happens here, enum is now Foo.Bar
pass
这听起来不像是
enum34
安装的问题。听起来您正在查看的对象不是enum
模块。您的代码可能已损坏。类似的:IntFlag
确实在enum43
中丢失。自己检查源代码:哦,是的,enum34
没有IntFlag
,所以也有。即使安装了enum34
,如果您确实在访问enum
模块上的属性,您也会收到不同的错误消息。您知道如何升级enum吗?我知道这听起来很愚蠢,但我一直在搜索,找不到任何有用的东西。正如我在答案底部建议的那样,只需在包中使用其源代码创建自己的枚举模块,然后改用它。
import sys
sys = 1 # doesn't have to be 1, can be anything that's not sys
# sys is no longer the module you imported, this will fail
sys.stdout.write('hello world!\n')
import enum
class Foo(enum.Enum):
BAR = 1
enum = Foo.Bar # or something like this
class Baz(enum.Enum): # failure happens here, enum is now Foo.Bar
pass