win10系统 You may need to close and restart your shell after running ‘conda init‘失败原因之一:profile.ps1的问题

问题解决过程

1.安装好(我 all user/仅自己都尝试过)conda,我是手动配置的环境变量之后,我打算conda activate base环境。PS:我自己的电脑以前装过miniconda,时间久了也不清楚会不会存在没卸载干净的问题了。

2.结果失败了,报错:windows You may need to close and restart your shell after running 'conda init'. 但是conda -V的输出是正常的conda 23.5.2。

3.我conda init/ conda init powershell / conda init cmd.exe都失败了。印象中我第一次conda init powershell之后输出的大意是让我重启终端,我重启之后再conda init powershell了一次就会no action taken,具体输出的最后是:

C:\Users\1\OneDrive\�ĵ�\WindowsPowerShell\profile.ps1 
No action taken.

4.我按照网上的教程win vscode anaconda conda init 失败_conda init失败_TuT_today的博客-CSDN博客

get-ExecutionPolicy   # 查看系统执行策略状态 
set-executionpolicy remotesigned # 修改执行策略状态

我在powershell管理员执行get-ExecutionPolicy的时候是Restricted的状态,所以我就通过get-ExecutionPolicy
set-executionpolicy remotesigned改成了remotesigned状态。但是我还是没法成功conda activate。

4.我发现每次conda init powershell都会在我的C:\Users\1\OneDrive\�ĵ�\WindowsPowerShell\profile.ps1 路径新增一个乱码文件夹�ĵ�\WindowsPowerShell里面是配置文件profile.ps1,里面有内容

#region conda initialize
# !! Contents within this block are managed by 'conda init' !!
If (Test-Path "D:\Anaconda\Scripts\conda.exe") {
    (& "D:\Anaconda\Scripts\conda.exe" "shell.powershell" "hook") | Out-String | ?{$_} | Invoke-Expression
}
#endregion

5.受到这篇ananconda powershell init失败&无法激活环境问题_conda init powershell 报错_往事封尘的博客-CSDN博客和评论区的启发,我怀疑文件profile.ps1放错了位置,Newbing也说“conda init是一个命令,用于在PowerShell中使用conda命令。它会在C:\Users\<username>\Documents\WindowsPowerShell\profile.ps1文件中添加一些初始化代码,用于设置conda的环境变量和提示符。”

6.解决方案:复制创建的C:\Users\1\OneDrive\�ĵ�\WindowsPowerShell\profile.ps1 文件,在C:\Users\1\OneDrive\文档目录下新建文件夹名称WindowsPowerShell,粘贴之前复制的profile.ps1。成功解决。

简要解决方案:

1. win+x进入powershell管理员之后如果执行

get-ExecutionPolicy

输出是:Restricted,就通过

set-executionpolicy remotesigned

改成remotesigned状态。

2.如果电脑中没有

C:\Users\<username>\Documents\WindowsPowerShell\profile.ps1

这个目录和文件,并且conda init把profile.ps1文件放在了其他目录下(具体路径conda init XXX的输出中会写),以我放错的乱码文件夹位置

C:\Users\1\OneDrive\�ĵ�\WindowsPowerShell\profile.ps1

为例。就首先在C:\Users\<username>\Documents(文档)文件夹手动创建WindowsPowerShell文件夹,然后把乱码错误文件夹中的profile.ps1文件移动进Documents\WindowsPowerShell\profile.ps1位置。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值