Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Activating venv in PowerShell opens venv in CLI #26

Open
Stonemuzzle opened this issue Apr 1, 2024 · 3 comments
Open

Activating venv in PowerShell opens venv in CLI #26

Stonemuzzle opened this issue Apr 1, 2024 · 3 comments

Comments

@Stonemuzzle
Copy link

When running pyenv-venv activate in a PowerShell session in Windows Terminal, the activated venv uses Windows CLI instead of PowerShell.

The pyenv-win-venv.ps1 script uses $MyInvocation.MyCommand.CommandType -eq "ExternalScript" to determine whether to use the activate.bat or the Activate.ps1 file to activate the venv. This always evaluates to "ExternalScript" since the pyenv-venv command is triggering the script, from which the command is then run.

I resolved locally by changing the check in the pyenv-win-venv.ps1 file to:

if ($PSVersionTable) {
    $invokedShell = "ps1"
} else {
    $invokedShell = "bat"

Environment:

  • Windows 11 Home
  • Windows Terminal, PowerShell session. I checked PowerShell ISE to determine if an issue with Windows Terminal and found that the original code hangs until cancelled on my system but my updated code successfully activates the venv so the ISE failure when using the repo code may just be local issue.
  • Python version 3.13.0a2
  • pyenv-win and pyenv-win-venv installed using PowerShell on 2024/04/01, so whatever versions were pulled as latest on that day with the install scripts; sorry, can't find version info for them specifically to verify.
@nayjsilva
Copy link

Encountered the same issue, the fix above did the trick.

@awonglk
Copy link

awonglk commented Aug 29, 2024

Same issue.
Is there any plans to fix this permanently?

@kiber-io
Copy link

kiber-io commented Nov 1, 2024

I couldn't solve the problem in the proposed way - it was always defined as ps1.
изображение

My way of solving:

# Auto-detect the shell
if ($MyInvocation.PSScriptRoot) {
    $invokedShell = "ps1"
} else {
    $invokedShell = "bat"
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants