0

用 brownie 实现烧瓶,在点击按钮时自动执行代码 create_collectible。导入简单收藏品来自本教程:

https://youtu.be/ZH_7nEIJDUY

链接:

  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/flask/cli.py", line 256, in locate_app
    __import__(module_name)
  File "/Users/work/Documents/OpenvinoNFT/app/api/api.py", line 2, in <module>
    from create_collectible import main, nftcode
  File "/Users/work/Documents/OpenvinoNFT/app/api/create_collectible.py", line 4, in <module>
    from brownie import SimpleCollectible, account, network, config
ImportError: cannot import name 'SimpleCollectible' from 'brownie' (/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/brownie/__init__.py)

Traceback (most recent call last)
File "/Users/work/Documents/OpenvinoNFT/app/api/api.py", line 2, in <module>
from create_collectible import main, nftcode
File "/Users/work/Documents/OpenvinoNFT/app/api/create_collectible.py", line 4, in <module>
from brownie import SimpleCollectible, account, network, config
During handling of the above exception, another exception occurred:
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/flask/cli.py", line 359, in __call__
rv = self._load_unlocked()
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/flask/cli.py", line 346, in _load_unlocked
self._app = rv = self.loader()
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/flask/cli.py", line 402, in load_app
app = locate_app(self, import_name, name)
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/flask/cli.py", line 261, in locate_app
raise NoAppException(
flask.cli.NoAppException: While importing 'api', an ImportError was raised:

Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/flask/cli.py", line 256, in locate_app
__import__(module_name)
File "/Users/work/Documents/OpenvinoNFT/app/api/api.py", line 2, in <module>
from create_collectible import main, nftcode
File "/Users/work/Documents/OpenvinoNFT/app/api/create_collectible.py", line 4, in <module>
from brownie import SimpleCollectible, account, network, config
ImportError: cannot import name 'SimpleCollectible' from 'brownie' (/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/brownie/__init__.py)
4

5 回答 5

1

我设法通过执行以下操作解决了这个问题:

在我的烧瓶应用程序中,我添加了:

os.system("brownie run scripts/simple_collectible/create_collectible.py  --network rinkeby")

在我烧瓶上的@app.route 下。

问题是代码在 python CLI 上运行,而不是在 Brownie CLI 中运行。

这可能不是最好的方法,但它确实有效。谢谢

于 2021-09-28T15:21:36.187 回答
1

将拼写更改为“SimpleCollectable”并安装“brownie pm install OpenZeppelin/openzeppelin-contracts@3.0.0”。

于 2021-12-06T19:33:09.877 回答
0

检查文档,您会发现可用的导入。

SimpleCollectible确实不在基本模块中

https://eth-brownie.readthedocs.io/en/stable/api-brownie.html#brownie

于 2021-09-24T20:33:34.280 回答
0

删除文件SimpleCollectible.sol(我不是指代码,我是指文件)。

然后使用其中的相关代码重新创建它。

于 2021-09-28T16:08:50.040 回答
0

您得到的错误的解释是,如果您直接使用 vs 代码运行脚本,则 brownie 看不到合同,您应该使用命令“brownie run create_collectible”从终端运行它

于 2021-12-05T16:37:38.573 回答