# Buggy code
def add_path(self):
    self.redirect_stdio.emit(False)
    directory = getexistingdirectory(self, _("Select directory"), self.last_path)
    self.redirect_stdio.emit(True)
    if directory:
        directory = osp.abspath(directory)
        self.last_path = directory
        if directory in self.pathlist:
            item = self.listwidget.findItems(directory, Qt.MatchExactly)[0]
            item.setCheckState(Qt.Checked)
            answer = QMessageBox.question(
                self,
                _("Add path"),
                _(
                    "This directory is already included in Spyder path "
                    "list.<br>Do you want to move it to the top of "
                    "the list?"
                ),
                QMessageBox.Yes | QMessageBox.No,
            )
            if answer == QMessageBox.Yes:
                self.pathlist.remove(directory)
            else:
                return
        self.pathlist.insert(0, directory)
        self.update_list()


# Traceback (UnicodeDecodeError)
File "C:\Users\AADL\Anaconda3\envs\python2_14\lib\site-packages\spyder\plugins\__init__.py", line 514, in <lambda>
toggled=lambda checked: self.toggle_view(checked),
File "C:\Users\AADL\Anaconda3\envs\python2_14\lib\site-packages\spyder\plugins\ipythonconsole.py", line 725, in toggle_view
self.create_new_client(give_focus=False)
File "C:\Users\AADL\Anaconda3\envs\python2_14\lib\site-packages\spyder\plugins\ipythonconsole.py", line 1046, in create_new_client
self.connect_client_to_kernel(client, is_cython=is_cython)
File "C:\Users\AADL\Anaconda3\envs\python2_14\lib\site-packages\spyder\plugins\ipythonconsole.py", line 1074, in connect_client_to_kernel
is_cython=is_cython)
File "C:\Users\AADL\Anaconda3\envs\python2_14\lib\site-packages\spyder\plugins\ipythonconsole.py", line 1498, in create_kernel_manager_and_kernel_client
if not kernel_spec.env.get('PYTHONPATH'):
File "C:\Users\AADL\Anaconda3\envs\python2_14\lib\site-packages\spyder\utils\ipython\kernelspec.py", line 91, in env
drop_env=(not default_interpreter))
File "C:\Users\AADL\Anaconda3\envs\python2_14\lib\site-packages\spyder\utils\misc.py", line 256, in add_pathlist_to_PYTHONPATH
pypath =  {'PYTHONPATH': pathstr + os.pathsep + old_pypath,
UnicodeDecodeError: 'ascii' codec can't decode byte 0xb0 in position 59: ordinal not in range(128)

# Fixed code
def add_path(self):
    self.redirect_stdio.emit(False)
    directory = getexistingdirectory(self, _("Select directory"), self.last_path)
    self.redirect_stdio.emit(True)
    if directory:
        is_unicode = False
        if PY2:
            try:
                directory.decode("ascii")
            except UnicodeEncodeError:
                is_unicode = True
            if is_unicode:
                QMessageBox.warning(
                    self,
                    _("Add path"),
                    _(
                        "You are using Python 2 and the path"
                        " selected has Unicode characters. "
                        "The new path will not be added."
                    ),
                    QMessageBox.Ok,
                )
                return
        directory = osp.abspath(directory)
        self.last_path = directory
        if directory in self.pathlist:
            item = self.listwidget.findItems(directory, Qt.MatchExactly)[0]
            item.setCheckState(Qt.Checked)
            answer = QMessageBox.question(
                self,
                _("Add path"),
                _(
                    "This directory is already included in Spyder "
                    "path list.<br>Do you want to move it to the "
                    "top of the list?"
                ),
                QMessageBox.Yes | QMessageBox.No,
            )
            if answer == QMessageBox.Yes:
                self.pathlist.remove(directory)
            else:
                return
        self.pathlist.insert(0, directory)
        self.update_list()