首页 文章

无法在Heroku中安装Django软件包

提问于
浏览
1

我刚刚将我的应用程序部署到Heroku,并且在打开应用程序时遇到错误,它说:“ModuleNotFoundError:没有名为'crispy_forms'的模块”,而且MultiSelectField也是如此 .

我试图在平台的控制台中安装这些软件包,但它似乎没有任何效果,每次运行'heroku run pip freeze'时,我都会得到相同的软件包 .

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

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 freeze'命令的包列表中,但是当我在平台上检查时,更新不存在 .

如下所示,我在根文件夹中添加了“requirements.txt”文件,其中包含Pipfile,Procfile .

使用代码pip freeze> requirements.txt添加了“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

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

    你所做的不起作用的原因是 heroku run bash - 或任何命令 - 创造了一个全新的dyno;你在那里安装了这些包,但是当你退出并且其他dynos没有受到影响时,dyno会被立即杀死 .

  • 0

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

    您通过 heroku run bash 所做的更改不会持久 . 一旦你退出bash,dyno会立即终止 .

    我建议您在根文件夹中创建一个需要_687697的requirements.txt,或者在Pipfile中提及依赖项 .

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

    在Pipfile中添加它

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

相关问题