6
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

pip install pyrebase しただけなのに... (UnicodeDecodeError)

Last updated at Posted at 2019-12-08

#はじめに
flaskでfirebaseを使おうと思い、便利~~(?)~~なpyrebaseというライブラリを見つけたのが全ての始まりであった。
#chapter: 1 ~予兆~
anaconda プロンプトで pip install

(flask_env) C:\Users\ryosu\flask_project\auto_call_app>pip install pyrebase4
Collecting pyrebase4
  Using cached https://files.pythonhosted.org/packages/25/17/653e33c0f3d4fb6556570c955b9a298990dd515bbd09b1a2abc99ec7a9fa/Pyrebase4-4.3.0-py3-none-any.whl
Collecting pycryptodome>=3.6.4
  Using cached https://files.pythonhosted.org/packages/c8/a9/d65f44cdb4b44e05b494fa0bfed087105a706033644e5826c48d3c6ccfb8/pycryptodome-3.9.4-cp38-cp38-win_amd64.whl
Collecting python-jwt==2.0.1
  Using cached https://files.pythonhosted.org/packages/dd/2a/9c4230b09f63737e7beb34e3a19895cd50c5ff88af16d3cd54cd71e2325a/python_jwt-2.0.1-py2.py3-none-any.whl
Collecting requests>=2.19.1
  Using cached https://files.pythonhosted.org/packages/51/bd/23c926cd341ea6b7dd0b2a00aba99ae0f828be89d72b2190f27c11d4b7fb/requests-2.22.0-py2.py3-none-any.whl
Collecting requests-toolbelt>=0.7.1
  Using cached https://files.pythonhosted.org/packages/60/ef/7681134338fc097acef8d9b2f8abe0458e4d87559c689a8c306d0957ece5/requests_toolbelt-0.9.1-py2.py3-none-any.whl
Collecting oauth2client==4.1.2
  Using cached https://files.pythonhosted.org/packages/82/d8/3eab58811282ac7271a081ba5c0d4b875ce786ca68ce43e2a62ade32e9a8/oauth2client-4.1.2-py2.py3-none-any.whl
Collecting gcloud==0.18.3
  Using cached https://files.pythonhosted.org/packages/11/ab/d0cee58db2d8445c26e6f5db25d9b1f1aa14a3ab30eea8ce77ae808d10ef/gcloud-0.18.3.tar.gz
Collecting jws>=0.1.3
  Using cached https://files.pythonhosted.org/packages/01/9e/1536d578ed50f5fe8196310ddcc921a3cd8e973312d60ac74488b805d395/jws-0.1.3.tar.gz
    ERROR: Command errored out with exit status 1:
     command: 'C:\Users\ryosu\Anaconda3\envs\flask_env\python.exe' -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\\Users\\ryosu\\AppData\\Local\\Temp\\pip-install-mp_hyf90\\jws\\setup.py'"'"'; __file__='"'"'C:\\Users\\ryosu\\AppData\\Local\\Temp\\pip-install-mp_hyf90\\jws\\setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' egg_info --egg-base 'C:\Users\ryosu\AppData\Local\Temp\pip-install-mp_hyf90\jws\pip-egg-info'
         cwd: C:\Users\ryosu\AppData\Local\Temp\pip-install-mp_hyf90\jws\
    Complete output (7 lines):
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "C:\Users\ryosu\AppData\Local\Temp\pip-install-mp_hyf90\jws\setup.py", line 17, in <module>
        long_description=read('README.md'),
      File "C:\Users\ryosu\AppData\Local\Temp\pip-install-mp_hyf90\jws\setup.py", line 5, in read
        return open(os.path.join(os.path.dirname(__file__), fname)).read()
    UnicodeDecodeError: 'cp932' codec can't decode byte 0x93 in position 502: illegal multibyte sequence
    ----------------------------------------
ERROR: Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.

とりあえずエラーコードを調べると、sys.setdefaultencoding('utf-8')を設定すると良いという記事があったのですが、python2系でのみ使えるモジュールらしく、python3系では無くなっていた...
#chapter: 2 ~地獄へ~
ここでもう一度エラー文を眺めてみると

  Using cached https://files.pythonhosted.org/packages/11/ab/d0cee58db2d8445c26e6f5db25d9b1f1aa14a3ab30eea8ce77ae808d10ef/gcloud-0.18.3.tar.gz
