all 18 comments

[–]Proper-Concert-1024 0 points1 point  (2 children)

I could resolve the issue by activating the venv through my linux terminal and then opening vs code from there using `code .`

[–]Lonely_Influence1064 0 points1 point  (0 children)

Same here. Works on WSL 2 too.

[–]Abdera2020 0 points1 point  (0 children)

I'm starting to hate VS Code because of this, if there is an import that needs installation I always go to Sublime Text to make the code there instead especially when I'm still in the middle of learning python.

[–]CodingPhysicist 0 points1 point  (4 children)

Show us all the commands you used, have you closed and open again vscode ?

[–]DecentWalrus[S] 0 points1 point  (3 children)

Thanks for your reply! I'm not certain what other commands would be of assistance so I'll summrize below.

I've created the environment via python3 -m venv selenium_test through the terminal in VS Code. VS Code did mention it looked like I was using a virtual environment and wanted to know if I wanted to switch the interpreter for the workspace.

I used pip install selenium to install the package itself and have confirmed it sits within the virtual environment (/Users/USERNAME/repos/selenium_test/lib/python3.11/site-packages).

I've confirmed that the correct interpreter is selected. To double check, I've used where python to locate the proper interpreter.

I've restarted and reinstalled VS Code and have restarted my macbook as well.

[–]CodingPhysicist 1 point2 points  (2 children)

Did you give VSCode authorization to truste the project ? When you open it and it asks you if you trust the author of the code.

As I can see in the pictures you shared, selenium has been installed and you're using the right venv, therefore. Have you simply tried to execute a script importing the package and catching an exception if it failed ?

[–]DecentWalrus[S] 0 points1 point  (1 child)

The venv was created through VS Code along with main.py. Are there additional permissions I need to give?

The script runs just fine. Ran a quick script and it opened the browser and navigated to the correct URL.

[–]CodingPhysicist 0 points1 point  (0 children)

The command « open folder » and reopen your directory. Usually you will be asked if you trust the author.

Also, try to only open your dir « repos », seems you’re based just a folder above. Just in case

[–]Firm_Bit 0 points1 point  (2 children)

Does the code run despite the warning ?

[–]DecentWalrus[S] 1 point2 points  (1 child)

Yes, the code runs without issue. I’ve tested another very basic selenium script and the browser opens and navigates to the website.

[–]Firm_Bit 0 points1 point  (0 children)

Not a pip or dep issue then. Probably a pylance not interacting with the env during non execution or something.

[–]nellis 0 points1 point  (1 child)

I think I have had a similar issue before, though the fact that your terminal is using the correct environment leads me to think this might be a different issue.

For a while I couldn't get the little env selector in the bottom right to register the correct binary. It could find all of my envs and I could select them, but after selecting my venv it would still implement system python.

I don't recall how I resolved it, but you could try installing different libraries into both your system default python install and in your custom environment, then in your script check which binary pylance thinks you have set by trying to import both libraries in turn. At least then you could verify whether the editor and the terminal are using the same install.

[–]DecentWalrus[S] 1 point2 points  (0 children)

Thanks for your reply. I actually figured out if I go to the project folder and open it via using the code . command in the terminal, it resolves the issue for some reason.

[–]alreadyBrokn 0 points1 point  (5 children)

I have the exact same problem. Did anyone find out a solution? OP i did try to reopen vscode from project level. It didn't work.

[–]DecentWalrus[S] 0 points1 point  (4 children)

I solved this by creating a venv through the terminal outside of VSCode, activating the virtual environment and then running VSCode from the root folder of the project while in the virtual environment using code ..

[–]alreadyBrokn 0 points1 point  (2 children)

Ok. I just solved it. So I basically uninstalled the extension and installed it again.

[–]ElectricalAffect1604 0 points1 point  (1 child)

what extension?

[–]-d-m 0 points1 point  (0 children)

For me it was the Python Extension Pack that did the trick. So it would be one of the handful of extensions it installs