Home > Back-end >  VS Studio Code not detecting modules installed in conda environment
VS Studio Code not detecting modules installed in conda environment

Time:07-27

I created a new environment through anaconda prompt. Next I used "conda activate <env_name>". After that I installed my needed packages and modules using "conda install module_name" in anaconda prompt.

I open my VS Studio and select the interpreter. I have no problems finding the venvs made with conda. enter image description here

I select it and then I open my terminal (in vs code, by default its command prompt) and it looks like this:

 C:\Users\<filepath to the folder with the jupyter notebook> >C:/Users/X/Anaconda3/Scripts/activate

(base) C:\Users\<filepath to the folder with the jupyter notebook> >conda activate classification_train

(classification_train) C:\Users\<filepath to the folder with the jupyter notebook> >

"classification_train" is my env made with conda.

The problem is when I try to import my modules, I get this error:

ModuleNotFoundError: No module named 'pandas'

Now pandas is actually the first import, I am sure the rest of modules will get the same errors. enter image description here

My JSON settings are these (I know most are irrelevant to this case but here we go):

{
"workbench.colorTheme": "Default Dark ",
"python.linting.pylintEnabled": false,
"python.linting.enabled": true,
"python.defaultInterpreterPath": "C:\\Users\\X\\AppData\\Local\\Programs\\Python\\Python310\\python.exe",
"python.linting.flake8Enabled": true,
"[python]": {
    "editor.defaultFormatter": "ms-python.python"
},
"editor.formatOnSave": true,
"terminal.integrated.defaultProfile.windows": "Command Prompt",

}

I reinstalled Anaconda and added to PATH. I have tried activating the venv through anaconda prompt and then using "code" to open vs studio from prompt. And my modules are installed. I checked with "conda list" in the command prompt in vs studio and in anaconda prompt. Everything is there. This just makes no sense for me. What can be done?

CodePudding user response:

You might notice that libraries such as "os", "time" and "datetime" will not give you an error, because they exist in your conda environment by default.

Try to install the libraries to your conda environment using the following syntax (for pandas):

    conda install pandas

You may additionally specify the version you want to install. You will have to do this for all of the libraries that you want to use.

CodePudding user response:

So the issue was the python version selected in VS Code was not the same as the python version selected in the conda environment. Thx all for help.

  • Related