【问题标题】:What do I add to my requirements.txt in Django directory in order to push it to Heroku?为了将其推送到 Heroku,我应该在 Django 目录中的 requirements.txt 中添加什么?
【发布时间】:2018-02-07 09:44:08
【问题描述】:

我是编程/Web 开发的新手,我想将 Django 目录推送到 heroku。但是每次我在命令行中输入“git push heroku master”时都会遇到同样的错误:

"Could not find a version that satisfies the requirement bonjour-py==0.3 (from -r /tmp/build_602f#############86ff270e/requirements.txt (line 3)) (from versions: )"

我激活了虚拟环境,但无济于事。现在我假设问题可能是我的 requirements.txt 文件不包含任何内容(因为我认为无论如何都没有理由)。不过,我想知道"bonjour-py==0.3" 是什么以及如何解决这个问题。非常感谢您的帮助!

【问题讨论】:

  • 您可以按照 Kostas 的答案进行操作,或者,如果确实只有 bonjour-py 丢失,请使用 pip install bonjour-py 在 heroku 上安装它。

标签: python django git heroku


【解决方案1】:

问题是,python2.7 和 python3.x 是不同的版本。您需要相同版本的 python - 服务器和本地。

待办事项:

  1. 用终端进入项目目录

    cd /your/path/to/project/

  2. 激活你的虚拟环境

    源环境/bin/激活

  3. 使用 pip 生成 requirements.txt

    pip freeze > requirements.txt

  4. 转到您的服务器并使用相同的 python 版本创建新的 virtualenv (https://virtualenv.pypa.io/en/stable/reference/#cmdoption-p)

    virtualenv --python=python2.7 环境

  5. 在服务器上激活 virtualenv

    源环境/bin/激活

  6. 使用 pip 安装 requirements.txt

    pip install -r requirements.txt

  7. Django 迁移

    python manage.py 迁移

  8. 使用 runserver 启动 django(进行测试)或连接 webserver(nginx、uwsgi、gunicorn、...)

    python manage.py runserver

【讨论】:

    【解决方案2】:

    在您的 Python 虚拟环境和项目路径中,只需键入:

    pip freeze > requirements.txt.

    这将在requirements.txt 文件中列出您使用的每个 python 包的确切版本。这就是 Heroku 将如何知道它需要安装哪些包才能运行您的 Django 应用程序的方式。

    【讨论】:

    • 还要确保使用与 heroku 上相同的 Python 版本。至少不要混合使用 Python 2 和 3。许多库对于某些 Python 版本不可用。
    • 我相信我现在使用了错误的 Python 版本。我使用的是 python-2.7.10,我猜这会导致冲突。我将 python 更新为 python-3.6.2,但我的终端仍然告诉我我使用的是 python-2.7.10。创建别名也不起作用。任何想法如何解决这个问题?
    猜你喜欢
    • 2015-07-09
    • 1970-01-01
    • 1970-01-01
    • 2018-06-30
    • 2021-05-18
    • 2014-01-10
    • 1970-01-01
    • 2021-03-02
    • 1970-01-01
    相关资源
    最近更新 更多