skip to Main Content

I installed snowflake-connector-python in my virtual environment recently using pip install snowflake-connector-python[pandas]==2.7.6, and it works ok when I run my script from the command line with the virtual environment activated. I set the same virtual environment as VSC interpreter, but trying to run python debugger raises an exeception:

ModuleNotFoundError: No module named 'snowflake.connector'

I also can see that pylance doesn’t recognize the package either, but all other installed packages are recognized with no problem.

I have seen several questions and answers for similar cases, but none of them have worked for me.

EDIT

I added the parameter python to the launch.json:

{
    // Use IntelliSense to learn about possible attributes.
    // Hover to view descriptions of existing attributes.
    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Python: Current File",
            "type": "python",
            "python": "${workspaceFolder}/MyVenv/Scripts/python",
            "request": "launch",
            "program": "${file}",
            "console": "integratedTerminal",
            "args": [
                "--env", "dev",
                "--argument"
            ],
            "envFile": "${workspaceFolder}/.env",
        }
    ]
}

Getting the same result.

EDIT

I found that the way the module is imported makes pylance to recognize it, but debugger is still raising the error.

This is the old and new way of importing the module into the code:

Old way

enter image description here

New way

enter image description here

With the new way, code is not highlighted by pylance, but it is not colored as recognized, though.

4

Answers


  1. Chosen as BEST ANSWER

    The problem was finally solved by doing this:

    1. Delete the python virtual environment.
    2. Create the python virtual environment again.
    3. Activate the new python virtual enviroment.
    4. Installing all libraries again with python -m pip install -r requirements.txt

  2. Usually, when your module can’t be found, your environment hasn’t been activated.

    You can try adding the following code to your settings.json after choosing the python interpreter:

    "python.terminal.activateEnvironment": true
    
    Login or Signup to reply.
  3. I had a similar issue with VSCode as well. What I did is uninstalled the Python extension, reinstalled it and then installed Create Blank Python Module extension (all from Visual Studio Marketplace, of course)

    Hope this helps

    Login or Signup to reply.
  4. I had this problem on mac, it was caused by the interpreter in the vs code Python settings being set to the string "python" instead of the string "python3" (on my system running "python" gives an unknown command error)

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search