'Use external packages in eth-brownie?
I am trying open a ERC721 smart contract in Brownie on VSCode and loop through the token ids and set the URI of each in each iteration. I execute the script with brownie run scripts/parcel_asset/testpyodbc.py
. I am trying to use an ODBC driver named pyodbc to query an Access database and create a cursor to iterate. It works fine when running as just a python script but Brownie gives a error ModuleNotFoundError: No module named 'pyodbc'
. Is there a way to his odbc with Brownie?
Below is the error I get
\nft> brownie run scripts/parcel_asset/testpyodbc.py
Brownie v1.17.2 - Python development framework for Ethereum
File ".\scripts\parcel_asset\testpyodbc.py", line 1, in <module>
import pyodbc
ModuleNotFoundError: No module named 'pyodbc'
Terminating local RPC client...
PS C:\Users\philk\Dropbox\smartCity\nft\OrlandoMagicOrange\nft> brownie run scripts/parcel_asset/testpyodbc.py
INFO: Could not find files for the given pattern(s).
Brownie v1.17.2 - Python development framework for Ethereum
NftProject is the active project.
import pyodbc
ModuleNotFoundError: No module named 'pyodbc'
Terminating local RPC client...
Solution 1:[1]
I found this on a Discord channel: brownie is installed to its own virtual environment, if you want other packages to work you have to "inject" them into the brownie virtualenv: When using brownie I can't use external modules, pip install doesn't work brownie but full disclosure, i tried this for another package i was working with to no avail.
pipx inject eth-brownie pyodbc
This fixed the problem
Solution 2:[2]
If you installed brownie with pipx
, you'll need to inject
outside packages into your project.
So instead of
pip install matplotlib
It would be
pipx inject eth-brownie matplotlib
pipx
installs packages into a siloed virtual environment, so you have to install into that the brownie virtual environment to use other packages.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Patrick Collins |
Solution 2 | Patrick Collins |