为了将其推送到Heroku,我应在Django目录中的我的requirements.txt中添加什么?

rud*_*iam 1 python git django heroku

我是编程/网络开发的新手,我想将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: )"
Run Code Online (Sandbox Code Playgroud)

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

Kos*_*tos 7

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

pip freeze > requirements.txt

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


小智 6

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

待办事项:

  1. 拿终端去项目目录

    cd /你的/路径/到/项目/

  2. 激活您的虚拟环境

    源环境/bin/激活

  3. 用pip生成requirements.txt

    pip冻结>需求.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(进行测试)或连接网络服务器(nginx、uwsgi、gunicorn 等)

    python manage.py runserver