python - eth-brownie - 没有名为 <Users.someuser> 的模块

标签 python macos blockchain solidity cryptocurrency

尝试在 MacOS 上运行 eth-brownie 脚本时出现此错误

ModuleNotFoundError: No module named 'Users.xyz'

运行命令:

brownie run scripts/mainnet/poolUpdaterMainNet.py --network bsc-main

如果有人能提供帮助,那就太好了。

最佳答案

我在 Python 3.9.6 上,但只在我的 MacOS 上遇到了类似的问题,在我的 Linux 机器上没有出现。

无论哪种方式,我想我都找到了解决方案(至少对于我的版本而言)。问题源于文件 brownie/project/scripts.py 中的函数 _import_from_path(应该在您的 eth-brownie 文件夹中找到,无论您安装它在哪里)。按照它的编写方式,它会错误地将 Users.username 识别为“不是模块”。

我的解决方案:将 _import_from_path 替换为以下内容

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]

说明:import_str 现在被修改为反射(reflect)准确的文件位置而不是模块名称。 else: block 现在通过指定文件位置导入模块,然后将该文件作为模块加载。我不确定这是否会破坏其他操作系统中的任何功能,但我很高兴将它用作我 Mac 的修补程序——我现在可以运行我的脚本文件夹。

关于python - eth-brownie - 没有名为 <Users.someuser> 的模块,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68721661/

相关文章:

python - 使用 Keras 训练 CNN-LSTM 时卡在第一个时期

python - 属性错误 : at/auth/login/facebook/Exception Value: operators

python - python中使用Tkinter编辑标题栏

C语言Osx下的彩色文本[Xcode]

blockchain - 如何使用 Quorum 进行智能合约存储迁移?

python - Scikit 学习管道类型错误 : zip argument #2 must support iteration

html - 列表元素不适合 IE 和 MAC 的 Chrome 上的给定空间

macos - Mac OSX : folder extension association programmatically

docker - 区 block 链 : Hyper Ledger Fabric Installations in Windows 10

java - 显示 Aion 账户的余额