pgsync
pgsync copied to clipboard
ModuleNotFoundError: No module named 'plugins'
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'
Sorry about this. Fixed now
I am still getting this error can you help?
I am still facing the same problem, is there any suggestion to fix it? @toluaina
Same error when trying to use plugins in the schema
So this issue was closed which is why it was not visible.
- First, create a "plugins" directory and add it to your PYTHONPATH.
- Create your plugin module inside the plugins director e.g
plugins/full_name_plugin.py
- Make sure you have an init module inside the plugins director
plugins/__init__.py
- 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
- In your schema.json, ensure you have referenced the plugin by its name
{
"plugins": ["Fullname"]
...
}
My issue turned out to be the PYTHONPATH being .../plugins
instead of just ...
excluding the plugins directory itself. Cheers!
closing as resolved. Also updated the docs