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

"workon" command has no effect after second call #25

Open
zeroxia opened this issue Jun 27, 2021 · 4 comments
Open

"workon" command has no effect after second call #25

zeroxia opened this issue Jun 27, 2021 · 4 comments

Comments

@zeroxia
Copy link

zeroxia commented Jun 27, 2021

my system: windows 10:

> [System.Environment]::OSVersion.Version

Major  Minor  Build  Revision
-----  -----  -----  --------
10     0      19041  0

powershell version: Version : 5.1.19041.1023

I use pyenv-win to install: 3.8.10

And put the "VirtualEnvWrapper.psm1" at: "$mydocuments\WindowsPowerShell\Modules".
Added these to Profile.ps1:

$PowerShellPath = Split-Path $PROFILE.CurrentUserAllHosts
Import-Module $PowerShellPath\Modules\VirtualEnvWrapper.psm1

Restarted powershell, execute mkvirtualenv t1, I can enter (t1) virtualenv.
then execute deactivate, virtualenv is deactivated, all is good.

Then I type workon t1 again, prompt does not have (t1) prefix, and the python command is still the global one, at this point, if I execute deactivate, this is reported as not recognized.

I have to edit the VirtualEnvWrapper.psm1:
In the function function Workon, change this line:

    Import-Module $activate_path

To this:

    & $activate_path

Now everything works, I can workon t1, deactivate, workon t1, all is good.

Just don't know the root cause, I'm completely noob with powershell.

@nyambol
Copy link

nyambol commented Jun 29, 2021

Having to use the call operator suggests that a change of scope has occurred. What directory is your 'Envs' directory stored in?

I'm getting different behavior for PS 7 and PS 5 depending on whether I invoke them in Windows Terminal or standalone. Location of 'Envs' is one of them.

@zeroxia
Copy link
Author

zeroxia commented Jul 9, 2021

I did not put any explicit environment to change the "Envs", it's at: $env:USERPROFILE/Envs
But I do have a "HOME" env var globally, which points to a subdirectory of $env:USERPROFILE, and in powershell, there is a $home variable pointing to $env:USERPROFILE, not sure if this can be the root cause.

@regisf
Copy link
Owner

regisf commented Jul 31, 2021

Hi @zeroxia
I will check this issue tomorrow morning.
Regards

@Gregor1337
Copy link

you can also just use the same activation as in mkvirtualenv at line 103ff:

  $VEnvScritpsPath = Join-Path $NewEnv "Scripts"
  $ActivatepPath = Join-Path $VEnvScritpsPath "activate.ps1"
  . $ActivatepPath

The Import-Module fct only executes once per shell session apparently.

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