pgsync icon indicating copy to clipboard operation
pgsync copied to clipboard

ModuleNotFoundError: No module named 'plugins'

Open dberrocal-git opened this issue 3 years ago • 6 comments

PGSync version: lastest git pull 12.31am CET

Postgres version: docker-compose

Elasticsearch version: docker-compose

Redis version: docker-compose

Python version: docker-compose

Problem Description:

docker-compose up

Error Message (if any):

pgsync_1         |  0:00:00.000378 (0.00 sec)
pgsync_1         | Traceback (most recent call last):
pgsync_1         |   File "/usr/local/bin/pgsync", line 7, in <module>
pgsync_1         |     sync.main()
pgsync_1         |   File "/usr/local/lib/python3.7/site-packages/click/core.py", line 1137, in __call__
pgsync_1         |     return self.main(*args, **kwargs)
pgsync_1         |   File "/usr/local/lib/python3.7/site-packages/click/core.py", line 1062, in main
pgsync_1         |     rv = self.invoke(ctx)
pgsync_1         |   File "/usr/local/lib/python3.7/site-packages/click/core.py", line 1404, in invoke
pgsync_1         |     return ctx.invoke(self.callback, **ctx.params)
pgsync_1         |   File "/usr/local/lib/python3.7/site-packages/click/core.py", line 763, in invoke
pgsync_1         |     return __callback(*args, **kwargs)
pgsync_1         |   File "/usr/local/lib/python3.7/site-packages/pgsync/sync.py", line 1139, in main
pgsync_1         |     sync = Sync(document, verbose=verbose, **kwargs)
pgsync_1         |   File "/usr/local/lib/python3.7/site-packages/pgsync/sync.py", line 75, in __init__
pgsync_1         |     document.get("database", self.index), verbose=verbose, **kwargs
pgsync_1         |   File "/usr/local/lib/python3.7/site-packages/pgsync/base.py", line 55, in __init__
pgsync_1         |     self.__engine = pg_engine(database, **kwargs)
pgsync_1         |   File "/usr/local/lib/python3.7/site-packages/pgsync/base.py", line 1012, in pg_engine
pgsync_1         |     port=port,
pgsync_1         |   File "/usr/local/lib/python3.7/site-packages/pgsync/utils.py", line 143, in get_postgres_url
pgsync_1         |     plugins: Plugins = Plugins("plugins", ["Auth"])
pgsync_1         |   File "/usr/local/lib/python3.7/site-packages/pgsync/plugin.py", line 26, in __init__
pgsync_1         |     self.reload()
pgsync_1         |   File "/usr/local/lib/python3.7/site-packages/pgsync/plugin.py", line 33, in reload
pgsync_1         |     self.walk(self.package)
pgsync_1         |   File "/usr/local/lib/python3.7/site-packages/pgsync/plugin.py", line 37, in walk
pgsync_1         |     plugins = import_module(package)
pgsync_1         |   File "/usr/local/lib/python3.7/importlib/__init__.py", line 127, in import_module
pgsync_1         |     return _bootstrap._gcd_import(name[level:], package, level)
pgsync_1         |   File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
pgsync_1         |   File "<frozen importlib._bootstrap>", line 983, in _find_and_load
pgsync_1         |   File "<frozen importlib._bootstrap>", line 965, in _find_and_load_unlocked
pgsync_1         | ModuleNotFoundError: No module named 'plugins'



dberrocal-git avatar Sep 28 '21 10:09 dberrocal-git

Sorry about this. Fixed now

toluaina avatar Sep 28 '21 11:09 toluaina

I am still getting this error can you help?

sumitmitra255 avatar May 18 '22 05:05 sumitmitra255

I am still facing the same problem, is there any suggestion to fix it? @toluaina

behnood-R avatar Jun 17 '22 22:06 behnood-R

Same error when trying to use plugins in the schema

bitofbreeze avatar Jul 18 '22 23:07 bitofbreeze

So this issue was closed which is why it was not visible.

  1. First, create a "plugins" directory and add it to your PYTHONPATH.
  2. Create your plugin module inside the plugins director e.g plugins/full_name_plugin.py
  3. Make sure you have an init module inside the plugins director plugins/__init__.py
  4. full_name_plugin.py should look something like this
from pgsync import plugin

class FullnamePlugin(plugin.Plugin):
    name = 'Fullname'

    def transform(self, doc, **kwargs):

        firstname = doc['firstname'] 
        lastname = doc['lastname'] 
        doc['fullname'] = f'{firstname}{lastname}'

        return doc
  1. In your schema.json, ensure you have referenced the plugin by its name
    {
        "plugins": ["Fullname"]
         ...
    }

toluaina avatar Jul 19 '22 09:07 toluaina

My issue turned out to be the PYTHONPATH being .../plugins instead of just ... excluding the plugins directory itself. Cheers!

bitofbreeze avatar Jul 19 '22 10:07 bitofbreeze

closing as resolved. Also updated the docs

toluaina avatar Sep 02 '22 18:09 toluaina