Virtualenv: Unable to deactivate virtualenv while using Powershell in Windows Terminal

Created on 27 Mar 2020  ·  6Comments  ·  Source: pypa/virtualenv

Issue

Unable to deactivate the virtual environment while using Powershell in Windows Terminal.

Environment
Windows 10 Pro 10.0.18363
Windows Terminal (Powershell)

console pip 20.0.2 setuptools 46.0.0 wheel 0.34.2

Output of the virtual environment creation

PS D:\projects\ceres> virtualenv . -vvv --with-traceback
56 setup logging to NOTSET [DEBUG report:43]
57 could not create app data folder C:\Users\Spors\AppData\Local\pypa\virtualenv due to FileNotFoundError(2, 'The syste
m cannot find the path specified') [INFO app_data:54]
70 created temporary app data folder C:\Users\Spors\AppData\Local\Temp\tmpbehz5s21 [DEBUG app_data:32]
70 find interpreter for spec PythonSpec(path=c:\program files\python\38\python.exe) [INFO builtin:44]
70 proposed PythonInfo(spec=CPython3.8.1.final.0-64, exe=c:\program files\python\38\python.exe, platform=win32, version
='3.8.1 (tags/v3.8.1:1b293b6, Dec 18 2019, 23:11:46) [MSC v.1916 64 bit (AMD64)]', encoding_fs_io=utf-8-utf-8) [INFO bu
iltin:50]
71 accepted PythonInfo(spec=CPython3.8.1.final.0-64, exe=c:\program files\python\38\python.exe, platform=win32, version
='3.8.1 (tags/v3.8.1:1b293b6, Dec 18 2019, 23:11:46) [MSC v.1916 64 bit (AMD64)]', encoding_fs_io=utf-8-utf-8) [DEBUG b
uiltin:52]
76 symlink on filesystem does not work [DEBUG info:47]
76 filesystem is not case-sensitive [DEBUG info:28]
142 create virtual environment via CPython3Windows(dest=D:\projects\ceres, clear=False, global=False) [INFO session:52]
143 create folder D:\projects\ceres\Lib\site-packages [DEBUG _sync:21]
143 create folder D:\projects\ceres\Scripts [DEBUG _sync:21]
143 write D:\projects\ceres\pyvenv.cfg [DEBUG pyenv_cfg:34]
143     home = c:\program files\python\38 [DEBUG pyenv_cfg:38]
143     implementation = CPython [DEBUG pyenv_cfg:38]
143     version_info = 3.8.1.final.0 [DEBUG pyenv_cfg:38]
143     virtualenv = 20.0.10 [DEBUG pyenv_cfg:38]
144     include-system-site-packages = false [DEBUG pyenv_cfg:38]
144     base-prefix = c:\program files\python\38 [DEBUG pyenv_cfg:38]
144     base-exec-prefix = c:\program files\python\38 [DEBUG pyenv_cfg:38]
144     base-executable = c:\program files\python\38\python.exe [DEBUG pyenv_cfg:38]
144 copy c:\program files\python\38\python.exe to D:\projects\ceres\Scripts\python.exe [DEBUG _sync:48]
146 copy c:\program files\python\38\pythonw.exe to D:\projects\ceres\Scripts\pythonw.exe [DEBUG _sync:48]
147 copy c:\program files\python\38\python3.dll to D:\projects\ceres\Scripts\python3.dll [DEBUG _sync:48]
148 copy c:\program files\python\38\python38.dll to D:\projects\ceres\Scripts\python38.dll [DEBUG _sync:48]
158 copy c:\program files\python\38\vcruntime140.dll to D:\projects\ceres\Scripts\vcruntime140.dll [DEBUG _sync:48]
159 copy c:\program files\python\38\DLLs\libcrypto-1_1.dll to D:\projects\ceres\Scripts\libcrypto-1_1.dll [DEBUG _sync:
48]
167 copy c:\program files\python\38\DLLs\libffi-7.dll to D:\projects\ceres\Scripts\libffi-7.dll [DEBUG _sync:48]
168 copy c:\program files\python\38\DLLs\libssl-1_1.dll to D:\projects\ceres\Scripts\libssl-1_1.dll [DEBUG _sync:48]
171 copy c:\program files\python\38\DLLs\pyexpat.pyd to D:\projects\ceres\Scripts\pyexpat.pyd [DEBUG _sync:48]
172 copy c:\program files\python\38\DLLs\select.pyd to D:\projects\ceres\Scripts\select.pyd [DEBUG _sync:48]
173 copy c:\program files\python\38\DLLs\sqlite3.dll to D:\projects\ceres\Scripts\sqlite3.dll [DEBUG _sync:48]
177 copy c:\program files\python\38\DLLs\tcl86t.dll to D:\projects\ceres\Scripts\tcl86t.dll [DEBUG _sync:48]
179 copy c:\program files\python\38\DLLs\tk86t.dll to D:\projects\ceres\Scripts\tk86t.dll [DEBUG _sync:48]
181 copy c:\program files\python\38\DLLs\unicodedata.pyd to D:\projects\ceres\Scripts\unicodedata.pyd [DEBUG _sync:48]
185 copy c:\program files\python\38\DLLs\winsound.pyd to D:\projects\ceres\Scripts\winsound.pyd [DEBUG _sync:48]
186 copy c:\program files\python\38\DLLs\_asyncio.pyd to D:\projects\ceres\Scripts\_asyncio.pyd [DEBUG _sync:48]
187 copy c:\program files\python\38\DLLs\_bz2.pyd to D:\projects\ceres\Scripts\_bz2.pyd [DEBUG _sync:48]
188 copy c:\program files\python\38\DLLs\_ctypes.pyd to D:\projects\ceres\Scripts\_ctypes.pyd [DEBUG _sync:48]
189 copy c:\program files\python\38\DLLs\_decimal.pyd to D:\projects\ceres\Scripts\_decimal.pyd [DEBUG _sync:48]
190 copy c:\program files\python\38\DLLs\_elementtree.pyd to D:\projects\ceres\Scripts\_elementtree.pyd [DEBUG _sync:48
]
192 copy c:\program files\python\38\DLLs\_hashlib.pyd to D:\projects\ceres\Scripts\_hashlib.pyd [DEBUG _sync:48]
193 copy c:\program files\python\38\DLLs\_lzma.pyd to D:\projects\ceres\Scripts\_lzma.pyd [DEBUG _sync:48]
194 copy c:\program files\python\38\DLLs\_msi.pyd to D:\projects\ceres\Scripts\_msi.pyd [DEBUG _sync:48]
195 copy c:\program files\python\38\DLLs\_multiprocessing.pyd to D:\projects\ceres\Scripts\_multiprocessing.pyd [DEBUG
_sync:48]
196 copy c:\program files\python\38\DLLs\_overlapped.pyd to D:\projects\ceres\Scripts\_overlapped.pyd [DEBUG _sync:48]
197 copy c:\program files\python\38\DLLs\_queue.pyd to D:\projects\ceres\Scripts\_queue.pyd [DEBUG _sync:48]
198 copy c:\program files\python\38\DLLs\_socket.pyd to D:\projects\ceres\Scripts\_socket.pyd [DEBUG _sync:48]
199 copy c:\program files\python\38\DLLs\_sqlite3.pyd to D:\projects\ceres\Scripts\_sqlite3.pyd [DEBUG _sync:48]
200 copy c:\program files\python\38\DLLs\_ssl.pyd to D:\projects\ceres\Scripts\_ssl.pyd [DEBUG _sync:48]
200 copy c:\program files\python\38\DLLs\_tkinter.pyd to D:\projects\ceres\Scripts\_tkinter.pyd [DEBUG _sync:48]
201 create D:\projects\ceres\Lib\site-packages\_virtualenv.py [DEBUG api:60]
203 create virtualenv import hook file D:\projects\ceres\Lib\site-packages\_virtualenv.pth [DEBUG api:63]
203 ============================== target debug ============================== [DEBUG session:54]
203 debug via 'D:\projects\ceres\Scripts\python.exe' 'c:\program files\python\38\lib\site-packages\virtualenv\create\de
bug.py' [DEBUG creator:182]
203 {
  "sys": {
    "executable": "D:\\projects\\ceres\\Scripts\\python.exe",
    "_base_executable": "D:\\projects\\ceres\\Scripts\\python.exe",
    "prefix": "D:\\projects\\ceres",
    "base_prefix": "c:\\program files\\python\\38",
    "real_prefix": null,
    "exec_prefix": "D:\\projects\\ceres",
    "base_exec_prefix": "c:\\program files\\python\\38",
    "path": [
      "D:\\projects\\ceres\\Scripts\\python38.zip",
      "c:\\program files\\python\\38\\DLLs",
      "c:\\program files\\python\\38\\lib",
      "c:\\program files\\python\\38",
      "D:\\projects\\ceres",
      "D:\\projects\\ceres\\lib\\site-packages"
    ],
    "meta_path": [
      "<class '_virtualenv._Finder'>",
      "<class '_frozen_importlib.BuiltinImporter'>",
      "<class '_frozen_importlib.FrozenImporter'>",
      "<class '_frozen_importlib_external.PathFinder'>"
    ],
    "fs_encoding": "utf-8",
    "io_encoding": "cp1252"
  },
  "version": "3.8.1 (tags/v3.8.1:1b293b6, Dec 18 2019, 23:11:46) [MSC v.1916 64 bit (AMD64)]",
  "os": "<module 'os' from 'c:\\\\program files\\\\python\\\\38\\\\lib\\\\os.py'>",
  "site": "<module 'site' from 'c:\\\\program files\\\\python\\\\38\\\\lib\\\\site.py'>",
  "datetime": "<module 'datetime' from 'c:\\\\program files\\\\python\\\\38\\\\lib\\\\datetime.py'>",
  "math": "<module 'math' (built-in)>",
  "json": "<module 'json' from 'c:\\\\program files\\\\python\\\\38\\\\lib\\\\json\\\\__init__.py'>"
} [DEBUG session:55]
295 add seed packages via FromAppData(download=False, pip=latest, setuptools=latest, wheel=latest, via=copy, app_data_d
ir=C:\Users\Spors\AppData\Local\Temp\tmpbehz5s21\seed-app-data\v1) [INFO session:59]
296 Attempting to acquire lock 2491013030048 on C:\Users\Spors\AppData\Local\Temp\tmpbehz5s21\seed-app-data\v1\3.8\whee
ls.lock [DEBUG filelock:270]
296 Lock 2491013030048 acquired on C:\Users\Spors\AppData\Local\Temp\tmpbehz5s21\seed-app-data\v1\3.8\wheels.lock [INFO
 filelock:274]
297 get bundled wheel c:\program files\python\38\lib\site-packages\virtualenv\seed\embed\wheels\pip-20.0.2-py2.py3-none
-any.whl [DEBUG acquire:51]
297 get bundled wheel c:\program files\python\38\lib\site-packages\virtualenv\seed\embed\wheels\setuptools-46.0.0-py3-n
one-any.whl [DEBUG acquire:51]
297 get bundled wheel c:\program files\python\38\lib\site-packages\virtualenv\seed\embed\wheels\wheel-0.34.2-py2.py3-no
ne-any.whl [DEBUG acquire:51]
300 install wheel from wheel C:\Users\Spors\AppData\Local\Temp\tmpbehz5s21\seed-app-data\v1\3.8\wheels\wheel-0.34.2-py2
.py3-none-any.whl via CopyPipInstall [DEBUG via_app_data:46]
300 install setuptools from wheel C:\Users\Spors\AppData\Local\Temp\tmpbehz5s21\seed-app-data\v1\3.8\wheels\setuptools-
46.0.0-py3-none-any.whl via CopyPipInstall [DEBUG via_app_data:46]
300 build install image to C:\Users\Spors\AppData\Local\Temp\tmpbehz5s21\seed-app-data\v1\3.8\image\CopyPipInstall\whee
l-0.34.2-py2.py3-none-any of wheel-0.34.2-py2.py3-none-any.whl [DEBUG base:57]
300 install pip from wheel C:\Users\Spors\AppData\Local\Temp\tmpbehz5s21\seed-app-data\v1\3.8\wheels\pip-20.0.2-py2.py3
-none-any.whl via CopyPipInstall [DEBUG via_app_data:46]
301 build install image to C:\Users\Spors\AppData\Local\Temp\tmpbehz5s21\seed-app-data\v1\3.8\image\CopyPipInstall\setu
ptools-46.0.0-py3-none-any of setuptools-46.0.0-py3-none-any.whl [DEBUG base:57]
301 build install image to C:\Users\Spors\AppData\Local\Temp\tmpbehz5s21\seed-app-data\v1\3.8\image\CopyPipInstall\pip-
20.0.2-py2.py3-none-any of pip-20.0.2-py2.py3-none-any.whl [DEBUG base:57]
334 copy directory C:\Users\Spors\AppData\Local\Temp\tmpbehz5s21\seed-app-data\v1\3.8\image\CopyPipInstall\wheel-0.34.2
-py2.py3-none-any\wheel to D:\projects\ceres\Lib\site-packages\wheel [DEBUG _sync:48]
397 copy C:\Users\Spors\AppData\Local\Temp\tmpbehz5s21\seed-app-data\v1\3.8\image\CopyPipInstall\setuptools-46.0.0-py3-
none-any\easy_install.py to D:\projects\ceres\Lib\site-packages\easy_install.py [DEBUG _sync:48]
402 copy directory C:\Users\Spors\AppData\Local\Temp\tmpbehz5s21\seed-app-data\v1\3.8\image\CopyPipInstall\setuptools-4
6.0.0-py3-none-any\pkg_resources to D:\projects\ceres\Lib\site-packages\pkg_resources [DEBUG _sync:48]
408 copy directory C:\Users\Spors\AppData\Local\Temp\tmpbehz5s21\seed-app-data\v1\3.8\image\CopyPipInstall\wheel-0.34.2
-py2.py3-none-any\wheel-0.34.2.dist-info to D:\projects\ceres\Lib\site-packages\wheel-0.34.2.dist-info [DEBUG _sync:48]
429 copy C:\Users\Spors\AppData\Local\Temp\tmpbehz5s21\seed-app-data\v1\3.8\image\CopyPipInstall\wheel-0.34.2-py2.py3-n
one-any\wheel-0.34.2.virtualenv to D:\projects\ceres\Lib\site-packages\wheel-0.34.2.virtualenv [DEBUG _sync:48]
432 generated console scripts wheel.exe wheel3.exe wheel-3.8.exe [DEBUG base:53]
479 copy directory C:\Users\Spors\AppData\Local\Temp\tmpbehz5s21\seed-app-data\v1\3.8\image\CopyPipInstall\setuptools-4
6.0.0-py3-none-any\setuptools to D:\projects\ceres\Lib\site-packages\setuptools [DEBUG _sync:48]
554 copy directory C:\Users\Spors\AppData\Local\Temp\tmpbehz5s21\seed-app-data\v1\3.8\image\CopyPipInstall\pip-20.0.2-p
y2.py3-none-any\pip to D:\projects\ceres\Lib\site-packages\pip [DEBUG _sync:48]
857 copy directory C:\Users\Spors\AppData\Local\Temp\tmpbehz5s21\seed-app-data\v1\3.8\image\CopyPipInstall\setuptools-4
6.0.0-py3-none-any\setuptools-46.0.0.dist-info to D:\projects\ceres\Lib\site-packages\setuptools-46.0.0.dist-info [DEBU
G _sync:48]
884 copy C:\Users\Spors\AppData\Local\Temp\tmpbehz5s21\seed-app-data\v1\3.8\image\CopyPipInstall\setuptools-46.0.0-py3-
none-any\setuptools-46.0.0.virtualenv to D:\projects\ceres\Lib\site-packages\setuptools-46.0.0.virtualenv [DEBUG _sync:
1764 copy C:\Users\Spors\AppData\Local\Temp\tmpbehz5s21\seed-app-data\v1\3.8\image\CopyPipInstall\pip-20.0.2-py2.py3-none-any\pip-20.0.2.virtualenv to D:\projects\ceres\Lib\site-packages\pip-20.0.2.virtualenv [DEBUG _sync:48]
1767 generated console scripts pip.exe pip3.exe pip-3.8.exe [DEBUG base:53]
1767 Attempting to release lock 2491013030048 on C:\Users\Spors\AppData\Local\Temp\tmpbehz5s21\seed-app-data\v1\3.8\wheels.lock [DEBUG filelock:315]
1767 Lock 2491013030048 released on C:\Users\Spors\AppData\Local\Temp\tmpbehz5s21\seed-app-data\v1\3.8\wheels.lock [INFO filelock:318]
1768 add activators for Bash, Batch, Fish, PowerShell, Python, Xonsh [INFO session:64]
1771 write D:\projects\ceres\pyvenv.cfg [DEBUG pyenv_cfg:34]
1771    home = c:\program files\python\38 [DEBUG pyenv_cfg:38]
1771    implementation = CPython [DEBUG pyenv_cfg:38]
1771    version_info = 3.8.1.final.0 [DEBUG pyenv_cfg:38]
1771    virtualenv = 20.0.10 [DEBUG pyenv_cfg:38]
1771    include-system-site-packages = false [DEBUG pyenv_cfg:38]
1771    base-prefix = c:\program files\python\38 [DEBUG pyenv_cfg:38]
1771    base-exec-prefix = c:\program files\python\38 [DEBUG pyenv_cfg:38]
1771    base-executable = c:\program files\python\38\python.exe [DEBUG pyenv_cfg:38]
1772 remove temporary app data folder C:\Users\Spors\AppData\Local\Temp\tmpbehz5s21 [DEBUG app_data:35]
1825 created virtual environment CPython3.8.1.final.0-64 in 1773ms
  creator CPython3Windows(dest=D:\projects\ceres, clear=False, global=False)
  seeder FromAppData(download=False, pip=latest, setuptools=latest, wheel=latest, via=copy, app_data_dir=C:\Users\Spors\AppData\Local\Temp\tmpbehz5s21\seed-app-data\v1)
  activators BashActivator,BatchActivator,FishActivator,PowerShellActivator,PythonActivator,XonshActivator [WARNING __main__:21]

Workaround until it's fixed
See https://github.com/pypa/virtualenv/issues/1724#issuecomment-604964446

bug help-wanted needs-reproducer

Most helpful comment

This is what I've tried to explain on the other thread too, seems I've failed. We provide an activation script. For deactivation the expectation isn't that you'll have a deactivate script but rather typing in deactivate in the shell will perform the deactivation. The only reason the Batch activation has a deactivation is because it does not allow defining a deactivate script during activation, so we work around that issue by having a deactivation script that we put onto the path.

All 6 comments

Did you try if the problem persists with other terminals?

The report shows the creation of the virtual environment, but doesn't show how to reproduce the issue. I have confirmed on my PC that I can create, activate and deactivate a virtualenv on Windows Terminal:

>virtualenv xxx
created virtual environment CPython3.8.1.final.0-64 in 2468ms
  creator CPython3Windows(dest=C:\Work\Projects\pip\xxx, clear=False, global=False)
  seeder FromAppData(download=False, pip=latest, setuptools=latest, wheel=latest, via=copy, app_data_dir=C:\Users\Gustav\AppData\Local\pypa\virtualenv\seed-app-data\v1
.0.1)
  activators BashActivator,BatchActivator,FishActivator,PowerShellActivator,PythonActivator,XonshActivator
>.\xxx\Scripts\activate.ps1
(xxx) >deactivate
>

If you can provide instructions on how to reproduce the issue, I'll try them out and confirm if I can get the same problem.

Did you try if the problem persists with other terminals?

It is happening just with the Powershell cmd.

The report shows the creation of the virtual environment, but doesn't show how to reproduce the issue. I have confirmed on my PC that I can create, activate and deactivate a virtualenv on Windows Terminal:

>virtualenv xxx
created virtual environment CPython3.8.1.final.0-64 in 2468ms
  creator CPython3Windows(dest=C:\Work\Projects\pip\xxx, clear=False, global=False)
  seeder FromAppData(download=False, pip=latest, setuptools=latest, wheel=latest, via=copy, app_data_dir=C:\Users\Gustav\AppData\Local\pypa\virtualenv\seed-app-data\v1
.0.1)
  activators BashActivator,BatchActivator,FishActivator,PowerShellActivator,PythonActivator,XonshActivator
>.\xxx\Scripts\activate.ps1
(xxx) >deactivate
>

If you can provide instructions on how to reproduce the issue, I'll try them out and confirm if I can get the same problem.

Whats your current powershell version? Just run.

Get-Host | Select-Object Version

I cannot provide any instructions because I dont do anything different than you.

virtualenv . -vvv --with-traceback
./Scripts/activate
./Scripts/deactivate

@Halfbax the expectation is that this would work:

virtualenv . -vvv --with-traceback
./Scripts/activate
deactivate

Note, not calling the deactivated script directly. Can you show the output of those three?

@gaborbernat

Calling it directly seems to be the problem. I am able to reproduce it with Powershell 5/6/7.

This works.

deactivate

The activation nor the deactivation scripts produce any output. You can close this thread. If it is okay for you that the deactivation script doesnt work when directly called.

This is what I've tried to explain on the other thread too, seems I've failed. We provide an activation script. For deactivation the expectation isn't that you'll have a deactivate script but rather typing in deactivate in the shell will perform the deactivation. The only reason the Batch activation has a deactivation is because it does not allow defining a deactivate script during activation, so we work around that issue by having a deactivation script that we put onto the path.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

rlayte picture rlayte  ·  27Comments

dpvpro picture dpvpro  ·  43Comments

native-api picture native-api  ·  22Comments

ionelmc picture ionelmc  ·  26Comments

BakedPotato999 picture BakedPotato999  ·  31Comments