question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Auto-select python from the activated environment

See original GitHub issue

Environment data

  • VS Code version: 1.51.1
  • Extension version (available under the Extensions sidebar): (what is that? not finding)
  • OS and version: Windows 10 1909 (18363.1198)
  • Python version (& distribution if applicable, e.g. Anaconda): 3.7.8 (Anaconda)
  • Type of virtual environment used (N/A | venv | virtualenv | conda | …): conda
  • Relevant/affected Python packages and their versions: PySide2==5.15.2, sip==5.5.0
  • Relevant/affected Python-related VS Code extensions and their versions: Anaconda Extension Pack==v1.0.1, Python==v2020.11.371526539, Qt for Python==v0.5.3
  • Value of the python.languageServer setting: Jedi

[NOTE: If you suspect that your issue is related to the Microsoft Python Language Server (python.languageServer: 'Microsoft'), please download our new language server Pylance from the VS Code marketplace to see if that fixes your issue]

Expected behaviour

well i expected it to import PySide2, but it failed.

Actual behaviour

When running the python script with the automatically generated launch.json

Traceback (most recent call last):
  File "e:\Python\myenv\src\main.py", line 16, in <module>
    from draw import draw_window
  File "e:\Python\myenv\src\draw.py", line 13, in <module>
    from PySide2 import QtCore, QtGui, QtWidgets
ModuleNotFoundError: No module named 'PySide2'

Steps to reproduce:

[NOTE: Self-contained, minimal reproducing code samples are extremely helpful and will expedite addressing your issue]

  1. Create a file (say, main.py)

  2. Input only one single line: import PySide2

  3. Save and change to the virtual env, run with the debugger provided by Python extension

  4. You’ll see the ModuleNotFoundError: No module named 'PySide2'

  5. Running python main.py doesn’t raise this error

  6. Running import PySide2 in python interactivate mode doesn’t raise this error

  7. I’m pretty sure that I DID pip install PySide2 in my virtual env, and pip show PySide2 DOESN’T raise WARNING: Package(s) not found, so i suspect it a problem has something to do with the extension.

Logs

I post the output of pip freeze of my env here:

certifi==2020.12.5
packaging==20.7
pyparsing==2.4.7
PyQt5==5.15.2
PyQt5-sip==12.8.1
PySide2==5.15.2
pywin32==225
shiboken2==5.15.2
sip==5.5.0
toml==0.10.2
wincertstore==0.2

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:2
  • Comments:12 (6 by maintainers)

github_iconTop GitHub Comments

2reactions
karthiknadigcommented, Dec 11, 2020

Yes. The extension should be able to select the python based on activated environment or CONDA_PREFIX.

We have marked this issue as “needs decision” to make sure we have a conversation about your idea. We plan to leave this feature request open for at least a month to see how many 👍 votes the opening comment gets to help us make our decision.

0reactions
karrtikrcommented, Dec 14, 2022
Read more comments on GitHub >

github_iconTop Results From Across the Web

Auto activate virtual environment in Visual Studio Code
Enter Ctrl + Shift + P in your vs code. Locate your Virtual Environment: Python: select interpreter > Enter interpreter path > Find....
Read more >
Using Python environments in VS Code
To select a specific environment, use the Python: Select Interpreter command from the Command Palette (Ctrl+Shift+P).
Read more >
Autocomplete | Python in Visual Studio Code
The path to the custom modules is set when a virtual environment is activated. Solution: Launch VS Code from a Terminal/Command window with...
Read more >
venv — Creation of virtual environments — Python 3.11.1 ...
You don't specifically need to activate a virtual environment, as you can just specify the full path to that environment's Python interpreter when...
Read more >
VS Code Setup with Python Virtual Environments - YouTube
Installed VS Code to PATH, installing the python extension, and handling virtual environments from within Visual Studio Code.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found