Python找不到Brownie文件

问题描述

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

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

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

PS C:UserschretDocumentsdemorownie_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:UserschretAppDataRoamingPythonPython39site-packagesrownie\_cli\__main__.py", line 64, in main
  importlib.import_module(f"brownie._cli.{cmd}").main()
File "C:UserschretAppDataRoamingPythonPython39site-packagesrownie\_cliun.py", line 44, in main
  network.connect(CONFIG.argv["network"])
File "C:UserschretAppDataRoamingPythonPython39site-packagesrownie
etworkmain.py", line 50, in connect
  rpc.launch(active["cmd"], **active["cmd_settings"])
File "C:UserschretAppDataRoamingPythonPython39site-packagesrownie
etworkpc\__init__.py", line 75, in launch
  self.process = self.backend.launch(cmd, **kwargs)
File "C:UserschretAppDataRoamingPythonPython39site-packagesrownie
etworkpcganache.py", line 73, in launch
  return psutil.Popen(cmd_list, stdin=DEVNULL, stdout=out, stderr=out)
File "C:UserschretAppDataRoamingPythonPython39site-packagespsutil\__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,现在消息略有不同,但仍然不能运行部署.py的脚本。脚本为:

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

当前错误消息为:

PS C:UserschretDocumentsdemorownie_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:UserschretAppDataLocalProgramsPythonPython39libsite-packagesrownie\_cli\__main__.py", line 64, in main
    importlib.import_module(f"brownie._cli.{cmd}").main()
  File "C:UserschretAppDataLocalProgramsPythonPython39libsite-packagesrownie\_cliun.py", line 44, in main
    network.connect(CONFIG.argv["network"])
  File "C:UserschretAppDataLocalProgramsPythonPython39libsite-packagesrownie
etworkmain.py", line 50, in connect
    rpc.launch(active["cmd"], **active["cmd_settings"])
  File "C:UserschretAppDataLocalProgramsPythonPython39libsite-packagesrownie
etworkpc\__init__.py", line 75, in launch
    self.process = self.backend.launch(cmd, **kwargs)
  File "C:UserschretAppDataLocalProgramsPythonPython39libsite-packagesrownie
etworkpcganache.py", line 73, in launch
    return psutil.Popen(cmd_list, stdin=DEVNULL, stdout=out, stderr=out)
  File "C:UserschretAppDataLocalProgramsPythonPython39libsite-packagespsutil\__init__.py", line 1312, in __init__
    self.__subproc = subprocess.Popen(*args, **kwargs)
  File "C:UserschretAppDataLocalProgramsPythonPython39libsubprocess.py", line 951, in __init__
    self._execute_child(args, executable, preexec_fn, close_fds,
  File "C:UserschretAppDataLocalProgramsPythonPython39libsubprocess.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:UserschretDocumentsdemorownie_simple_storage>

目录镜像:

如有任何帮助,我们将不胜感激:)

在尝试了所有建议后,我最终只通过卸载和删除每个单独的程序和相关文件才能使其正常工作。 卸载了Python,从我的电脑上删除了所有与Python相关的文件,对VSCode也做了同样的操作,删除了所有与教程相关的NPM包、纱线、Solc(我之前没有任何可以编码的东西)。

然后,复制所有步骤,直到最初的POST发布,一切都运行正常……不知道问题实际上是如何解决的,这有点令人沮丧,但它确实解决了。


解决方案

我认为由于brownie是通过pipx安装的,您必须告诉VS路径的代码。

  • ctrl+Shift+p

  • Python:选择解释器

  • 在os中查找路径。这是在Linux中

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

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

相关文章