0

我正在关注关于 Solidity 和 Python 的教程(供参考https://www.youtube.com/watch?v=M576WGiDBdQ&t=5447s)。

我正处于安装 Python 和 Brownie 并通过 VSCode 运行的阶段,但是当我询问 Brownie 的版本时,我收到了以下通知 brownie --version INFO: Could not find files for the given pattern(s). Brownie v1.17.1 - Python development framework for Ethereum

当我尝试在名为 deploy.py ( ) 的文件上运行一个非常基本的脚本时def main(): print ("hello!"),结果如下:

PS C:\Users\chret\Documents\demo\brownie_simple_storage> brownie run scripts/deploy.py
INFO: Could not find files for the given pattern(s).
Brownie v1.17.1 - Python development framework for Ethereum

BrownieSimpleStorageProject is the active project.

Launching 'ganache-cli.cmd --port 8545 --gasLimit 12000000 --accounts 10 --hardfork istanbul --mnemonic brownie'...
File "C:\Users\chret\AppData\Roaming\Python\Python39\site-packages\brownie\_cli\__main__.py", line 64, in main
  importlib.import_module(f"brownie._cli.{cmd}").main()
File "C:\Users\chret\AppData\Roaming\Python\Python39\site-packages\brownie\_cli\run.py", line 44, in main
  network.connect(CONFIG.argv["network"])
File "C:\Users\chret\AppData\Roaming\Python\Python39\site-packages\brownie\network\main.py", line 50, in connect
  rpc.launch(active["cmd"], **active["cmd_settings"])
File "C:\Users\chret\AppData\Roaming\Python\Python39\site-packages\brownie\network\rpc\__init__.py", line 75, in launch
  self.process = self.backend.launch(cmd, **kwargs)
File "C:\Users\chret\AppData\Roaming\Python\Python39\site-packages\brownie\network\rpc\ganache.py", line 73, in launch
  return psutil.Popen(cmd_list, stdin=DEVNULL, stdout=out, stderr=out)
File "C:\Users\chret\AppData\Roaming\Python\Python39\site-packages\psutil\__init__.py", line 1312, in __init__
  self.__subproc = subprocess.Popen(*args, **kwargs)
File "C:\Program, line line, in in
  self._execute_child(args, executable, preexec_fn, close_fds,
File "C:\Program, line line, in in
  hp, ht, pid, tid = _winapi.CreateProcess(executable, args,
FileNotFoundError: [WinError 2] The system cannot find the file specified

我已经尝试从 Python 卸载并重新安装到 Brownie,更改了 Brownie 文件的位置,但由于我的知识非常有限(完全是初学者),我现在陷入困境。

更新我再次重新安装了 Python 和 pipx 和 brownie,现在消息略有不同,但仍然没有运行 deploy.py 的脚本。脚本是:

def main():
    print("Hello!")

当前的错误消息是:

PS C:\Users\chret\Documents\demo\brownie_simple_storage> brownie run scripts.deploy.py

INFO: Could not find files for the given pattern(s).
Brownie v1.17.1 - Python development framework for Ethereum

BrownieSimpleStorageProject is the active project.

Launching 'ganache-cli.cmd --port 8545 --gasLimit 12000000 --accounts 10 --hardfork istanbul --mnemonic brownie'...
  File "C:\Users\chret\AppData\Local\Programs\Python\Python39\lib\site-packages\brownie\_cli\__main__.py", line 64, in main
    importlib.import_module(f"brownie._cli.{cmd}").main()
  File "C:\Users\chret\AppData\Local\Programs\Python\Python39\lib\site-packages\brownie\_cli\run.py", line 44, in main
    network.connect(CONFIG.argv["network"])
  File "C:\Users\chret\AppData\Local\Programs\Python\Python39\lib\site-packages\brownie\network\main.py", line 50, in connect
    rpc.launch(active["cmd"], **active["cmd_settings"])
  File "C:\Users\chret\AppData\Local\Programs\Python\Python39\lib\site-packages\brownie\network\rpc\__init__.py", line 75, in launch
    self.process = self.backend.launch(cmd, **kwargs)
  File "C:\Users\chret\AppData\Local\Programs\Python\Python39\lib\site-packages\brownie\network\rpc\ganache.py", line 73, in launch
    return psutil.Popen(cmd_list, stdin=DEVNULL, stdout=out, stderr=out)
  File "C:\Users\chret\AppData\Local\Programs\Python\Python39\lib\site-packages\psutil\__init__.py", line 1312, in __init__
    self.__subproc = subprocess.Popen(*args, **kwargs)
  File "C:\Users\chret\AppData\Local\Programs\Python\Python39\lib\subprocess.py", line 951, in __init__
    self._execute_child(args, executable, preexec_fn, close_fds,
  File "C:\Users\chret\AppData\Local\Programs\Python\Python39\lib\subprocess.py", line 1420, in _execute_child
    hp, ht, pid, tid = _winapi.CreateProcess(executable, args,
FileNotFoundError: [WinError 2] The system cannot find the file specified
PS C:\Users\chret\Documents\demo\brownie_simple_storage>

目录图片:文件位置截图

任何帮助将不胜感激 :)

在尝试了所有建议后,我最终只能通过卸载和删除每个程序和相关文件来使其工作。卸载 Python,从我的计算机中删除所有与 Python 相关的文件,对 VSCode 执行相同操作,删除所有 npm 包、yarn、solc,以及与教程相关的所有内容(我之前没有任何用于编码的东西)。

然后,复制了所有步骤,直到原始帖子问题,一切正常......不知道问题是如何真正解决的有点令人沮丧,但确实如此。

4

2 回答 2

2

我认为既然brownie是通过安装的pipx,你必须告诉路径的vs代码。

  • ctrl + shift + p

  • Python:选择解释器

在此处输入图像描述

  • 在os中找到路径。这是在linux中

      ~/.local/pipx/venvs/eth-brownie/bin/python
    

我使用的是 Linux,所以在您的系统中找到路径并将其添加到那里。

于 2021-12-31T08:42:45.447 回答
1

您的deploy脚本位于contracts文件夹/目录中。

它需要在您的项目的脚本目录中,您的brownie_simple_storage/scripts文件夹中。

尝试将它移到那里,并在该文件夹中运行您的脚本。

编辑:

您可能需要安装nodejsganache-cli

于 2021-11-15T13:30:19.760 回答