Import "brownie" could not be resolved in Pylance
Asked Answered
S

6

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!

Submicroscopic answered 31/12, 2021 at 17:8 Comment(7)
will this answer #69928308 helpNumeration
@Numeration 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.Submicroscopic
what is your operating system. find where it is installedNumeration
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.Submicroscopic
maybe restart the vs codeNumeration
@Numeration tried that too!Submicroscopic
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 confifgurationNumeration
C
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.
Citizenry answered 17/1, 2022 at 10:28 Comment(1)
The same is a solution for the issue also when using virtualenv (using the specific path, depending where you have placed the virtualenv).Seducer
A
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

Alkahest answered 11/1, 2022 at 4:11 Comment(2)
Hey Patrick, thanks for responding to this! Got it, I'll just ignore it for now then.Submicroscopic
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.Seducer
I
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

Inappropriate answered 11/4, 2022 at 20:46 Comment(2)
This is a copy of @Ali Sıtkı Aslantaş's answer 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.Letterhead
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 timeInappropriate
I
1

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

pip install brownie
Ir answered 7/7, 2022 at 12:36 Comment(0)
B
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.

Blackleg answered 4/1, 2023 at 9:6 Comment(0)
P
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.

Peyton answered 18/2, 2023 at 18:20 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.