DEV Community

Michael Saparov
Michael Saparov

Posted on

Settings for PowerShell to show the name of virtual environment (pipenv)

  • Open PowerShell.

Open PowerShell with administrator permission.

  • Check PowerShell profile availability:

Check that you have PowerShell profile, run the command:

Test-Path $profile
Enter fullscreen mode Exit fullscreen mode

If you get False, than create profile by running the command:

New-Item -Type File -Force $profile
Enter fullscreen mode Exit fullscreen mode
  • Open the profile in editor:
notepad $profile
Enter fullscreen mode Exit fullscreen mode
  • Add the code to the profile file:
function prompt {
        # Check,  if virtual environment is activated by using  pipenv shell
        if ($env:PIPENV_ACTIVE) {
            Write-Host "(pipenv) " -NoNewline -ForegroundColor Cyan
        }
        # Check,  if virtual environment is activated by using  venv
        elseif ($env:VENV_PROMPT -eq "activated") {
            Write-Host "(venv) " -NoNewline -ForegroundColor Cyan
        }

        "PS $($executionContext.SessionState.Path.CurrentLocation)$('>' * ($nestedPromptLevel + 1)) "
    }
Enter fullscreen mode Exit fullscreen mode
  • To change the current value of the PowerShell script launch policy, the Set-ExecutionPolicy cmdlet is used. For example, let's allow local scripts to run:
Set-ExecutionPolicy RemoteSigned
Enter fullscreen mode Exit fullscreen mode
  • For further use, restart the terminal
  • Result: Image description

Top comments (0)