• 5

A PHP Error was encountered

Severity: Notice

Message: Undefined index: userid

Filename: views/question.php

Line Number: 191


File: /home/prodcxja/public_html/questions/application/views/question.php
Line: 191
Function: _error_handler

File: /home/prodcxja/public_html/questions/application/controllers/Questions.php
Line: 433
Function: view

File: /home/prodcxja/public_html/questions/index.php
Line: 315
Function: require_once

I am experimenting with Visual Studio Code and so far, it seems great (light, fast, etc).

I am trying to get one of my Python apps running that uses a virtual environment, but also uses libraries that are not in the site-package of my virtual environment.

I know that in settings.json, I can specify a python.pythonPath setting, which I have done and is pointing to a virtual environment.

I also know that I can add additional paths to python.autoComplete.extraPaths, where thus far I am adding the external libraries. The problem is, when I am debugging, it's failing because it's not finding the libraries specified in python.autoComplete.extraPaths.

Is there another setting that must be used for this?


      • 1
    • @jbasko, yes, i think i read everything out there. They all indicate only that the python.pythonPath takes a single value that points to the python interpreter. In eclipse for example, you can add external source folders. But not sure how to do that for vs code.
    • Doesn't sound like you've read. So you have "pythonPath":"${config.python.pythonPath}", in your launch.json?
    • I have it set to the path of my virtual environment's python interpreter in all the files (settings, launch and task.json). What you are reading states that if it is in the settings.json, it will be picked up if the setting is as you state in launch.json. That's fine, but not my issue. My issue as adding multiple paths (paths to external libraries) to the python path. Much like you can do in Eclipse and other editors.
    • Here is a super hacky workaround until it is actually solved, add this to the top of your first python file: import sys; sys.path.append('/path/to/my/pylib')

This worked for me:-

in your launch.json profile entry, specify a new entry called "env", and set PYTHONPATH yourself.

"configurations": [
        "name": "Python",
        "type": "python",
        "stopOnEntry": false,
        "request": "launch",
        "pythonPath": "${config.python.pythonPath}",
        "program": "${file}",
        "cwd": "${workspaceRoot}",
        "debugOptions": [
        "env": {
            "PYTHONPATH": "/path/a:path/b"
  • 30
Reply Report

The Python Extension in VS Code has a setting for python.envFile which specifies the path to a file containing environment variable definitions. By default it is set to:

"python.envFile": "${workspaceFolder}/.env"

So to add your external libraries to the path, create a file named .env in your workspace folder and add the below line to it if you are using Windows:


The advantage of specifying the path here is that both the auto-complete as well as debugging work with this one setting itself. You may need to close and re-open VS Code for the settings to take effect.

  • 23
Reply Report
      • 2
    • Info: this worked for me with a VSCode attached to a running container; If someone find this usefull: "python.pythonPath": "/usr/bin/python" & .env -> PYTHONPATH="/usr/src/my-project/a;/usr/src/my-project/b"
      • 1
    • This is the best way. .env files are commonly used in more applications (and languages) than VS Code. The .env file can travel with the source code and still be recognized by other engines/IDEs, where the settings.json file is specific to VS Code.
    • This still works in 2019. I add that if you are using pipenv, you have to set the path to the /User/.virtualenvs/{$projectname} in order to have the corrent environment with the installed libraries

bash escamotage (works with debugger AND autocomplete); need to install code command in PATH (vsc shell command: install...)


# vscode python setup

function fvscode {
  # you just want one of this:
  export PYTHONPATH=<your python installation ../bin/python3>
  # you may want many of these:
  export PYTHONPATH=<your lib dir here>:$PYTHONPATH
  # launch vscode
alias vscode='fvscode'

the launch VSC by typing 'vscode'.

  • 0
Reply Report

According to the environments doc, the places the extension looks for environments include some defaults and also the setting value for python.venvPath in the workspace settings

eg: "python.venvPath": "~/.virtualenvs"

This allows you to find several (eg: virtualenvs) as mentioned:

To select a specific environment, use the Python: Select Interpreter command from the Command Palette

  • 0
Reply Report

Trending Tags