Getting this error while trying to run a eth-brownie script on MacOS
ModuleNotFoundError: No module named 'Users.xyz'
Run command:
brownie run scripts/mainnet/poolUpdaterMainNet.py --network bsc-main
Would be great if someone can help.
I am on Python 3.9.6, but had a similar problem only using my MacOS, does not occur on my Linux machine.
Either way, I think I found a solution (at least for my version). The issue stems from the function _import_from_path in the file brownie/project/scripts.py (that should be found in your eth-brownie folder, wherever you installed it). The way it is written, it will incorrectly identify Users.username as "not a module."
My solution: replace _import_from_path with the following
def _import_from_path(path: Path) -> ModuleType:
# Imports a module from the given path
import_str = "/" + "/".join(path.parts[1:-1] + (path.stem,))+'.py'
if import_str in _import_cache:
importlib.reload(_import_cache[import_str])
else:
spec = importlib.util.spec_from_file_location('.'+path.stem,import_str)
module = importlib.util.module_from_spec(spec)
spec.loader.exec_module(module)
_import_cache[import_str] = module
return _import_cache[import_str]
Explanation: import_str is now modified to reflect the exact file location instead of a module name. The else: block now imports the module by specifying the file location and then loading that file as a module. I'm not sure if this will break any of the functionality in other operating systems, but I'm happy with using it as a hotfix for my Mac -- I can now run my scripts folder.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With