Anaconda2和Anaconda3反复安装出现的问题的解决方法

最近多次安装卸载Anaconda2和Anaconda3,导致重新安装时老是出现两个问题,其中一个问题是Anaconda装完后,打开Anaconda Navigator报错,无法启动;令一个问题是Jupyter Notebook打开后显示kernel dead,防止以后再次遇到手足无措,在此写下解决方法。

1.Navigator Error:An unexpected error occurred on Navigator start-up

报错信息如下:

Main Error
could not determine a constructor for the tag 'tag:yaml.org,2002:python/unicode'
  in "C:\Users\Zheng Chen\AppData\Local\ContinuumIO\binstar\config.yaml", line 1, column 1
Traceback
Traceback (most recent call last):
  File "C:\ProgramData\Anaconda2\lib\site-packages\anaconda_navigator\exceptions.py", line 75, in exception_handler
    return_value = func(*args, **kwargs)
  File "C:\ProgramData\Anaconda2\lib\site-packages\anaconda_navigator\app\start.py", line 138, in start_app
    window = run_app(splash)
  File "C:\ProgramData\Anaconda2\lib\site-packages\anaconda_navigator\app\start.py", line 64, in run_app
    window = MainWindow(splash=splash, tab_project=False)
  File "C:\ProgramData\Anaconda2\lib\site-packages\anaconda_navigator\widgets\main_window.py", line 163, in __init__
    self.api = AnacondaAPI()
  File "C:\ProgramData\Anaconda2\lib\site-packages\anaconda_navigator\api\anaconda_api.py", line 2127, in AnacondaAPI
    ANACONDA_API = _AnacondaAPI()
  File "C:\ProgramData\Anaconda2\lib\site-packages\anaconda_navigator\api\anaconda_api.py", line 90, in __init__
    self._client_api = ClientAPI()
  File "C:\ProgramData\Anaconda2\lib\site-packages\anaconda_navigator\api\client_api.py", line 638, in ClientAPI
    CLIENT_API = _ClientAPI()
  File "C:\ProgramData\Anaconda2\lib\site-packages\anaconda_navigator\api\client_api.py", line 93, in __init__
    self.reload_binstar_client()
  File "C:\ProgramData\Anaconda2\lib\site-packages\anaconda_navigator\api\client_api.py", line 305, in reload_binstar_client
    config = binstar_client.utils.get_config()
  File "C:\ProgramData\Anaconda2\lib\site-packages\binstar_client\utils\config.py", line 229, in get_config
    file_configs = load_file_configs(SEARCH_PATH)
  File "C:\ProgramData\Anaconda2\lib\site-packages\binstar_client\utils\config.py", line 223, in load_file_configs
    raw_data = collections.OrderedDict(kv for kv in itertools.chain.from_iterable(load_paths))
  File "C:\ProgramData\Anaconda2\lib\collections.py", line 69, in __init__
    self.__update(*args, **kwds)
  File "C:\ProgramData\Anaconda2\lib\_abcoll.py", line 571, in update
    for key, value in other:
  File "C:\ProgramData\Anaconda2\lib\site-packages\binstar_client\utils\config.py", line 223, in 
    raw_data = collections.OrderedDict(kv for kv in itertools.chain.from_iterable(load_paths))
  File "C:\ProgramData\Anaconda2\lib\site-packages\binstar_client\utils\config.py", line 203, in _dir_yaml_loader
    yield filepath, load_config(filepath)
  File "C:\ProgramData\Anaconda2\lib\site-packages\binstar_client\utils\config.py", line 187, in load_config
    data = yaml_load(fd)
  File "C:\ProgramData\Anaconda2\lib\site-packages\binstar_client\utils\yaml.py", line 9, in yaml_load
    return safe_load(stream)
  File "C:\ProgramData\Anaconda2\lib\site-packages\yaml\__init__.py", line 93, in safe_load
    return load(stream, SafeLoader)
  File "C:\ProgramData\Anaconda2\lib\site-packages\yaml\__init__.py", line 71, in load
    return loader.get_single_data()
  File "C:\ProgramData\Anaconda2\lib\site-packages\yaml\constructor.py", line 39, in get_single_data
    return self.construct_document(node)
  File "C:\ProgramData\Anaconda2\lib\site-packages\yaml\constructor.py", line 48, in construct_document
    for dummy in generator:
  File "C:\ProgramData\Anaconda2\lib\site-packages\yaml\constructor.py", line 398, in construct_yaml_map
    value = self.construct_mapping(node)
  File "C:\ProgramData\Anaconda2\lib\site-packages\yaml\constructor.py", line 208, in construct_mapping
    return BaseConstructor.construct_mapping(self, node, deep=deep)
  File "C:\ProgramData\Anaconda2\lib\site-packages\yaml\constructor.py", line 127, in construct_mapping
    key = self.construct_object(key_node, deep=deep)
  File "C:\ProgramData\Anaconda2\lib\site-packages\yaml\constructor.py", line 88, in construct_object
    data = constructor(self, node)
  File "C:\ProgramData\Anaconda2\lib\site-packages\yaml\constructor.py", line 414, in construct_undefined
    node.start_mark)
