Replies: 1 comment
-
Thank you for the effort, helps us beginners a lot! |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
This is a long post, why should you read it?
I encountered over the last few months many situations, where some version conflicts were at play. The main ingredients here are Python and NodeJS. With the solution described here, you have the flexibility to tune both nobs Python and NodeJS to whatever fits your project. A large number of questions in this forum originate from wrong or at least unclear setups. This here is a long article, but it might help you to overcome or even never face those problems.
I am trying to keep this up-to-date. If you notice mistakes in this article or changes like for example the newest Brownie installs now in the latest Python version, please let me know.
Content overview
EDIT 14. Mar 2022:
EDIT 26. Feb 2022:
python3.9.venv
. This has been taken into account here.Motivation
The current Brownie version v1.18.1 won't install (in a virtual environment) on Python 3.10.2 (Win 10). This causes problems when testing for reverted transactions. More on that here:
https://stackoverflow.com/questions/71126128/brownie-testing-for-reverted-transactions-does-not-work-with-pytest-raises-or
eth-brownie/brownie#1441
Approach to fix this
The latest Brownie version can be installed without issues under 3.9.10. I don't want to downgrade my standard Python so I will create a virtual environment with this specific Python version and install everything in there.
Workflow
The following workflow assumes you have already a running Python version. It is written for Windows but can be easily adapted for Mac. All command line stuff I am doing in Powershell. The setup is my personal preference, there are many ways to organize your code and this is just an example.
Install some of the Visual C++ build tools (if you haven't already)
Download and install https://visualstudio.microsoft.com/visual-cpp-build-tools/

Select only the module ticked off in the screenshot (German system) and continue with the installation.
Prepare your Python version and install virtualenv
In my home directory, I already have a directory called
pythonversions
. To create one simply do ...Download the Python version you need, e.g. Python 3.9.10. I downloaded the MSI Installer 64bit
Install the Python as "custom installation". Since I don't want this to become my standard python version I deselected "add to Path" and all other optional features besides pip before proceeding. I will need pip. During the installation process, I create a directory within
pythonversions
named after the version number, in my case 3.9.10. This step unpacks Python into pythonversions/3.9.10With my main Python version I install
virtualenv
like so:pip install virtualenv
Setup your virtual environment for a specific Python version
Under my home directory, I create a directory that will host all virtual environments.
In PowerShell:
The syntax for creating a virtual environment is the following:
Here is an example.
I used py39bro as a directory name because I want it to be short and I want to see the python version and if it contains brownie. Name it to your liking.
Setup your project with node.js
Since my project works with brownie, I will have to install nodeenv for node JS capabilities in order to install ganache.
For one of the next steps (nodeenv -p) I need to open my Powershell as Admin. I keep the other Powershell window in the background because I will come back to it later. Press WindowsKey >enter "PowerShell" > right-click on Powershell in start menu > select "run as administrator" > confirm > navigate to your project directory.
Activate the virtual environment. This can be done from any directory, not necessarily from your project root.
The following are not my actual command in PowerShell, I just want to illustrate that the TAB key is your friend.
Great your virtual environment is activated. Make sure you are running the correct Python version
breaking change with new nodejs version installed by nodeenv
status 14. Mar 2022:
Now we are at the point that we can install nodeenv, which is needed to set up Ganache. Here however there is now a change, because with the newest nodejs version 17.7.1 the Ganache installation fails. Here is a short excerpt from the error log, a German English gibberish, which is again not very helpful.
The solution is to select the correct nodejs version for the Python virtual environment. In this case, Ganache is compatible with nodejs version 16.14.10.
These are now the steps which allow us to install Ganache after a successful pairing of Nodeenv with the Python virtual environment.
Connect nodeenv with your virtual Python environment (this step needs admin rights).
In case you are preparing your virtual environment for hardhat you want to install (24.02.2022) node LTS (lates stable). Here is what worked for me at this date:
important
nodeenv --list
will list all available nodejs versions.nodeenv --node=16.14.0 -p
Installing the payload
(stuff I actually want to work with) At this point, I can close my elevated Powershell window and return to the normal Powershell.
Install ganache
(py39bro)myProject>npm install -g ganache
Install Cython to avoid Cytoolz error
(py39bro)myProject>pip install Cython
Install brownie
(py39bro)myProject>pip install eth-brownie
Now comes the moment of truth. I did all this to get to the newest brownie version, which failed installation on Python 3.10.2. with
ERROR: Could not find a version that satisfies the requirement vyper==0.3.1 (from eth-brownie)
Hurray, I finally installed Brownie v1.18.1 ... And yes, brownie introduced the error "INFO: Could not find files for the given pattern(s)." which will accompany me from now on without any impact besides creating a slight annoyance.
Just to finish this preparation I will
Configure VSCode to use the virtual environment
In VSCode open settings with

Ctrl+,
Into the search box type: python environment and set your venv folders, here an example:
Disclaimer: I am by no means an expert. In fact, I started a few months ago with learning blockchain development. I hope that this post will be obsolete soon and Python, Virtualenv, nodeenv, Cytoolz, Brownie, Vyper and ... will play nicely with each other. Until then, hope this solved your problem too.
Beta Was this translation helpful? Give feedback.
All reactions