VS code 和anaconda报错

本文最后更新于 2024年5月16日。

UserWarning: mkl-service package failed to import,
therefore Intel(R) MKL initialization ensuring its correct out-of-the box operation under condition when Gnu OpenMP had already been loaded by Python process is not assured. Please install mkl-service package, see http://github.com/IntelPython/mkl-service
安装anaconda后,在ipython里导入某些模块的时候报错
UserWarning: mkl-service package failed to import, therefore Intel(R) MKL initialization ensuring its correct out-of-the box operation under condition when Gnu OpenMP had already been loaded by Python process is not assured. Please install mkl-service package
解决方法:
先配置三个环境变量,缺一不可
D:\Anaconda3
D:\Anaconda3\Scripts
D:\Anaconda3\Library\bin
将D:\Anaconda3\Library\bin下
libcrypto-1_1-x64.dll
libssl-1_1-x64.dll
以上两个文件复制到
D:\Anaconda3\DLLs
问题解决

完成上面步骤后重启vscode

PS E:\mydoc\sync_pc_home_work\pyfile> conda activate base
CommandNotFoundError: Your shell has not been properly configured to use 'conda activate'.
If using 'conda activate' from a batch script, change your
invocation to 'CALL conda.bat activate'.
To initialize your shell, run
$ conda init <SHELL_NAME>
Currently supported shells are:
- bash
- cmd.exe
- fish
- tcsh
- xonsh
- zsh
- powershell
See 'conda init --help' for more information and options.
IMPORTANT: You may need to close and restart your shell after running 'conda init'.

接着

C:\Users\xxx>conda init
no change     C:\ProgramData\Anaconda3\Scripts\conda.exe
no change     C:\ProgramData\Anaconda3\Scripts\conda-env.exe
no change     C:\ProgramData\Anaconda3\Scripts\conda-script.py
no change     C:\ProgramData\Anaconda3\Scripts\conda-env-script.py
no change     C:\ProgramData\Anaconda3\condabin\conda.bat
no change     C:\ProgramData\Anaconda3\Library\bin\conda.bat
no change     C:\ProgramData\Anaconda3\condabin\_conda_activate.bat
no change     C:\ProgramData\Anaconda3\condabin\rename_tmp.bat
no change     C:\ProgramData\Anaconda3\condabin\conda_auto_activate.bat
no change     C:\ProgramData\Anaconda3\condabin\conda_hook.bat
no change     C:\ProgramData\Anaconda3\Scripts\activate.bat
no change     C:\ProgramData\Anaconda3\condabin\activate.bat
no change     C:\ProgramData\Anaconda3\condabin\deactivate.bat
modified      C:\ProgramData\Anaconda3\Scripts\activate
modified      C:\ProgramData\Anaconda3\Scripts\deactivate
modified      C:\ProgramData\Anaconda3\etc\profile.d\conda.sh
modified      C:\ProgramData\Anaconda3\etc\fish\conf.d\conda.fish
no change     C:\ProgramData\Anaconda3\shell\condabin\Conda.psm1
modified      C:\ProgramData\Anaconda3\shell\condabin\conda-hook.ps1
no change     C:\ProgramData\Anaconda3\Lib\site-packages\xontrib\conda.xsh
modified      C:\ProgramData\Anaconda3\etc\profile.d\conda.csh
modified      C:\Users\Xuemao\Documents\WindowsPowerShell\profile.ps1
modified      HKEY_CURRENT_USER\Software\Microsoft\Command Processor\AutoRun
==> For changes to take effect, close and re-open your current shell. <==

powershell会报无法加载脚本的错误,

然后会报无法运行脚本错误

. : 无法加载文件 C:\Users\Xuemao\Documents\WindowsPowerShell\profile.ps1,因为在此系统上禁止运行脚本。有关详细信息,
请参阅 https:/go.microsoft.com/fwlink/?LinkID=135170 中的 about_Execution_Policies。
所在位置 行:1 字符: 3
+ . 'C:\Users\Xuemao\Documents\WindowsPowerShell\profile.ps1'
+   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo          : SecurityError: (:) [],PSSecurityException
+ FullyQualifiedErrorId : UnauthorizedAccess

下面这个对我无效

直接原因:powershell和cmd是不一样的,在cmd输入conda activate xxx可以看到前面的base环境变成相应的xxx环境,而在powershell中却不会。
直接说解决方法:打开powershell输入conda init即可解决,无需添加环境变量,无需改动powershell,代价是每次打开powershell都将花几百毫秒加载文件
我使用的是vscode,终端默认powershell,如果是cmd就完全不会有这个提示,所以这个报错的原因在于powershell的缺陷