运行Windows Anaconda Powershell Prompt 报错显示:Invoke-Expression : 无法将参数绑定到参数“Command”,因为该参数为空字符串。 所在位置 D:\anaconda\shell\condabin\Conda.psm1:107 字符: 36(对应自己报错路径和文件行数)
主要看报错该上面的报错位置
Traceback (most recent call last):
File "D:\app\Anaconda\Lib\site-packages\conda\exception_handler.py", line 17, in __call__
return func(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^
File "D:\app\Anaconda\Lib\site-packages\conda\cli\main.py", line 91, in main_sourced
print(activator.execute(), end="")
UnicodeEncodeError: 'gbk' codec can't encode character '\ue219' in position 1967: illegal multibyte sequence
UnicodeEncodeError: ‘gbk’ codec can’t encode character ‘\ue1bb’ in position 491: illegal multibyte sequence,然而在外部中断中却不会出现,是 Python 插件解析错误,python 的 print 函数存在限制,不能打印全部的 unicode 字符
解决方案:
跳转到该D:\app\Anaconda\Lib\site-packages\conda\cli\main.py文件中
1.在文件最上方加上
import io
2.函数中设置编码格式为 gb18030
找到 print(activator.execute(), end=""),在此前面加上
def main_sourced(shell, *args, **kwargs):
"""Entrypoint for the "sourced" invocation of CLI interface. E.g. `conda activate`."""
shell = shell.replace("shell.", "", 1)
# This is called any way later in conda.activate, so no point in removing it
from ..base.context import context
context.__init__()
init_loggers(context)
from ..activate import _build_activator_cls
try:
activator_cls = _build_activator_cls(shell)
except KeyError:
from ..exceptions import CondaError
raise CondaError("%s is not a supported shell." % shell)
activator = activator_cls(args)
sys.stdout = io.TextIOWrapper(sys.stdout.buffer,encoding='gb18030')
print(activator.execute(), end="")
return 0
最后问题被成功解决。