Python 3.6.4で、pip install python-memcached==1.58 したところ「tuple index out of range」エラー

python-memcachedの環境構築をする時に

# 仮想環境を作る
$ python -m venv env364

# アクティベート
$ source env364/bin/activate

# Pythonのバージョンを確認
(env364) $ python --version
Python 3.6.4

# pipでインストール
(env364) $ pip install python-memcached==1.58
Collecting python-memcached==1.58
  Using cached https://files.pythonhosted.org/packages/f7/62/14b2448cfb04427366f24104c9da97cf8ea380d7258a3233f066a951a8d8/python-memcached-1.58.tar.gz
    Complete output from command python setup.py egg_info:
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/private/var/folders/h0/l5plp4zd3517r988jpm481g00000gn/T/pip-build-q026ekfn/python-memcached/setup.py", line 8, in <module>
        version=get_module_constant('memcache', '__version__'),
      File "/path/to/lib/python3.6/site-packages/setuptools/depends.py", line 164, in get_module_constant
        return extract_constant(code, symbol, default)
      File "/path/to/lib/python3.6/site-packages/setuptools/depends.py", line 195, in extract_constant
        const = code.co_consts[arg]
    IndexError: tuple index out of range

とエラーが出てインストールができなかったため、対応した時のメモです。

 

環境

  • Python 3.6.4
  • setuptools 28.8.0

 

対応

python-memcachedGitHubにissueがありました。
can't install python-memcached1.58 in Python 3.6.0b2 · Issue #103 · linsomniac/python-memcached

setuptoolsのバージョンが古いために発生しているようでした。

 
そのため、setuptoolsのバージョンを上げてからインストールしたところ成功しました。

# setuptoolsのバージョンを上げる
(env364) $ pip install -U setuptools
Collecting setuptools
  Using cached https://files.pythonhosted.org/packages/37/06/754589caf971b0d2d48f151c2586f62902d93dc908e2fd9b9b9f6aa3c9dd/setuptools-40.6.3-py2.py3-none-any.whl
Installing collected packages: setuptools
  Found existing installation: setuptools 28.8.0
    Uninstalling setuptools-28.8.0:
      Successfully uninstalled setuptools-28.8.0
Successfully installed setuptools-40.6.3

# python-memcachedをインストール
(env364) $ pip install python-memcached==1.58
Collecting python-memcached==1.58
  Using cached https://files.pythonhosted.org/packages/f7/62/14b2448cfb04427366f24104c9da97cf8ea380d7258a3233f066a951a8d8/python-memcached-1.58.tar.gz
Requirement already satisfied: six>=1.4.0 in ./env364/lib/python3.6/site-packages (from python-memcached==1.58)
Installing collected packages: python-memcached
  Running setup.py install for python-memcached ... done
Successfully installed python-memcached-1.58

 
ちなみに、python-memcached 1.59 ではエラーが発生せずにインストールできるようです。

# 仮想環境を作る
$ python -m venv env364_1

# アクティベート
$ source env364_1/bin/activate

# setuptoolsのバージョンを確認
(env364_1) $ pip list
pip (9.0.1)
setuptools (28.8.0)

# インストール
(env364_1) $ pip install python-memcached
Collecting python-memcached
  Using cached https://files.pythonhosted.org/packages/f5/90/19d3908048f70c120ec66a39e61b92c253e834e6e895cd104ce5e46cbe53/python_memcached-1.59-py2.py3-none-any.whl
Collecting six>=1.4.0 (from python-memcached)
  Using cached https://files.pythonhosted.org/packages/73/fb/00a976f728d0d1fecfe898238ce23f502a721c0ac0ecfedb80e0d88c64e9/six-1.12.0-py2.py3-none-any.whl
Installing collected packages: six, python-memcached
Successfully installed python-memcached-1.59 six-1.12.0