0
0

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.

【Python2to3アップデート方法】caniusepython3でPython3系非対応のpipモジュールをチェック

Last updated at Posted at 2019-04-16

目次

概要

Python2系を3系にアップデートする際に、利用しているpipモジュールが3系で利用できるのかをチェックする、caniusepython3の使い方を説明する。

Installation

pipでインストールする。

$ pip install caniusepython3

Usage

module単位で調べる

$ caniusepython3 -p numpy scipy ipython

requirements.txtを調べる

$ caniusepython3 -r requirements.txt

setup.pyを調べる

# If your project's setup.py uses setuptools
# (note that setup_requires can't be checked) ...
$ python setup.py caniusepython3

requirements.txt調べてみる

requirements.txtを作成

以下の内容のrequirements.txtを調べる。

requirements.txt
# cat requirements.txt
backports.functools-lru-cache==1.5
backports.ssl-match-hostname==3.5.0.1
caniusepython3==7.0.0
certifi==2019.3.9
chardet==3.0.4
distlib==0.2.8
future==0.17.1
futures==3.2.0
idna==2.8
iniparse==0.4
ipaddress==1.0.16
kitchen==1.1.1
MySQL-python==1.2.5
packaging==19.0
pycurl==7.19.0
pygobject==3.22.0
pygpgme==0.3
pyliblzma==0.5.3
pyparsing==2.4.0
pyxattr==0.5.1
requests==2.21.0
six==1.12.0
urlgrabber==3.10
urllib3==1.24.1
yum-metadata-parser==1.1.4

チェックする

caniusepython3を実行する

iniparse, pygobject, pyliblzma, pyxattr, urlgrabberの5つが引っかかった。

$ caniusepython3 -r requirements.txt
Finding and checking dependencies ...
[WARNING] problem fetching yum-metadata-parser, assuming ported (404)

You need 5 projects to transition to Python 3.
Of those 5 projects, 5 have no direct dependencies blocking their transition:

  iniparse
  pygobject
  pyliblzma
  pyxattr
  urlgrabber

[WARNING] problem fetching yum-metadata-parser, assuming ported (404)

調べてみたが情報がないので、caniusepython3のソースを読んでみた。
https://github.com/brettcannon/caniusepython3/blob/master/caniusepython3/pypi.py#L85

pypi.py
def supports_py3(project_name):
    """Check with PyPI if a project supports Python 3."""
    log = logging.getLogger("ciu")
    log.info("Checking {} ...".format(project_name))
    request = requests.get("https://pypi.org/pypi/{}/json".format(project_name))
    if request.status_code >= 400:
        log = logging.getLogger("ciu")
        log.warning("problem fetching {}, assuming ported ({})".format(
                        project_name, request.status_code))
        return True
    response = request.json()
    return any(c.startswith("Programming Language :: Python :: 3")
               for c in response["info"]["classifiers"])

pypi.orgに該当のパッケージのページが存在しないとエラーが出るみたい。

つまり、このページが存在しない場合は、調べることができないということか。

module単位で実行した場合は以下のように出力される

$ caniusepython3 -p iniparse
Finding and checking dependencies ...

You need 1 project to transition to Python 3.
Of that 1 project, 1 has no direct dependencies blocking its transition:

  iniparse

Python3に対応しているmoudleの場合は、以下のように出力される

$ caniusepython3 -p requests
Finding and checking dependencies ...

You have 0 projects blocking you from using Python 3!

参考

0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?