5

Error is: Import "brownie" could not be resolvedPylance

I know there are other SO posts that refer to this, but it seems most of them are talking about booting up a new env and installing x package into that virtual env.

However with Brownie, I'm especially confused because the brownie docs say:

pipx installs Brownie into a virtual environment and makes it available directly from the commandline. Once installed, you will never have to activate a virtual environment prior to using Brownie.

I don't want to mess with the virtual env that brownie uses.

Anyways, my code runs fine and the command line tells me that brownie is installed.It's just that this warning is really annoying me. Can anyone tell me how to clear it up? Thanks!

OneCricketeer
  • 179,855
  • 19
  • 132
  • 245
user12457151
  • 853
  • 2
  • 12
  • 25
  • will this answer https://stackoverflow.com/questions/69927808/python-does-not-find-the-brownie-file/70540493#70540493 help – Yilmaz Dec 31 '21 at 17:33
  • @Yilmaz I took a look, an eth-brownie venv does not show up when I try to select a python interpreter. I tried pasting in the ~/.local/pipx/venvs/eth-brownie/bin/python path but it didn't find anything. – user12457151 Dec 31 '21 at 21:18
  • what is your operating system. find where it is installed – Yilmaz Dec 31 '21 at 21:19
  • I'm on mac os monterey. so interestingly enough ~/.local/pipx/venvs/eth-brownie/bin/python is the right path in my computer. I just selected it again as the interpreter path, this time through a Finder pop up. It didn't fix the issue. – user12457151 Dec 31 '21 at 21:24
  • maybe restart the vs code – Yilmaz Dec 31 '21 at 21:25
  • @Yilmaz tried that too! – user12457151 Dec 31 '21 at 21:40
  • btw make sure you are using vs-code terminal not shell. if you are using shell then u need to add that path to shell confifguration – Yilmaz Jan 01 '22 at 00:16

6 Answers6

10
  1. open command pallete cmd+shift+P (on mac)
  2. type python select
  3. click Python: Select Interpreter
    • Enter interpreter path ~/.local/pipx/venvs/eth-brownie/bin/python
  4. this works for me.
  • The same is a solution for the issue also when using virtualenv (using the specific path, depending where you have placed the virtualenv). – Fanta Jul 24 '22 at 10:15
7

It's happening because we install python with pipx instead of pip. pylance looks in the location our pip files are generally stored, and doesn't see brownie since we installed with pipx (which installed to it's on isolated virtual environment). So you have a few options:

  1. Ignore it
  2. Install brownie with pip in a virtual environment (not recommended)

If there is another suggestion, happy to hear it

Patrick Collins
  • 5,621
  • 3
  • 26
  • 64
  • 3
    Hey Patrick, thanks for responding to this! Got it, I'll just ignore it for now then. – user12457151 Jan 11 '22 at 14:38
  • The same issue happens with virtualenv. Still need to provide the path to the python interpreter (for the virtualenv) as per asnwer below by Ali. – Fanta Jul 24 '22 at 10:14
4

for Windows:

  1. Ctrl+Shift+P
  2. Type python select
  3. click Python: Select Interpreter
  4. Enter interpreter path ~/.local/pipx/venvs/eth-brownie/Scripts/python
  5. You can also click "Find" to search your files for the path if manually inputting it isn't working

This is an addition to @Ali Sıtkı Aslantaş's answer

  • This is a copy of [@Ali Sıtkı Aslantaş's answer](https://stackoverflow.com/a/70739859/3025856) from January, yet it doesn't provide acknowledgement. It does add the fifth list item, but that would better be served as a comment on Ali's answer rather than duplicating their answer to add a minor addition. – Jeremy Caney Apr 16 '22 at 00:51
  • 1
    My apologies. I tried to comment on @Ali Sıtkı Aslantaş's answer, but was prevented from doing so because I'm new to stack overflow. I'll make sure to site my sources next time – Vincent Lam Apr 18 '22 at 02:30
1

I tried below pip command & the warning in my python code got resolved.

pip install brownie
dhanesh24g
  • 344
  • 1
  • 6
1

The answer is probably quiet simple, as for me, each time I have to use different packages, I need to select the right interpreter in order not to get that silly warning.

If you are on Windows (I assume you are using VS code) follow the following steps:

  1. View > Command Palette
  2. Search for "Python: Select Interpreter"
  3. Select "Enter interpreter path..." > "Find..."
  4. Enter this path "C:\Users<< username >>.local\pipx\venvs\eth-brownie\Scripts" (of course swap << username >> with your username)
  5. Select as interpreter the "python.exe" file contained inside of the Scripts folder.

Otherwise, if you are on an Apple device, the Steps to follow should be pretty much the same but at point 4) you need to enter a path that looks similar to the following: ~/.local/pipx/venvs/eth-brownie/bin/python.

So far, this method allowed me to solve any "Import" could not be resolved in Pylance.

Julia Meshcheryakova
  • 3,162
  • 3
  • 22
  • 42
1

The suggested methods seem correct, however, all of them are for Linux/OS, making the answer really confusing for the windows users.

I followed Patrick's tutorial and my path is: C:\Users\korisnik.local\pipx\venvs\eth-brownie\Scripts ^Korisnik Being the name of the account. It's honestly hard to find path if you don't know where to look at.

Eric Aya
  • 69,473
  • 35
  • 181
  • 253