Virtualenv: WindowsターミナルでPowershellを使用しているときにvirtualenvを非アクティブ化できません

作成日 2020年03月27日  ·  6コメント  ·  ソース: pypa/virtualenv

問題

WindowsターミナルでPowershellを使用しているときに、仮想環境を非アクティブ化できません。

環境
Windows 10 Pro 10.0.18363
Windowsターミナル(Powershell)

console pip 20.0.2 setuptools 46.0.0 wheel 0.34.2

仮想環境作成の出力

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]

修正されるまでの回避策
https://github.com/pypa/virtualenv/issues/1724#issuecomment-604964446を参照して

bug help-wanted needs-reproducer

最も参考になるコメント

これは私が他のスレッドでも説明しようとしたことですが、失敗したようです。 アクティベーションスクリプトを提供します。 非アクティブ化の場合、非アクティブ化スクリプトがあることは期待されていませんが、シェルにdeactivateと入力すると、非アクティブ化が実行されます。 バッチアクティベーションに非アクティブ化がある唯一の理由は、アクティブ化中に非アクティブ化スクリプトを定義できないためです。そのため、パスに非アクティブ化スクリプトを配置することで、この問題を回避します。

全てのコメント6件

他の端末でも問題が解決しない場合は試しましたか?

レポートには仮想環境の作成が示されていますが、問題を再現する方法は示されていません。 PCで、Windowsターミナルでvirtualenvを作成、アクティブ化、および非アクティブ化できることを確認しました。

>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
>

問題を再現する方法について説明していただければ、試してみて、同じ問題が発生するかどうかを確認します。

他の端末でも問題が解決しない場合は試しましたか?

これは、Powershellコマンドだけで発生します。

レポートには仮想環境の作成が示されていますが、問題を再現する方法は示されていません。 PCで、Windowsターミナルでvirtualenvを作成、アクティブ化、および非アクティブ化できることを確認しました。

>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
>

問題を再現する方法について説明していただければ、試してみて、同じ問題が発生するかどうかを確認します。

現在のPowerShellバージョンは何ですか? ただ走れ。

Get-Host | Select-Object Version

私はあなたと違うことは何もしていないので、私は指示を与えることができません。

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

@Halfbaxは、これが機能することを期待しています。

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

非アクティブ化されたスクリプトを直接呼び出さないことに注意してください。 これら3つの出力を表示できますか?

@gaborbernat

直接呼び出すのが問題のようです。 Powershell5 / 6/7で再現できます。

これは機能します。

deactivate

アクティブ化スクリプトも非アクティブ化スクリプトも出力を生成します。 このスレッドを閉じることができます。 直接呼び出されたときに非アクティブ化スクリプトが機能しないことが問題ない場合。

これは私が他のスレッドでも説明しようとしたことですが、失敗したようです。 アクティベーションスクリプトを提供します。 非アクティブ化の場合、非アクティブ化スクリプトがあることは期待されていませんが、シェルにdeactivateと入力すると、非アクティブ化が実行されます。 バッチアクティベーションに非アクティブ化がある唯一の理由は、アクティブ化中に非アクティブ化スクリプトを定義できないためです。そのため、パスに非アクティブ化スクリプトを配置することで、この問題を回避します。

このページは役に立ちましたか?
0 / 5 - 0 評価