ModuleNotFoundError: No module named 'plugins.'
insaneadinesia opened this issue · 2 comments
insaneadinesia commented
PGSync version: 2.5.0
Postgres version: postgres (PostgreSQL) 14.8 (Homebrew)
Elasticsearch version: docker.elastic.co/elasticsearch/elasticsearch:7.8.0
Redis version: 7.0.8
Python version: Python 3.8.9
Problem Description:
Got ModuleNotFoundError: No module named 'plugins.'1
when define schema with plugins.
- Already Export PYTHONPATH
export PYTHONPATH=$PYTHONPATH:/Users/mamatosai/efishery/pgsync/module
- My Test Plugin
from pgsync import plugin
class TestPlugin(plugin.Plugin):
print('masuk')
name = 'Test'
def transform(self, doc, **kwargs):
print('masuk2')
doc['test'] = 'masuk'
print('masuk3')
return doc
Error Message (if any):
efishery/pgsync/book took 2s
➜ pgsync --config schema.json -d
masuk
- public.books
- public.authors
0:00:00.206699 (0.21 sec)
Traceback (most recent call last):
File "/Users/mamatosai/Library/Python/3.8/bin/pgsync", line 7, in <module>
sync.main()
File "/Users/mamatosai/Library/Python/3.8/lib/python/site-packages/click/core.py", line 1130, in __call__
return self.main(*args, **kwargs)
File "/Users/mamatosai/Library/Python/3.8/lib/python/site-packages/click/core.py", line 1055, in main
rv = self.invoke(ctx)
File "/Users/mamatosai/Library/Python/3.8/lib/python/site-packages/click/core.py", line 1404, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "/Users/mamatosai/Library/Python/3.8/lib/python/site-packages/click/core.py", line 760, in invoke
return __callback(*args, **kwargs)
File "/Users/mamatosai/Library/Python/3.8/lib/python/site-packages/pgsync/sync.py", line 1450, in main
sync: Sync = Sync(document, verbose=verbose, **kwargs)
File "/Users/mamatosai/Library/Python/3.8/lib/python/site-packages/pgsync/singleton.py", line 17, in __call__
cls._instances[key] = super(Singleton, cls).__call__(
File "/Users/mamatosai/Library/Python/3.8/lib/python/site-packages/pgsync/sync.py", line 102, in __init__
self._plugins: Plugins = Plugins("plugins", self.plugins)
File "/Users/mamatosai/Library/Python/3.8/lib/python/site-packages/pgsync/plugin.py", line 26, in __init__
self.reload()
File "/Users/mamatosai/Library/Python/3.8/lib/python/site-packages/pgsync/plugin.py", line 33, in reload
self.walk(self.package)
File "/Users/mamatosai/Library/Python/3.8/lib/python/site-packages/pgsync/plugin.py", line 71, in walk
self.walk(f"{package}.{pkg}")
File "/Users/mamatosai/Library/Python/3.8/lib/python/site-packages/pgsync/plugin.py", line 37, in walk
module = import_module(package)
File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.8/lib/python3.8/importlib/__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
File "<frozen importlib._bootstrap>", line 991, in _find_and_load
File "<frozen importlib._bootstrap>", line 961, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
File "<frozen importlib._bootstrap>", line 991, in _find_and_load
File "<frozen importlib._bootstrap>", line 973, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'plugins.'
4d11 commented
Your directory should be named
/Users/mamatosai/efishery/pgsync/plugins
asturm-fe commented
Elaborating on @4d11 's answer:
The python module (aka the folder containing your my_plugin.py
) must be named "plugins" and must contain an (empty) __init__.py
file. The path you add to your PYTHONPATH is then the path to the parent-directory of that module (so you dont include the /plugins-part).