ConstructorError: could not determine a constructor for the tag 'tag:yaml.org,2002:python/unicode'

  in "C:\Users\Zheng Chen\AppData\Local\ContinuumIO\binstar\config.yaml", line 1, column 1

解决方法:

windows下以管理员身份打开Anaconda Prompt,然后逐个输入下面的语句,进行更新(linux或Max下直接在终端输入即可)

conda update conda
conda update anaconda-navigator
conda update navigator-updater

若还是不行,再输入以下语句:

conda install anaconda-client=1.6.14

2.kernel dead(Kernel error)

Anaconda2和Anaconda3反复安装出现的问题的解决方法_第1张图片

报错信息如下:

Traceback (most recent call last):
File "C:\ProgramData\Anaconda2\lib\site-packages\tornado\web.py", line 1512, in _execute
result = yield result
File "C:\ProgramData\Anaconda2\lib\site-packages\tornado\gen.py", line 1055, in run
value = future.result()
File "C:\ProgramData\Anaconda2\lib\site-packages\tornado\concurrent.py", line 238, in result
raise_exc_info(self._exc_info)
File "C:\ProgramData\Anaconda2\lib\site-packages\tornado\gen.py", line 1063, in run
yielded = self.gen.throw(*exc_info)
File "C:\ProgramData\Anaconda2\lib\site-packages\notebook\services\sessions\handlers.py", line 73, in post
type=mtype))
File "C:\ProgramData\Anaconda2\lib\site-packages\tornado\gen.py", line 1055, in run
value = future.result()
File "C:\ProgramData\Anaconda2\lib\site-packages\tornado\concurrent.py", line 238, in result
raise_exc_info(self._exc_info)
File "C:\ProgramData\Anaconda2\lib\site-packages\tornado\gen.py", line 1063, in run
yielded = self.gen.throw(*exc_info)
File "C:\ProgramData\Anaconda2\lib\site-packages\notebook\services\sessions\sessionmanager.py", line 79, in create_session
kernel_id = yield self.start_kernel_for_session(session_id, path, name, type, kernel_name)
File "C:\ProgramData\Anaconda2\lib\site-packages\tornado\gen.py", line 1055, in run
value = future.result()
File "C:\ProgramData\Anaconda2\lib\site-packages\tornado\concurrent.py", line 238, in result
raise_exc_info(self._exc_info)
File "C:\ProgramData\Anaconda2\lib\site-packages\tornado\gen.py", line 1063, in run
yielded = self.gen.throw(*exc_info)
File "C:\ProgramData\Anaconda2\lib\site-packages\notebook\services\sessions\sessionmanager.py", line 92, in start_kernel_for_session
self.kernel_manager.start_kernel(path=kernel_path, kernel_name=kernel_name)
File "C:\ProgramData\Anaconda2\lib\site-packages\tornado\gen.py", line 1055, in run
value = future.result()
File "C:\ProgramData\Anaconda2\lib\site-packages\tornado\concurrent.py", line 238, in result
raise_exc_info(self._exc_info)
File "C:\ProgramData\Anaconda2\lib\site-packages\tornado\gen.py", line 307, in wrapper
yielded = next(result)
File "C:\ProgramData\Anaconda2\lib\site-packages\notebook\services\kernels\kernelmanager.py", line 148, in start_kernel
super(MappingKernelManager, self).start_kernel(**kwargs)
File "C:\ProgramData\Anaconda2\lib\site-packages\jupyter_client\multikernelmanager.py", line 110, in start_kernel
km.start_kernel(**kwargs)
File "C:\ProgramData\Anaconda2\lib\site-packages\jupyter_client\manager.py", line 258, in start_kernel
**kw)
File "C:\ProgramData\Anaconda2\lib\site-packages\jupyter_client\manager.py", line 203, in _launch_kernel
return launch_kernel(kernel_cmd, **kw)
File "C:\ProgramData\Anaconda2\lib\site-packages\jupyter_client\launcher.py", line 128, in launch_kernel
proc = Popen(cmd, **kwargs)
File "C:\ProgramData\Anaconda2\lib\subprocess.py", line 390, in init
errread, errwrite)
File "C:\ProgramData\Anaconda2\lib\subprocess.py", line 640, in _execute_child
startupinfo)

