无法在Heroku中安装Django软件包

时间:2018-08-21 12:31:37

标签: python django heroku

我刚将我的应用程序部署到Heroku,打开应用程序时出现错误,它说:“ ModuleNotFoundError:没有名为'crispy_forms'的模块”,与MultiSelectField相同。

我试图在平台的控制台中安装这些软件包,但是似乎没有效果,每次我运行“ heroku run pip Frozen”时,我都会得到相同的软件包。

我尝试在运行以下命令的本地控制台中执行此操作:

heroku run bash
pip install django-crispy-forms
pip install django-multiselectfield
pip freeze # To check if the packages where installed

然后我发现一切似乎都很好,django-crispy-forms和django-multiselectfield出现在“ pip Frozen”命令的软件包列表中,但是当我检入平台时,更新不存在。

如下所示,我在根文件夹中添加了“ requirements.txt”文件以及Pipfile Procfile。

“ requirements.txt”文件中添加了代码pip Frozen> requirements.txt:

argon2-cffi==18.1.0
bcrypt==3.1.4
certifi==2018.4.16
cffi==1.11.5
chardet==3.0.4
dj-database-url==0.4.2
Django==2.0
django-crispy-forms==1.7.2
-e git://github.com/AndrewIngram/django-extra- 
views.git@aa58167af84d89feea286f9567a72cc5941360e4#egg=django_extra_views
django-heroku==0.1.0
django-multiselectfield==0.1.8
django-session-timeout==0.0.3
gunicorn==19.7.1
idna==2.7
mailsnake==1.6.4
numpy==1.14.5
pandas==0.23.3
Pillow==5.2.0
pipenv==2018.5.18
psycopg2==2.7.3.2
pycparser==2.18
python-dateutil==2.7.3
pytz==2017.3
requests==2.19.1
six==1.11.0
stripe==2.4.0
urllib3==1.23
virtualenv==16.0.0
virtualenv-clone==0.3.0
whitenoise==3.3.1

我的Pipfile如下:

[[source]]

url = "https://pypi.python.org/simple"
verify_ssl = true


[packages]

django = "*"
gunicorn = "*"
django-heroku = "*"
django-crispy-forms = "*"
django-multiselectfield = "*"


[requires]

python_version = "3.6"

我的git push heroku master的输出如下:

Counting objects: 3, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (3/3), done.
Writing objects: 100% (3/3), 711 bytes | 0 bytes/s, done.
Total 3 (delta 1), reused 0 (delta 0)
remote: Compressing source files... done.
remote: Building source:
remote:
remote: -----> Python app detected
remote:        Skipping installation, as Pipfile.lock hasn't changed since 
last 
deploy.
remote: -----> Discovering process types
remote:        Procfile declares types -> web
remote:
remote: -----> Compressing...
remote:        Done: 156.9M
remote: -----> Launching...
remote:        Released v14
remote:        https://blooming-headland-56472.herokuapp.com/ deployed to 
Herok
remote:
remote: Verifying deploy... done.
To https://git.heroku.com/blooming-headland-56472.git
   d4535c9..5966fd9  master -> master

2 个答案:

答案 0 :(得分:0)

不要尝试手动安装软件包。您应该创建一个requirements.txt文件并将其提交到git,然后Heroku会在部署时自动安装软件包。

您未完成操作的原因是heroku run bash-或任何命令-创建了一个全新的测功机;您在此处安装了软件包,但是退出时,测功机会立即终止,其他测功机不会受到影响。

答案 1 :(得分:0)

https://devcenter.heroku.com/articles/deploying-python

您通过heroku run bash进行的更改不会持续。一旦退出bash,则dyno立即终止。

我建议您在根文件夹中创建诸如pip freeze > requirements.txt之类的requirements.txt或在Pipfile中提及依赖项。

  

在部署应用程序时会自动安装Pipfile或requirements.txt中指定的依赖项。

将此添加到您的Pipfile

[packages]
django-crispy-forms = "*"
django = "*"
django-multiselectfield = "*"