« ^ »

AttributeError: module 'enum' has no attribute 'IntFlag'"

所要時間: 約 1分

shuttile使おうと思ったら次のエラーが出たのでメモしておく武士。

(py3.6.0) $ sshuttle -r username@hostname 0/0
[local sudo] Password:
Failed to import the site module
Traceback (most recent call last):
  File "/envs/py3.6.0/lib/python3.6/site.py", line 548, in <module>
    main()
  File "/envs/py3.6.0/lib/python3.6/site.py", line 530, in main
    known_paths = addusersitepackages(known_paths)
  File "/envs/py3.6.0/lib/python3.6/site.py", line 282, in addusersitepackages
    user_site = getusersitepackages()
  File "/envs/py3.6.0/lib/python3.6/site.py", line 258, in getusersitepackages
    user_base = getuserbase() # this will also set USER_BASE
  File "/envs/py3.6.0/lib/python3.6/site.py", line 248, in getuserbase
    USER_BASE = get_config_var('userbase')
  File "/envs/py3.6.0/lib/python3.6/sysconfig.py", line 601, in get_config_var
    return get_config_vars().get(name)
  File "/envs/py3.6.0/lib/python3.6/sysconfig.py", line 580, in get_config_vars
    import _osx_support
  File "/envs/py3.6.0/lib/python3.6/_osx_support.py", line 4, in <module>
    import re
  File "/envs/py3.6.0/lib/python3.6/re.py", line 142, in <module>
    class RegexFlag(enum.IntFlag):
AttributeError: module 'enum' has no attribute 'IntFlag'

IntFlagは本当にないのか?

>>> import enum
>>> enum.IntFlag
<enum 'IntFlag'>

ある。となるとenum34が邪魔している的な?と言う気になるのでuninstallしてみる。

(py3.6.0) $ pip uninstall enum34
Uninstalling enum34-1.1.6:
  /envs/py3.6.0/lib/python3.6/site-packages/enum/LICENSE
  /envs/py3.6.0/lib/python3.6/site-packages/enum/README
  /envs/py3.6.0/lib/python3.6/site-packages/enum/__init__.py
  /envs/py3.6.0/lib/python3.6/site-packages/enum/__pycache__/__init__.cpython-36.pyc
  /envs/py3.6.0/lib/python3.6/site-packages/enum34-1.1.6.dist-info/DESCRIPTION.rst
  /envs/py3.6.0/lib/python3.6/site-packages/enum34-1.1.6.dist-info/INSTALLER
  /envs/py3.6.0/lib/python3.6/site-packages/enum34-1.1.6.dist-info/METADATA
  /envs/py3.6.0/lib/python3.6/site-packages/enum34-1.1.6.dist-info/RECORD
  /envs/py3.6.0/lib/python3.6/site-packages/enum34-1.1.6.dist-info/WHEEL
  /envs/py3.6.0/lib/python3.6/site-packages/enum34-1.1.6.dist-info/metadata.json
  /envs/py3.6.0/lib/python3.6/site-packages/enum34-1.1.6.dist-info/top_level.txt
Proceed (y/n)? y
  Successfully uninstalled enum34-1.1.6

もう一度実行してみる。

(py3.6.0) $ sshuttle -r username@hostname 0/0
[local sudo] Password:
client: Connected.

できた。enum34が邪魔していたっぽい。enum34はPython3.4で入ったenumモジュールのPython2へのバックポートなのでPython3.4以降では不要なんだけど、他のライブラリの依存関係に引きずられて入ってしまうことがある。今回はそんな感じだった。