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.

Conda environment Python is not used when starting VS Code from the terminal

See original GitHub issue

VS Code version

1.62.0

Extension version

2021.11

OS type

macOS

OS version

11.6.1

Python distribution

Anaconda

Python version

3.9.6

Language server

Pylance

Expected behaviour

When I start VS Code from the macOS terminal using the code command, I expect the integrated VS Code terminal to use the default conda environment. For example, when I open a folder from within VS Code (using File -> Open… from the menu), it opens the selected folder of Python files. I select a Python file to edit it and VS Code selects my default conda environment which is named base. When I open the integrated VS Code terminal, it uses the base conda environment and the associated Python. A screen capture of this process is shown below.

mLVBy

Actual behaviour

When I start VS Code from the macOS terminal using the code command, the integrated VS Code terminal does not use the default conda environment’s Python. The integrated terminal uses the system Python and packages.

Steps to reproduce

From within the Mac terminal, I cd to the folder containing the Python files. From within the directory, I open VS Code using the code . terminal command. I select a Python file to edit and VS Code selects my default conda environment which is named base. When I open the integrated VS Code terminal, it says I’m using the base conda environment. However, the integrated VS Code terminal is not using the conda environment Python and packages. A screen capture of this is shown below.

aAJHb

Logs

No response

Code of Conduct

  • I agree to follow this project’s Code of Conduct

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:2
  • Comments:8 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
gonghenghaicommented, Nov 9, 2021

@karthiknadig Sorry, but I think you have misunderstood him. He does not mean after he has selected a python interpreter in the system terminal then enter into the VSCode, the python interpreter activated in the system terminal should be inherited by the VSCode.

What has occurred is, he entered into the VSCode through the system terminal with the command of code ., no matter what environment has activated in the system terminal, the VSCode can not select the conda base environment, even the bottom-left prompted he has selected the conda base environment, even he select the python interpreter manually, even he activate the environment manually, even he create a new terminal, even he has opened the folder and selected the conda base in the past and reopen it again, nothing works. He just can not get the conda base environment when he entered into VSCode through code . command.

What a weird thing, just beyond my imagination. This is the link on StackOverflow

Capture

0reactions
karthiknadigcommented, Mar 17, 2022
Read more comments on GitHub >

github_iconTop Results From Across the Web

Visual Studio Code terminal doesn't activate Conda environment
Go to the menu bar and click on Terminal. Type: conda init; Close this terminal and open a new one; In the new...
Read more >
Using Python environments in VS Code
Conda environments can't be automatically activated in the VS Code Integrated Terminal if the default shell is set to PowerShell. To change the...
Read more >
Efficient Way to Activate Conda in VSCode - Medium
Option 2: Run “conda activate <env-name>” in terminal · CTRL+SHIFT+P open “Preference: Open User Settings (JSON)”. We choose User settings instead of Workspace ......
Read more >
Setting up Environments
Type interpreter in the search box. And select the Python: Select Interpreter option. You should see a list of all the available (both...
Read more >
Advanced Visual Studio Code for Python Developers
Setting Up Your Terminal. You'll spend much of your Python development time inside a shell terminal. You can use a separate application, like...
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