LoginSignup
1
7

More than 5 years have passed since last update.

herokuでPythonライブラリ(pandas,sklearnとか)を使えるようにするための方法

Posted at

ローカル(開発)環境で使うには

これは、言わずもがなですが、コマンドからpipでインストールすればいいだけです。

herokuで使うには

いくつか、ファイルを編集する必要があります。git pushはできたけど、ブラウザ開いたらModuleNotFoundErrorになった時は、これをする必要があるかもしれません。

まずは、

pip freeze > requirements.txt

でrequirements.txtを生成する必要があります。すると、例えば以下のようなファイルが生成されます。(あくまで、一例です)

requirements.txt
beautifulsoup4==4.6.1
certifi==2018.4.16
chainer==4.3.1
chardet==3.0.4
cycler==0.10.0
dj-database-url==0.5.0
Django==2.1
django-heroku==0.3.1
filelock==3.0.4
gunicorn==19.9.0
html5lib==1.0.1
idna==2.7
jsm==0.19
kiwisolver==1.0.1
lxml==4.2.4
matplotlib==2.2.2
numpy==1.15.0
pandas==0.23.4
pandas-datareader==0.6.0
pipenv==2018.7.1
protobuf==3.6.0
psycopg2==2.7.5
pyparsing==2.2.0
python-dateutil==2.7.3
pytz==2018.5
requests==2.19.1
requests-file==1.4.3
requests-ftp==0.3.1
scikit-learn==0.19.2
scipy==1.1.0
six==1.11.0
sklearn==0.0
urllib3==1.23
virtualenv==16.0.0
virtualenv-clone==0.3.0
webencodings==0.5.1
whitenoise==3.3.1
wrapt==1.10.11

つぎに、Pipfileを編集します。例えば、pandasを使うなら、下記のようにpackagesに追加する必要があります。

[[source]]
url = "https://pypi.python.org/simple"
verify_ssl = true
name = "pypi"

[packages]
dj-database-url = "*"
django = "*"
gunicorn = "*"
psycopg2 = "*"
whitenoise = "*"
requests = "*"
pandas = "*"
jsm = "*"
pandas_datareader = "*"
matplotlib = "*"
chainer="*"
sklearn="*"
scipy="*"

[requires]
python_version = "3.6"

Pipfileを編集した上で、コマンドから、Pipfile.lockを生成します。

pipenv install

pipenvが無ければ、pipからpipenv自体をインストールしましょう。

これで、git add→commit→pushでできるハズです。

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