WindowsError: [Error 2]

原因是python2.7和python3.6反复安装卸载的缘故(即Anaconda2和Anaconda3反复安装卸载的缘故),导致jupyter notebook没有读到正确的python 内核路径,解决方法如下:

(1)在Anaconda Prompt中输入语句(对windows而言,linux或Max直接在终端输入查看)

jupyter kernelspec list

查看安装的内核及其位置,如果是反复安装会显示Python2和Python3两个内核及其所在路径

(2)进入内核所在的目录,打开里面的kernel.jason文件,查看Python编译器的路径是否正确

我现在安装的是Anaconda2,所对应的应该是Python2,所以直接把Python3那个文件夹删了,然后打开Python2文件夹中的kernel.jason文件时,发现内核路径是错的:

{
 "display_name": "Python 2", 
 "language": "python", 
 "argv": [
  "C:\\ProgramData\\Anaconda3\\envs\\py2\\python.exe", 
  "-m", 
  "ipykernel_launcher", 
  "-f", 
  "{connection_file}"
 ]
}

我的Anaconda2安装的路径是C:\ProgramData\Anaconda2,其中的python.exe也在此根目录下,所以修改kernel.jason为:

{
 "display_name": "Python 2", 
 "language": "python", 
 "argv": [
  "C:\\ProgramData\\Anaconda2\\python.exe", 
  "-m", 
  "ipykernel_launcher", 
  "-f", 
  "{connection_file}"
 ]
}

保存后重新打开jupyter notebook就不再显示kernel error了。

Anaconda2和Anaconda3反复安装出现的问题的解决方法_第2张图片

注意有可能,你的Kernel还是显示的Kernel error,原因在于你选择的是python3内核,切换到python2就可以了(但如果你像我一样删除了Python3文件夹,jupyter notebook里是不会再显示python3内核的)。

Anaconda2和Anaconda3反复安装出现的问题的解决方法_第3张图片

注:

Anaconda2-4.1.1-Windows-x86_64.exe下载链接

https://download.csdn.net/download/qq_21368481/10298381

Anaconda3-5.1.0-Windows-x86_64.exe下载链接

https://download.csdn.net/download/qq_21368481/10296836



你可能感兴趣的:(python)