本文介绍了Dokku编译错误-django.core.exceptions.ImproperlyConfigured:加载psycopg2模块时出错:没有名为'psycopg2'的模块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在尝试将内置的Django实例设置为数据库服务器.选择DigitalOcean作为我的平台,并已阅读Dokku是有用的PaaS系统,它将为我尝试部署的该API提供更好的可伸缩性.

I've been attempting to setup my built-up Django Instance as a Database Server. Had chosen DigitalOcean as my platform and had read that Dokku is a useful PaaS system that will enable better scalability for this API I'm trying to deploy.

在过去的3-4天里,我一直在解决这个问题,并且确实经历了我在网上可以找到的所有可能的解决方案.

I have been at this problem for the last 3-4 days straight and really had gone through every potential means of solution I could have found online.

作为一名前端开发人员,我在此后端安装问题上非常不好.

Being more of a front-end developer, I'm pretty bad at this backend installation matter.

起初我以为Dokku是一种Git-push功能,我将从 localhost-> Dokku-> Git->部署进行推送.

At first I thought that Dokku was sort of a Git-push function where I will push from localhost -> Dokku -> Git -> Deploy.

深入研究,我为Dokku设置了公私钥,以授权将Git推送到Github.

Digging deep, I setup Public-Private keys for Dokku to authorize a Git push to Github.

最终,在最终放弃那条路线之后,我确实意识到自己错了,并且Dokku应该工作的大致方式是 localhost-> Git push-> Dokku->部署.

Ultimately, after finally giving up on that route, I did realised I was in the wrong and roughly the way Dokku should work is localhost -> Git push -> Dokku -> Deploy.

在开发的最后15到18个小时内都处于这种状态.该流程似乎可以正常工作,我实际上并不需要在DigitalOcean Droplet上进行大量安装.

Been at this for the last 15-18 hrs of development. The flow seemed to work, where I didn't really need to do much installations on the DigitalOcean droplet.

但是,我面临的最大问题是

However, the biggest issue I am facing is with this

我当前的安装情况如下:

My current install is as so:

  • DigitalOcean Droplet 1单击Dokku版本0.14.6
  • 操作系统Ubuntu 18.04

我已将所有建议的文件添加到根文件夹下的以下在线博客和论坛中:

I have added all suggested files as I have found in online blogs and forums of the following under the root folder:


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 dokku master "之后,编译将为我提供一个部署URL,我可以查看并启动Django服务器.

I was expecting after typing "git push dokku master" the compilation will give me a deployment url which I can view and launch the Django server.

但是,我当时所面对的是:

However, what I was face was:


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



更具体地说:


无论我如何尝试在Dokku和localhost上安装"psycopg2",我都无法解决该错误.


No matter how I have tried to install on both Dokku and my localhost for "psycopg2", I was unable to resolve the bug.

我衷心希望有人能在上述方面为我提供帮助,因为对于Dokku或其真正如何编译软件包以及为何编译器无法检索"psycopg2"的部署,我不是专家.

I sincerely hope someone can assist me with the above, as I am no expert on this matter with Dokku or how it really compiles the package and why the compiler is unable to retrieve "psycopg2" for the deployment.

我也希望这也不会是唯一向前发展的问题.

I also hope this will not be the only issue moving forward as well.

希望听听您的专家建议.谢谢!

Hope to hear your expert advice. Thanks!

推荐答案

尝试使用此docker命令安装psycopg2适配器

docker-compose exec web pipenv install psycopg2-binary==2.8.3

如果您愿意,您也可以提及自己的特定版本.

you can also mention your own specific version if you like.

如果仍然出现错误,则表示容器未正确停止.使用以下命令将其停止

if you still get an error it means the container is not stopped properly. Use below command to stop it

docker-compose down

然后在安装psycopg2之后启动它

and then start it after installing psycopg2

docker-compose up

这篇关于Dokku编译错误-django.core.exceptions.ImproperlyConfigured:加载psycopg2模块时出错:没有名为'psycopg2'的模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

05-22 11:54