LoginSignup
20
14

More than 5 years have passed since last update.

HerokuにPython Djangoをデプロイするときエラー「No matching distribution found for anaconda-client==1.6...」

Last updated at Posted at 2018-07-06

DjangoをHerokuにデプロイするときこんなエラーに遭遇しました。

$ git push heroku master
Counting objects: 499, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (493/493), done.
Writing objects: 100% (499/499), 1.20 MiB | 576.00 KiB/s, done.
Total 499 (delta 156), reused 0 (delta 0)
remote: Compressing source files... done.
remote: Building source:
remote: 
remote: -----> Python app detected
remote: -----> Installing requirements with pip
remote:        Collecting alabaster==0.7.10 (from -r /tmp/build_xxx/requirements.txt (line 1))
remote:          Downloading https://files.pythonhosted.org/packages/2e/c3/xxx/alabaster-0.7.10-py2.py3-none-any.whl
remote:        Collecting anaconda-client==1.6.14 (from -r /tmp/build_xxx/requirements.txt (line 2))
remote:          Could not find a version that satisfies the requirement anaconda-client==1.6.14 (from -r /tmp/build_xxx/requirements.txt (line 2)) (from versions: 1.1.1, 1.2.2)
remote:        No matching distribution found for anaconda-client==1.6.14 (from -r /tmp/build_xxx/requirements.txt (line 2))
remote:  !     Push rejected, failed to compile Python app.
remote: 
remote:  !     Push failed
remote: Verifying deploy...
remote: 
remote: !   Push rejected to djangogirlsblog.
remote: 
To https://git.heroku.com/djangogirlsblog.git
 ! [remote rejected] master -> master (pre-receive hook declined)
error: failed to push some refs to 'https://git.heroku.com/djangogirlsblog.git'

anaconda-clientが見つかりませんでした、というエラーです。

原因

仮想環境を作っていないために、pip freezeコマンドで requirements.txtを作成すると、ローカルにインストールしたライブラリがすべて出てしまうことが原因です。

解決策

仮想環境を作って、Herokuに必要なライブラリだけを pip install してから pip freeze でrequirements.txtを作成します。

python -m venv heroku_env       # 仮想環境を作る(Python 3.3からの標準機能)
source heroku_env/bin/activate  # 仮想環境をアクティベート
pip install --upgrade pip       # pipアップグレード
pip install django-toolbelt     # pipにDjangoインストール(他に必要なライブラリがあればそれも入れます)
pip freeze > requirements.txt   # requirements.txtを再作成
git add .
git commit -m 'comment'
git push heroku master          # デプロイ

こんな感じになったら成功

$ git push heroku master
Counting objects: 501, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (495/495), done.
Writing objects: 100% (501/501), 1.20 MiB | 578.00 KiB/s, done.
Total 501 (delta 158), reused 0 (delta 0)
remote: Compressing source files... done.
remote: Building source:
remote: 
remote: -----> Python app detected
remote: -----> Installing requirements with pip
remote: 
remote: -----> Discovering process types
remote:        Procfile declares types -> web
remote: 
remote: -----> Compressing...
remote:        Done: 65.8M
remote: -----> Launching...
remote:        Released v16
remote:        https://djangogirlsblog.herokuapp.com/ deployed to Heroku
remote: 
remote: Verifying deploy... done.
To https://git.heroku.com/djangogirlsblog.git
   8f60f8f..ade1264  master -> master
Author : 溝江 智徳
20
14
1

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
20
14