Skip to content

"Go to Definition" in Jedi always prefers the user install, not the virtual environment #1979

Description

@guilim

Environment data

  • VS Code version: 1.24.1
  • Extension version (available under the Extensions sidebar): 2018.5.0
  • OS and version: Ubuntu 14.04
  • Python version: 2.7.6
  • Type of virtual environment used (N/A | venv | virtualenv | conda | ...): virtualenv

Actual behavior

When using the "Go to definition" feature (eg F12) on the name of an imported library, the priority of the lookup seems to be made on libraries installed in ~/.local, even if the library is also installed in the virtual environment configured for the current project.

It seems to be the case only if the lib is installed in ~/.local (ie pip install --user mode).
If the library was not installed in --user mode (ie in something like /usr/local/lib/(...), then the library from the virtualenv is correctly used.

Please note that it does not impact feature Run Python File in Terminal which uses the virtualenv library, as it should.

Expected behavior

The lookup priority of the "Go to definition" feature should be the same as the sys.path of virtualenv's python.
In other terms, it should go to the definition of the lib installed in the virtualenv.

Steps to reproduce:

  1. Create a new project containing one python file, which contains only:
    import pytest
  2. Create a new virtual environment, and install pytest in it:
    virtualenv /tmp/temp_venv
    source /tmp/temp_venv/bin/activate
    pip install pytest
  3. Configure the project settings.json so that it uses the virtualenv
    "python.pythonPath": "/tmp/temp_venv/bin/python"
  4. Go to the project file, and try to go to the definition of pytest in import pytest
    --> /tmp/temp_venv/lib/python2.7/site-packages/pytest.py is opened, which is OK
  5. Install pytest system wide, outside the virtualenv
    sudo pip install pytest
  6. Go to the project file, and try to go to the definition of pytest in import pytest
    --> /tmp/temp_venv/lib/python2.7/site-packages/pytest.py is opened, which is OK
  7. Install pytest in user's home, outside the virtualenv
    pip install pytest --user
  8. Go to the project file, and try to go to the definition of pytest in import pytest
    --> ~/.local/lib/python2.7/site-packages/pytest.py is opened, which is KO

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-editor-*User-facing catch-allarea-intellisenseLSP-related functionality: auto-complete, docstrings, navigation, refactoring, etc.bugIssue identified by VS Code Team member as probable bugverifiedVerification succeeded

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions