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.

Python: Create Terminal Doesn't Use Activate.ps1 in Powershell

See original GitHub issue

Environment data

  • VS Code version: 1.37
  • Extension version (available under the Extensions sidebar): 2019.8.29288
  • OS and version: Windows 10 1903
  • Python version (& distribution if applicable, e.g. Anaconda): Python 3.7.3 64-bit
  • Type of virtual environment used (N/A | venv | virtualenv | conda | …): venv
  • Relevant/affected Python packages and their versions: N/A
  • Jedi or Language Server? (i.e. what is "python.jediEnabled" set to; more info #3977): Jedi

Expected behaviour

Running the Python: Create Terminal command should properly activate my terminal using Activate.ps1

I expect to see this

Windows PowerShell
Copyright (C) Microsoft Corporation. All rights reserved.

Try the new cross-platform PowerShell https://aka.ms/pscore6

Loading personal and system profiles took 1881ms.
D:\MyProject [master ≡ +1 ~7 -0 !]> d:/MyProject/venv/Scripts/Activate.ps1
D:\MyProject [master ≡ +1 ~7 -0 !]>

Actual behaviour

The command activates my terminal with activate.bat

This is what I see

Windows PowerShell
Copyright (C) Microsoft Corporation. All rights reserved.

Try the new cross-platform PowerShell https://aka.ms/pscore6

Loading personal and system profiles took 1881ms.
D:\MyProject [master ≡ +1 ~7 -0 !]> d:/MyProject/venv/Scripts/activate.bat
D:\MyProject [master ≡ +1 ~7 -0 !]>

Steps to reproduce:

  1. Run the Python: Create Terminal command.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:4
  • Comments:10

github_iconTop GitHub Comments

2reactions
PhilMacKaycommented, Sep 3, 2019

Hello! I did some digging tonight with the code pulled from github. The issue seems to be related to the shellDetector that works based on the name of the terminal. If it doesn’t have a match, it returns the value “other”, which is then considered a success on line 57 of the same file.

By changing the test condition from if (shell) { to if (shell && shell !== 'other') {, the detection is considered failed and the next detectors can be used. It leads to a correct detection of the shell type, therefore the correct “activate” script is used.

I don’t know if the test condition in the identifyTerminalShell needs to be modified, or if it’s the shell detector itself that should return undefined instead of the value “other”…

Anyways, I hope this helps! I would make a pull request but my modification actually breaks two unit tests: Interpreters Known Paths Ensure known list of paths are returned on non-windows Ensure PATH variable and known list of paths are merged on non-windows

Thanks for the help!

1reaction
PhilMacKaycommented, Aug 12, 2019

Hi! I confirm I have the same issue, but with small differences in the environment: Environment data

  • VS Code version: 1.36.1
  • Extension version (available under the Extensions sidebar): 2019.8.29288
  • OS and version: Windows 10 Pro 1903
  • Python version (& distribution if applicable, e.g. Anaconda): Python 3.7.3 64-bit
  • Type of virtual environment used (N/A | venv | virtualenv | conda | …): venv
  • Relevant/affected Python packages and their versions: N/A
  • Jedi or Language Server? (i.e. what is “python.jediEnabled” set to; more info #3977): affects both

It affects Powershell Core 6 as well as Powershell. One possible workaround is to switch default shell to cmd, but I prefer the flexibility of Powershell. The other option is to stay on version 2019.6.24221, which is not affected by this bug.

Read more comments on GitHub >

github_iconTop Results From Across the Web

VS code terminal : Activate.ps1 cannot be loaded because ...
A way is changing the terminal in VSCode to Command Prompt instead of PowerShell. Open the drop-down on the right of the terminal...
Read more >
PowerShell prompt doesn't show virtualenv : PY-22469
There's a workaround for this issue. Under Settings > Tools > Terminal you can uncheck the Activate virtualenv option and then set the...
Read more >
Windows error: "activate.ps1 cannot be loaded because ...
This newly created VS Code Terminal will be using Command Prompt (similar to what you would see if you opened a Command Prompt...
Read more >
Cannot activate - Python - The freeCodeCamp Forum
I created a virtualenv for python, and I am trying to activate it with ... On Windows using PowerShell: path\to\venv\Scripts\Activate.ps1.
Read more >
Terminal Shell Integration in Visual Studio Code
By default, the shell integration script should automatically activate on supported shells launched from VS Code. This is done by injecting arguments and/or ......
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