参考链接1: conda : 无法将“conda”项识别为 cmdlet、函数、脚本文件或可运行程序的名称。
参考链接2: Win10下Anaconda使用conda activate报错Your shell has not been properly configured to use ‘conda activate’
参考链接3: 关于使用conda activate无法进入虚拟环境 CommandNotFoundError: Your shell has not been properly configured to use
参考链接4: vscode提示 “无法加载文件C:\XXX\WindowsPowerShell\profile.ps1,因为在此系统上禁止运行脚本” 的错误
参考链接5: vscCode执行命令提示无法加载文件 C:\Users\XXX\AppData\Roaming\npm\vue.ps1,因为在此系统上禁止运行脚本
问题1:cmd下无法识别conda
conda : 无法将“conda”项识别为 cmdlet、函数、
脚本文件或可运行程序的名称。
请检查名称的拼写,如果包括路径,
请确保路径正确,然后再试一次。
解决办法:
没有添加系统变量,所以系统根本识别不了conda命令,找不到位置。
添加以下系统变量即可正常运行:
添加对应Anaconda环境变量到系统变量中:
我的是:
D:\Anaconda3
D:\Anaconda3\Scripts
D:\Anaconda3\Library\bin
截图如下:添加好后重启cmd即可
问题2:输入conda activate ssd 之后报错
PS C:\Users\chenxuqi\Desktop\新建文件夹> conda activate ssd
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'.
PS C:\Users\chenxuqi\Desktop\新建文件夹>
解决办法1:需要先输入命令activate,如下演示:
Microsoft Windows [版本 10.0.18363.1198]
(c) 2019 Microsoft Corporation。保留所有权利。
C:\Users\chenxuqi>activate
(base) C:\Users\chenxuqi>conda activate ssd
(ssd) C:\Users\chenxuqi>python
Python 3.6.12 |Anaconda, Inc.| (default, Sep 9 2020, 00:29:25) [MSC v.1916 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import torch
>>> torch.__version__
'0.4.1'
>>>
>>>
解决办法2:输入如下命令,具体如下演示:
使用管理员身份打开cmd,输入命令: conda init cmd.exe或者conda init powershell,这两条都试试,回车,重启cmd.本人使用第一条指令就成功解决了.
Microsoft Windows [版本 10.0.18363.1198]
(c) 2019 Microsoft Corporation。保留所有权利。
C:\WINDOWS\system32>conda activate ssd
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:\WINDOWS\system32>conda init cmd.exe
no change D:\Anaconda3\Scripts\conda.exe
no change D:\Anaconda3\Scripts\conda-env.exe
no change D:\Anaconda3\Scripts\conda-script.py
no change D:\Anaconda3\Scripts\conda-env-script.py
no change D:\Anaconda3\condabin\conda.bat
no change D:\Anaconda3\Library\bin\conda.bat
no change D:\Anaconda3\condabin\_conda_activate.bat
no change D:\Anaconda3\condabin\rename_tmp.bat
no change D:\Anaconda3\condabin\conda_auto_activate.bat
no change D:\Anaconda3\condabin\conda_hook.bat
no change D:\Anaconda3\Scripts\activate.bat
no change D:\Anaconda3\condabin\activate.bat
no change D:\Anaconda3\condabin\deactivate.bat
modified D:\Anaconda3\Scripts\activate
modified D:\Anaconda3\Scripts\deactivate
modified D:\Anaconda3\etc\profile.d\conda.sh
modified D:\Anaconda3\etc\fish\conf.d\conda.fish
no change D:\Anaconda3\shell\condabin\Conda.psm1
modified D:\Anaconda3\shell\condabin\conda-hook.ps1
modified D:\Anaconda3\Lib\site-packages\xontrib\conda.xsh
modified D:\Anaconda3\etc\profile.d\conda.csh
modified HKEY_CURRENT_USER\Software\Microsoft\Command Processor\AutoRun
==> For changes to take effect, close and re-open your current shell. <==
C:\WINDOWS\system32>conda init powershell
no change D:\Anaconda3\Scripts\conda.exe
no change D:\Anaconda3\Scripts\conda-env.exe
no change D:\Anaconda3\Scripts\conda-script.py
no change D:\Anaconda3\Scripts\conda-env-script.py
no change D:\Anaconda3\condabin\conda.bat
no change D:\Anaconda3\Library\bin\conda.bat
no change D:\Anaconda3\condabin\_conda_activate.bat
no change D:\Anaconda3\condabin\rename_tmp.bat
no change D:\Anaconda3\condabin\conda_auto_activate.bat
no change D:\Anaconda3\condabin\conda_hook.bat
no change D:\Anaconda3\Scripts\activate.bat
no change D:\Anaconda3\condabin\activate.bat
no change D:\Anaconda3\condabin\deactivate.bat
no change D:\Anaconda3\Scripts\activate
no change D:\Anaconda3\Scripts\deactivate
no change D:\Anaconda3\etc\profile.d\conda.sh
no change D:\Anaconda3\etc\fish\conf.d\conda.fish
no change D:\Anaconda3\shell\condabin\Conda.psm1
no change D:\Anaconda3\shell\condabin\conda-hook.ps1
no change D:\Anaconda3\Lib\site-packages\xontrib\conda.xsh
no change D:\Anaconda3\etc\profile.d\conda.csh
modified C:\Users\chenxuqi\Documents\WindowsPowerShell\profile.ps1
==> For changes to take effect, close and re-open your current shell. <==
成功解决:
Microsoft Windows [版本 10.0.18363.1198]
(c) 2019 Microsoft Corporation。保留所有权利。
C:\Users\chenxuqi>conda activate ssd
(ssd) C:\Users\chenxuqi>python
Python 3.6.12 |Anaconda, Inc.| (default, Sep 9 2020, 00:29:25) [MSC v.1916 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import torch
>>> torch.__version__
'0.4.1'
>>>
>>>
问题3:VSCode的Terminal终端下报错:
错误提示:
. : 无法加载文件
C:\Users\chenxuqi\Documents\WindowsPowerShell\profile.ps1,
因为在此系统上禁止运行脚本。有关详细信息,
请参阅
https:/go.microsoft.com/fwlink/?LinkID=135170
中的 about_Execution_Policies。
解决办法摘录自参考链接4和参考链接5:
解决步骤:
1.以管理员身份运行PowerShell
2.输入命令: get-ExecutionPolicy,查看是否返回Restricted,表示状态是禁止的.
3.执行:set-ExecutionPolicy RemoteSigned即可,根据提示输入Y,确认.
截图展示演示过程:
代码展示:
Windows PowerShell
版权所有 (C) Microsoft Corporation。保留所有权利。
尝试新的跨平台 PowerShell https://aka.ms/pscore6
. : 无法加载文件 C:\Users\chenxuqi\Documents\WindowsPowerShell\profile.ps1,因为在此系统上禁止运行脚本。有关详细信息,
请参阅 https:/go.microsoft.com/fwlink/?LinkID=135170 中的 about_Execution_Policies。
所在位置 行:1 字符: 3
+ . 'C:\Users\chenxuqi\Documents\WindowsPowerShell\profile.ps1'
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : SecurityError: (:) [],PSSecurityException
+ FullyQualifiedErrorId : UnauthorizedAccess
PS C:\WINDOWS\system32> get-ExecutionPolicy
Restricted
PS C:\WINDOWS\system32> set-ExecutionPolicy RemoteSigned
执行策略更改
执行策略可帮助你防止执行不信任的脚本。更改执行策略可能会产生安全风险,如 https:/go.microsoft.com/fwlink/?LinkID=135170
中的 about_Execution_Policies 帮助主题所述。是否要更改执行策略?
[Y] 是(Y) [A] 全是(A) [N] 否(N) [L] 全否(L) [S] 暂停(S) [?] 帮助 (默认值为“N”): Y
PS C:\WINDOWS\system32>
PS C:\WINDOWS\system32>
完美解决:
VsCode下代码展示:
Windows PowerShell
版权所有 (C) Microsoft Corporation。保留所有权利。
尝试新的跨平台 PowerShell https://aka.ms/pscore6
加载个人及系统配置文件用了 853 毫秒。
(base) PS C:\Users\chenxuqi\Desktop\新建文件夹> conda activate ssd
(ssd) PS C:\Users\chenxuqi\Desktop\新建文件夹> python
Python 3.6.12 |Anaconda, Inc.| (default, Sep 9 2020, 00:29:25) [MSC v.1916 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import torch
>>> torch.__version__
'0.4.1'
>>>
VsCode下演示效果截图: