Python modules librarys packages load problems on IDEs Visual Code

Hello, Im using pip to download packages but that dependencies only works when I try from the CLI

Type "help", "copyright", "credits" or "license" for more information.
>>> import mysql.connector
>>> 

But when I try from Visual Code it does not work.

I already tried this matter of selecting the correct interpreter, I also tried creating virtual env and selecting the binary inside it and nothing. I try from Eclipse IDE too and is the same problem.

Import "mysql.connector" could not be resolvedPylancereportMissingImports

Any suggestion?

1 Like

dnf list installed python3* | grep -i mysql

Installing python packages with pip as root can easily corrupt your installation since pip does not understand nor respect the package installed files and may overwrite them. Using pip should always be done as user (not using su or sudo) or in a venv.

You also should be aware that that image shows python 3.10 and F37 is on python 3.11.

In a venv you can set a python 3.10 environment to support VS

1 Like

Thanks in advance for your time.

After trying many times as a normal user and not being able to solve it then try as root :confused: but so far I haven’t seen any strange behavior after that.

No output.

Yes! I could notice this! But but I didn’t quite understand, what should I do here?

1 Like

I have not used VS code so cannot immediately answer. I do have it installed.
Maybe if I had your exact code modules for what you are developing I could test but without that I would only be guessing.

My earlier comments are about what may happen, not what will happen in every case.

Having upgraded my system from F34 to F36 then F37 I have the older 3.10 python installed as well as 3.11.

My visual studio code as installed shows this in the help-about tab

Version: 1.74.2
Commit: e8a3071ea4344d9d48ef8a4df2c097372b0c5161
Date: 2022-12-20T10:27:19.253Z
Electron: 19.1.8
Chromium: 102.0.5005.167
Node.js: 16.14.2
V8: 10.2.154.15-electron.0
OS: Linux x64 6.0.15-300.fc37.x86_64
Sandboxed: No

and was updated just a week ago.

1 Like

VSCode says it is running Python from the python-virtualenv venv. Are you running from the same venv in the CLI? Did you install using pip from that venv?

And dnf is irrelevant here since VSCode is not using system packages.

1 Like

I’m with the same problem of Elliott but I have the last version of python and VS Code installed.

Sorry, I started this post and I was away for several days, my wife came on vacation and among other things anyway…

I’ve been there for several days within what time has allowed me and I discovered several things that solved my problem with both Eclipse and VSCode:

With Eclipse:
After you install PyDev the first thing you need to do is go to Windows-Preferences-Interpreters-Python Interpreters and select the python interpreter.

What is the problem here?

If you select Choose from list

he will show you the default python binaries:

After selecting one of them automatically he select the main libraries

Acepting this configuration we find a problem, the problem occur when we start downloading packages using pip command WITHOUT sudo bc is not recomendable, so when we download any package example:
pip install mysql-connector

He will install that packages under your home directory:
/home/isudovm/.local/lib/python3.11/site-packages

If you notice the previous full path name was /usr/bin/python3.10 and this one is /home/isudovm/.local/lib/python3.11/site-packages and it won’t work when you run your code.

Solution:
Select New-Browse for python/pypy and manually select /usr/bin/python3.11

Select proceed anyways after selecting /usr/bin/python3.11

And tha’s it. Works for me!

With VSCode:

You need to create first a venv if you dont know what is, google it.
After making some test I realize that when I create this venv from my terminal I dont know why didnt work, but when I create the venv using the VSCode directly then works.

9aed3f3fb19369b594eecb2d585f9e692a256092.png

After create the venv using VSCode activate the venv from the VSCode terminal and then use pip command to download the package you need and for me worked!

If any have any doubt please let me know.

1 Like

Hope that your wife get well as soon as possible!

About the problem, I found this:
https://github.com/microsoft/vscode-python/issues/20253

I’m thinking in using another IDE.