Dokku 编译错误 - django.core.exceptions.ImproperlyConfigured: 加载psycopg2模块时出错,没有名为'psycopg2'的模块。
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Dokku 编译错误 - django.core.exceptions.ImproperlyConfigured: 加载psycopg2模块时出错,没有名为'psycopg2'的模块。相关的知识,希望对你有一定的参考价值。
我一直在尝试将我建立的Django Instance设置为数据库服务器,我选择了DigitalOcean作为我的平台,并阅读了Dokku是一个有用的PaaS系统,将使我试图部署的这个API具有更好的扩展性。曾选择了DigitalOcean作为我的平台,并读到Dokku是一个有用的PaaS系统,可以让我试图部署的这个API有更好的扩展性。
在过去的3-4天里,我一直在这个问题上连轴转,真的已经把网上能找到的所有潜在的解决手段都找遍了。
作为一个前端开发比较多的人,我对后台安装这件事很不擅长。
一开始我以为Dokku是一种Git-push的功能,我将Git-push从 localhost -> Dokku -> Git -> Deploy.
深入研究后,我为Dokku设置了Public-Private密钥,以授权Git推送到Github。
最终,在最终放弃了这一途径后,我确实意识到自己错了,Dokku的工作方式大致应该是这样的 localhost -> Git push -> Dokku -> Deploy.
在过去的15-18小时的开发中,一直在这个。流程似乎工作,我真的不需要做太多的安装在DigitalOcean液滴。
然而,最大的问题,我面临的是与这个
我目前的安装情况是这样的。
- DigitalOcean Droplet 1-click Dokku VERSION 0.14.6
- 操作系统 Ubuntu 18.04
我已经添加了所有建议的文件,因为我在网上的博客和论坛中发现以下根文件夹下。
requirements.txt
---
absl-py==0.4.0
astor==0.7.1
backports.weakref==1.0.post1
dj-database-url==0.5.0
Django==1.11.20
django-cors-headers==3.0.0
django-filter==2.0.0
djangorestframework==3.9.4
enum34==1.1.6
funcsigs==1.0.2
futures==3.2.0
gast==0.2.0
GDAL==2.4.1
grpcio==1.14.1
h5py==2.8.0
Keras==2.2.2
Keras-Applications==1.0.4
Keras-Preprocessing==1.0.2
Markdown==2.6.11
mock==2.0.0
nose==1.3.7
numpy==1.16.3
pbr==4.2.0
Pillow==6.0.0
protobuf==3.6.1
psycopg2==2.8.2
pytz==2019.1
PyYAML==3.13
scipy==1.1.0
six==1.11.0
sqlparse==0.3.0
tensorboard==1.10.0
tensorflow==1.10.1
termcolor==1.1.0
Theano==1.0.2
virtualenv==16.5.0
Werkzeug==0.14.1
whitenoise==4.1.2
---
runtime.txt
---
<code>python-3.6.8</code>
app.json
---
{
"scripts": {
"dokku": {
"postdeploy": "./manage.py migrate"
}
}
}
---
Procfile
---
web: gunicorn core.wsgi — log-file -
---
settings.py
---
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': 'dbname',
'USER': 'dbuser',
'PASSWORD': 'dbpassword',
'HOST': 'localhost',
'PORT': '5432',
},
'original': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
}
}
我希望在输入"git push独库主"编译后会给我一个部署网址,我可以查看并启动Django服务器。
然而,我所面临的是。
Enumerating objects: 8664, done.
Counting objects: 100% (8664/8664), done.
Delta compression using up to 8 threads
Compressing objects: 100% (5363/5363), done.
Writing objects: 100% (8664/8664), 17.23 MiB | 3.67 MiB/s, done.
Total 8664 (delta 2186), reused 8568 (delta 2157)
remote: Resolving deltas: 100% (2186/2186), done.
-----> Cleaning up...
-----> Building apihirebred from herokuish...
-----> Adding BUILD_ENV to build environment...
-----> Python app detected
-----> Installing python-3.6.8
-----> Installing pip
-----> Installing dependencies with Pipenv 2018.5.18…
Installing dependencies from Pipfile…
-----> Noticed GDAL. Bootstrapping gdal.
-----> $ python manage.py collectstatic --noinput
Traceback (most recent call last):
File "/app/.heroku/python/lib/python3.6/site-packages/django/db/backends/postgresql/base.py", line 20, in <module>
import psycopg2 as Database
ModuleNotFoundError: No module named 'psycopg2'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "manage.py", line 22, in <module>
execute_from_command_line(sys.argv)
File "/app/.heroku/python/lib/python3.6/site-packages/django/core/management/__init__.py", line 381, in execute_from_command_line
utility.execute()
File "/app/.heroku/python/lib/python3.6/site-packages/django/core/management/__init__.py", line 357, in execute
django.setup()
File "/app/.heroku/python/lib/python3.6/site-packages/django/__init__.py", line 24, in setup
apps.populate(settings.INSTALLED_APPS)
File "/app/.heroku/python/lib/python3.6/site-packages/django/apps/registry.py", line 114, in populate
app_config.import_models()
File "/app/.heroku/python/lib/python3.6/site-packages/django/apps/config.py", line 211, in import_models
self.models_module = import_module(models_module_name)
File "/app/.heroku/python/lib/python3.6/importlib/__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 994, in _gcd_import
File "<frozen importlib._bootstrap>", line 971, in _find_and_load
File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 665, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 678, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "/app/.heroku/python/lib/python3.6/site-packages/django/contrib/auth/models.py", line 2, in <module>
from django.contrib.auth.base_user import AbstractBaseUser, BaseUserManager
File "/app/.heroku/python/lib/python3.6/site-packages/django/contrib/auth/base_user.py", line 47, in <module>
class AbstractBaseUser(models.Model):
File "/app/.heroku/python/lib/python3.6/site-packages/django/db/models/base.py", line 117, in __new__
new_class.add_to_class('_meta', Options(meta, app_label))
File "/app/.heroku/python/lib/python3.6/site-packages/django/db/models/base.py", line 321, in add_to_class
value.contribute_to_class(cls, name)
File "/app/.heroku/python/lib/python3.6/site-packages/django/db/models/options.py", line 204, in contribute_to_class
self.db_table = truncate_name(self.db_table, connection.ops.max_name_length())
File "/app/.heroku/python/lib/python3.6/site-packages/django/db/__init__.py", line 28, in __getattr__
return getattr(connections[DEFAULT_DB_ALIAS], item)
File "/app/.heroku/python/lib/python3.6/site-packages/django/db/utils.py", line 201, in __getitem__
backend = load_backend(db['ENGINE'])
File "/app/.heroku/python/lib/python3.6/site-packages/django/db/utils.py", line 110, in load_backend
return import_module('%s.base' % backend_name)
File "/app/.heroku/python/lib/python3.6/importlib/__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "/app/.heroku/python/lib/python3.6/site-packages/django/db/backends/postgresql/base.py", line 24, in <module>
raise ImproperlyConfigured("Error loading psycopg2 module: %s" % e)
django.core.exceptions.ImproperlyConfigured: Error loading psycopg2 module: No module named 'psycopg2'
! Error while running '$ python manage.py collectstatic --noinput'.
See traceback above for details.
You may need to update application code to resolve this error.
Or, you can disable collectstatic for this application:
$ heroku config:set DISABLE_COLLECTSTATIC=1
https://devcenter.heroku.com/articles/django-assets
更具体地说
"django.core.exceptions.ImproperlyConfigured: 加载psycopg2模块时出错,没有名为'psycopg2'的模块。没有名为'psycopg2'的模块。"无论我如何解决这个错误,这个错误一直存在。 ! [remote rejected] master -> master (pre-receive hook declined) error: failed to push some refs to 'dokku@server' (远程拒绝)
无论我如何尝试在Dokku和我的localhost上安装 "psycopg2",都无法解决这个错误。
我真诚地希望有人能帮助我解决以上问题,因为我不是Dokku的专家,也不知道Dokku到底是如何编译包的,为什么编译器无法检索 "psycopg2 "进行部署。
我也希望这也不会是今后唯一的问题。
希望能听到您的专业建议。谢谢!我一直在尝试设置 "psycopg2 "来进行部署。
试试这个docker命令来安装psycopg2适配器。
docker-compose exec web pipenv install psycopg2-binary==2.8.3
如果你愿意,你也可以提到你自己的具体版本。
如果你仍然得到一个错误,这意味着容器没有正确停止。使用下面的命令来停止它
docker-compose down
安装完psycopg2后再启动。
docker-compose up
以上是关于Dokku 编译错误 - django.core.exceptions.ImproperlyConfigured: 加载psycopg2模块时出错,没有名为'psycopg2'的模块。的主要内容,如果未能解决你的问题,请参考以下文章
错误:'没有名为'django.core.urlresolvers'的模块
python django-admin.py startproject xxx 错误:from django.core import management