LoginSignup
6
4

More than 3 years have passed since last update.

enumの互換性エラーの対処法

Last updated at Posted at 2020-07-12

Optunaインストール時に起きたエラーの原因と対処法

環境は以下の通り

  • Windows 10 Home
  • python 3.6.5
  • pip 19.3.1

Optunaをインストールしようと以下コードを実行したらエラーが出た

実行文
pip install optuna
実行結果
Collecting optuna
  Downloading https://files.pythonhosted.org/packages/33/32/266d4afd269e3ecd7fcc595937c1733f65eae6c09c3caea74c0de0b88d78/optuna-1.5.0.tar.gz (200kB)
     |████████████████████████████████| 204kB 1.7MB/s
Collecting alembic
  Downloading https://files.pythonhosted.org/packages/60/1e/cabc75a189de0fbb2841d0975243e59bde8b7822bacbb95008ac6fe9ad47/alembic-1.4.2.tar.gz (1.1MB)
     |████████████████████████████████| 1.1MB 6.4MB/s
  Installing build dependencies ... error
  ERROR: Command errored out with exit status 1:
   command: 'D:\Users\(user_name)\Anaconda3\python.exe' 'D:\Users\(user_name)\Anaconda3\lib\site-packages\pip' install --ignore-installed --no-user --prefix 'C:\Users\(user_name)\AppData\Local\Temp\pip-build-env-5wsdb490\overlay' --no-warn-script-location --no-binary :none: --only-binary :none: -i https://pypi.org/simple -- 'setuptools>=40.8.0' wheel
       cwd: None
  Complete output (14 lines):
  Traceback (most recent call last):
    File "D:\Users\(user_name)\Anaconda3\lib\runpy.py", line 193, in _run_module_as_main
      "__main__", mod_spec)
    File "D:\Users\(user_name)\Anaconda3\lib\runpy.py", line 85, in _run_code
      exec(code, run_globals)
    File "D:\Users\(user_name)\Anaconda3\lib\site-packages\pip\__main__.py", line 16, in <module>
      from pip._internal.main import main as _main  # isort:skip # noqa
    File "D:\Users\(user_name)\Anaconda3\lib\site-packages\pip\_internal\main.py", line 8, in <module>
      import locale
    File "D:\Users\(user_name)\Anaconda3\lib\locale.py", line 16, in <module>
      import re
    File "D:\Users\(user_name)\Anaconda3\lib\re.py", line 142, in <module>
      class RegexFlag(enum.IntFlag):
  AttributeError: module 'enum' has no attribute 'IntFlag'
  ----------------------------------------
ERROR: Command errored out with exit status 1: 'D:\Users\(user_name)\Anaconda3\python.exe' 'D:\Users\(user_name)\Anaconda3\lib\site-packages\pip'
 install --ignore-installed --no-user --prefix 'C:\Users\(user_name)\AppData\Local\Temp\pip-build-env-5wsdb490\overlay' --no-warn-script-location 
--no-binary :none: --only-binary :none: -i https://pypi.org/simple -- 'setuptools>=40.8.0' wheel Check the logs for full command output.

エラー内容

エラー文
ERROR: Command errored out with exit status 1: 'D:\Users\(user_name)\Anaconda3\python.exe' 'D:\Users\(user_name)\Anaconda3\lib\site-packages\pip'
 install --ignore-installed --no-user --prefix 'C:\Users\(user_name)\AppData\Local\Temp\pip-build-env-5wsdb490\overlay' --no-warn-script-location 
--no-binary :none: --only-binary :none: -i https://pypi.org/simple -- 'setuptools>=40.8.0' wheel Check the logs for full command output.

原因

標準ライブラリenumモジュールではなく、enum34パッケージのものが使われており、Python 3.6以降、enum34ライブラリは標準ライブラリenumと互換性がなくなったため。

解決策

Python3.6以降を使う場合、enum34ライブラリも不要なので、アンインストールし標準ライブラリのenumモジュールを使う。

enum34をアンインストール
pip uninstall enum34

enum34をアンインストール後、再度pip install optunaを実行すると、無事Optunaをインストールすることができました!

6
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
4