【问题标题】:Python does not find the Brownie filePython 找不到布朗尼文件
【发布时间】:2021-12-23 21:50:29
【问题描述】:

我正在学习关于 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>

目录图片:

任何帮助将不胜感激:)

【问题讨论】:

  • 感谢您制作这个,您可以添加您的脚本和您的目录的图像吗?
  • 感谢您与我们联系,Patrick,非常感谢您所做的所有工作,帮助我们智能合约领域的新手 :) 我将更新我的原始帖子带有脚本和图像。

标签: python visual-studio-code brownie


【解决方案1】:

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

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

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

编辑:

您可能需要安装nodejsganache-cli

【讨论】:

  • 我已经把deploy.py脚本移到brownie_simple_storage文件夹下,报错信息还是一样
  • 啊抱歉,请将deploy.py 放入您的scripts 文件夹中。
  • 同样的错误信息......还有一点很奇怪,当我输入`Python --version`时,我可以很好地打印出版本,但是当我对布朗尼做同样的事情时,我得到`信息:找不到给定模式的文件。 Brownie v1.17.1 - 以太坊的 Python 开发框架。问题可能来自布朗尼的安装文件夹吗?
  • 不,没关系。你有安装 ganache-cli 吗?
  • 我做了,但是当我检查时,我收到了这个消息:ganache-cli : The term 'ganache-cli' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again. At line:1 char:1 + ganache-cli --version + ~~~~~~~~~~~ + CategoryInfo : ObjectNotFound: (ganache-cli:String) [], CommandNotFoundException + FullyQualifiedErrorId : CommandNotFoundException 通过 Yarn 再次安装它,同样的错误消息回来了
【解决方案2】:

我认为由于brownie是通过pipx安装的,所以你必须告诉vs code的路径。

  • ctrl + shift + p

  • Python:选择解释器

  • 添加路径

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

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

【讨论】:

    猜你喜欢
    • 2022-01-03
    • 1970-01-01
    • 2021-12-03
    • 1970-01-01
    • 2022-08-09
    • 2023-02-06
    • 2021-11-08
    • 2021-09-21
    • 2022-01-23
    相关资源
    最近更新 更多