[英]Trying to run a Brownie Dapp in Docker
I'm trying to run my brownie dapp in a docker container, but i always have the same error and can't seem to fix it:我试图在 docker 容器中运行我的 brownie dapp,但我总是有同样的错误并且似乎无法修复它:
FileNotFoundError: [Errno 2] No such file or directory: 'C:/Users/username/.brownie/packages/OpenZeppelin/openzeppelin-> > contracts@4.4.2/contracts/access/Ownable.sol'
I cloned the OpenZepplin folder with all the contracts to the work folder of my project and then remapped it like this: dependencies:我将包含所有合约的 OpenZepplin 文件夹克隆到我项目的工作文件夹中,然后像这样重新映射它:依赖项:
- OpenZeppelin/openzeppelin-contracts@4.4.2
compiler:
solc:
remappings:
- "OpenZeppelin/openzeppelin-contracts@4.4.2/ = ./OpenZeppelin/openzeppelin-contracts@4.4.2/"
But it still gives the same error, and when I compile the contract, it is clearly still using the C:/Users/username/.brownie/packages/OpenZeppelin/openzeppelin-contracts@4.4.2/contracts folder.但它仍然给出相同的错误,当我编译合同时,它显然仍在使用C:/Users/username/.brownie/packages/OpenZeppelin/openzeppelin-contracts@4.4.2/contracts文件夹。 I know this because I tried to compile the contracts with a remapping to a non-existing folder:
我知道这一点是因为我试图通过重新映射到一个不存在的文件夹来编译合同:
remappings:
- "OpenZeppelin/openzeppelin-contracts@4.4.2/ = ./nothing/"
and it still compiled perfectly.它仍然可以完美编译。
Just wondering if anybody could help me with this, and thank you in advance!只是想知道是否有人可以帮助我,在此先感谢您!
Ok, I just had the IDENTICAL issue as yourself.好的,我刚刚遇到了与您相同的问题。 (I cloned a project and tried to run tests on my local machine, but got the same FileNotFoundError:)
(我克隆了一个项目并尝试在我的本地机器上运行测试,但得到了相同的 FileNotFoundError:)
But I managed to solve it.但我设法解决了它。
First thing you need to have is Brownie itself (Obviously).您首先需要拥有的是布朗尼蛋糕本身(很明显)。
Second thing is installed OpenZeppelin packages inside Brownie.第二件事是在 Brownie 中安装 OpenZeppelin 包。 Here is a link on how to set that up: @OpenZeppelin for Brownie
这是有关如何设置它的链接: @OpenZeppelin for Brownie
But in short, you just need this command:但简而言之,你只需要这个命令:
brownie pm install OpenZeppelin/openzeppelin-contracts@4.4.2
MAKE SURE IT'S THE VERSION OF @OpenZeppelin YOU NEED !!确保它是您需要的@OpenZeppelin 版本!!
3.Final step is to go into your project's build/contracts directory and delete ALL smartContract.json
files and then do brownie compile
anew. 3.最后一步是将 go 进入项目的 build/contracts 目录并删除所有
smartContract.json
文件,然后重新brownie compile
。
After that you can run test etc, it should work.之后你可以运行测试等,它应该工作。
IN DEPT EXPLANATION:在部门解释:
The reason we were getting that error was because Brownie uses smartCotnract.json build files to run the tests, and to locate all of its own dependencies/packages.我们收到该错误的原因是因为 Brownie 使用 smartCotnract.json 构建文件来运行测试,并找到它自己的所有依赖项/包。 Those.json files also contain paths to all of it (including @OpenZeppelin package), and are generated during compile phase only if they don't already exist or the code had been edited in a specific contract.
那些.json 文件还包含所有文件的路径(包括@OpenZeppelin 包),并且仅当它们尚不存在或代码已在特定合约中被编辑时才会在编译阶段生成。 (That is why you need to delete them if you want for
brownie compile
to generate new ones) (这就是为什么如果你想让
brownie compile
生成新的,你需要删除它们)
Therefor if I compile it on my local machine and push those smartContract.json files to git, and you happen to clone all of it and run the compile/tests.因此,如果我在我的本地机器上编译它并将那些 smartContract.json 文件推送到 git,你碰巧克隆了所有它并运行编译/测试。 It is highly unlikely it will work, as name-path on my local machine will differ.
它不太可能会起作用,因为我本地机器上的名称路径会有所不同。 (Username is practically 100% bound to be different)
(用户名几乎 100% 不同)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.