Collecting jws>=0.1.3
  Using cached https://files.pythonhosted.org/packages/01/9e/1536d578ed50f5fe8196310ddcc921a3cd8e973312d60ac74488b805d395/jws-0.1.3.tar.gz
    ERROR: Command errored out with exit status 1:
     command: 'C:\Users\ryosu\Anaconda3\envs\flask_env\python.exe' -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\\Users\\ryosu\\AppData\\Local\\Temp\\pip-install-mp_hyf90\\jws\\setup.py'"'"'; __file__='"'"'C:\\Users\\ryosu\\AppData\\Local\\Temp\\pip-install-mp_hyf90\\jws\\setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' egg_info --egg-base 'C:\Users\ryosu\AppData\Local\Temp\pip-install-mp_hyf90\jws\pip-egg-info'
         cwd: C:\Users\ryosu\AppData\Local\Temp\pip-install-mp_hyf90\jws\
    Complete output (7 lines):
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "C:\Users\ryosu\AppData\Local\Temp\pip-install-mp_hyf90\jws\setup.py", line 17, in <module>
        long_description=read('README.md'),
      File "C:\Users\ryosu\AppData\Local\Temp\pip-install-mp_hyf90\jws\setup.py", line 5, in read
        return open(os.path.join(os.path.dirname(__file__), fname)).read()
    UnicodeDecodeError: 'cp932' codec can't decode byte 0x93 in position 502: illegal multibyte sequence
    ----------------------------------------
ERROR: Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.

jws をインストールしているときにエラーが出ているみたいでなので、pip install jws をすると同じエラーが出たので、やっぱり...となりました。

さらにエラー文見てみると、
File "C:\Users\ryosu\AppData\Local\Temp\pip-install-mp_hyf90\jws\setup.py"のように、jws\setup.py の中のreturn open(os.path.join(os.path.dirname(__file__), fname)).read()の行でUnicodeDecodeErrorが出ていることがわかります。
ここでjwsのgithubから直接 setup.pyを確認すると、

setup.py
import os
from setuptools import setup

def read(fname):
    return open(os.path.join(os.path.dirname(__file__), fname)).read()

setup(
    name = "jws",
    version = "0.1.2",
    author = "Brian J Brennan",
    author_email = "brian@nyhacker.org",
    description = ("JSON Web Signatures implementation in Python"),
    license = "MIT",
    keywords = "jws json web security signing",
    url = "http://github.com/brianlovesdata/python-jws",
    packages=['jws'],
    long_description=read('README.md'),
    classifiers=[
        "Development Status :: 3 - Alpha",
        "Topic :: Utilities",
        "License :: OSI Approved :: MIT License",
    ],
    test_suite = 'nose.collector',
)

見つけることができました。
UnicodeDecodeErrorを解決するために、encodingを指定し、それをgithubから直接pip inastall すればいけるはず...
#chapter: 3 ~そして伝説へ~
jwsをgithubからzipファイルでダウンロードし、setup.pyreturn open(os.path.join(os.path.dirname(__file__), fname)).read()return open(os.path.join(os.path.dirname(__file__), fname), encoding='utf-8_sig').read()に書き換え、エラー文をもう一度見ると、Collecting jws>=0.1.3とあったので、version = "0.1.3"ともしておきました。

書き換えたjwsを新しく作ったレポジトリにぶち込むと...
しっかりとpushできました -> 書き換えたjwsのgithub
これをpip installします。
github から直接pip install するにはpip install git+https://github.com/kitarikes/jws4meのようにgithubのリンクを入力します。

$pip install git+https://github.com/kitarikes/jws4me
Collecting git+https://github.com/kitarikes/jws4me
  Cloning https://github.com/kitarikes/jws4me to c:\users\ryosu\appdata\local\temp\pip-req-build-lqn51ndb
  Running command git clone -q https://github.com/kitarikes/jws4me 'C:\Users\ryosu\AppData\Local\Temp\pip-req-build-lqn51ndb'
  Running command git submodule update --init --recursive -q
Building wheels for collected packages: jws
  Building wheel for jws (setup.py) ... done
  Created wheel for jws: filename=jws-0.1.3-cp38-none-any.whl size=9572 sha256=31bec145f3eb22bb415d4469f7c22914e333c3199114753d6154be320498537e
  Stored in directory: C:\Users\ryosu\AppData\Local\Temp\pip-ephem-wheel-cache-wm556ysw\wheels\8c\c9\43\5580c6dd5674d87b0619c3d91f0ec51398ed1dbd4274b0cda4
Successfully built jws
Installing collected packages: jws
  Found existing installation: jws 0.1.2
    Uninstalling jws-0.1.2:
      Successfully uninstalled jws-0.1.2
Successfully installed jws-0.1.3

Successfully installed jws-0.1.3 !!!!
無事にインストールできました。
pip install pyrebase4すると、無事にpyrebase4がインストールされました!
(ドラクエシリーズは3が好きです。#5も勿論好きです。)
#おわりに
pyrebaseをインストールしようとしたことで結構苦しみましたが、これでまたエラー耐性が付いたので良しとします...(これでやっとflaskの作業に移れる...)

(余談ですが、このエラーに苦しめられた後に、本日開催されたAtcoder ABC 147 が全く出来ずにさらに悲しい気持ちになっております。)
#リンク
https://github.com/nhorvath/Pyrebase4
https://github.com/brianloveswords/python-jws

6
3
3

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
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?