解决PyCharm打开PowerShell终端报错找不到conda-hook.ps1文件

文章目录

报错

pycharm项目配置了conda的虚拟环境后,打开终端,报以下错:

powershell 复制代码
Windows PowerShell
版权所有(C) Microsoft Corporation。保留所有权利。

安装最新的 PowerShell,了解新功能和改进!https://aka.ms/PSWindows

加载个人及系统配置文件用了 3432 毫秒。

# >>>>>>>>>>>>>>>>>>>>>> ERROR REPORT <<<<<<<<<<<<<<<<<<<<<<

    Traceback (most recent call last):
      File "conda\exception_handler.py", line 28, in __call__
      File "conda\cli\main.py", line 87, in main_sourced
      File "conda\activate.py", line 211, in execute
      File "conda\deprecations.py", line 174, in inner
      File "conda\activate.py", line 197, in hook
      File "pathlib\_local.py", line 546, in read_text
      File "pathlib\_abc.py", line 632, in read_text
      File "pathlib\_local.py", line 537, in open
    FileNotFoundError: [Errno 2] No such file or directory: 'C:\\Users\\xxx\\AppData\\Local\\Temp\\_MEI126402\\conda\\shell\\condabin\\conda-hook.ps1'

`$ D:\softwares\miniconda3\_conda.exe shell.powershell hook`

原因

猜测是因为在配置conda的虚拟环境时,指定了错误的conda的可执行文件:

选到了这个_conda.exe这个可执行文件,就会出现C:\Users\30667\AppData\Local\Temp\ MEI23362这个虚拟环境。

然后打开终端,就会报以上错。

解决

选择正确的conda可执行文件,condabin\conda.bat(也可选择Scripts\conda.exe):

再打开终端,就能正常加载conda虚拟环境了。