pythonxy和spyder无法启动 -- ConfigParser.py中的类型错误

0 投票
1 回答
528 浏览
提问于 2025-05-10 21:08

我之前一直在用Spyder这个工具,今天突然就不能用了。我发现PythonXY文件夹里的其他工具(比如Mayavi、Ipython控制台等)都能正常启动,但PythonXY和Spyder就是启动不了。当我从命令行启动它们时,出现了以下错误信息。有没有什么建议可以解决这个问题?我已经尝试过卸载再重新安装pythonxy/python了。

Traceback (most recent call last):
  File "C:\Python27\Scripts\xyhome.pyw", line 20, in <module>
    from xy import xyhome
  File "C:\Python27\lib\site-packages\xy\xyhome.pyw", line 60, in <module>
    from xy.config import (CONF, STARTUP_PATH, LOG_PATH, PLUGINS, XY_VERSION,
  File "C:\Python27\lib\site-packages\xy\config.py", line 40, in <module>
    CONF = UserConfig('xy', defaults=DEFAULTS, version=__version__, subfolder='.
xy')
  File "C:\Python27\lib\site-packages\xy\userconfig.py", line 110, in __init__
    if version != self.get_version(version):
  File "C:\Python27\lib\site-packages\xy\userconfig.py", line 130, in get_versio
n
    return self.get(self.DEFAULT_SECTION_NAME, 'version', version)
  File "C:\Python27\lib\site-packages\xy\userconfig.py", line 266, in get
    self.set(section, option, default)
  File "C:\Python27\lib\site-packages\xy\userconfig.py", line 332, in set
    self.__save()
  File "C:\Python27\lib\site-packages\xy\userconfig.py", line 167, in __save
    self.write(conf_file)
  File "C:\Python27\lib\ConfigParser.py", line 407, in write
    fp.write("[%s]\n" % section)
TypeError: must be unicode, not str
>>>

当我打印出最后一次调用的userconfig.py中的conf_file时,发现参数似乎是unicode格式:

<_io.TextIOWrapper name=u'C:\\Users\\rclement\\.xy\\.xy.ini' encoding='utf-8'>

我通过删除C:\Python27文件夹和一些非pythonxy安装包留下的子文件夹,成功重新安装了。没有修改注册表,Windows环境的PATH设置也保持不变。我还是不知道问题的原因是什么。

相关文章:

  • 暂无相关问题
暂无标签

1 个回答

0

我对这个错误做了一个快速修复

    for section in self._sections:
        fp.write("[%s]\n" % unicode(section)) #forced conversion to unicode
        for (key, value) in self._sections[section].items():
            if key == "__name__":
                continue
            if (value is not None) or (self._optcre == self.OPTCRE):
                key = " = ".join((key, str(value).replace('\n', '\n\t')))
            fp.write("%s\n" % (unicode(key))) #forced conversion to unicode
        fp.write(u"\n") #forced conversion to unicode

这个快速修复对我有效。不过我不知道问题是怎么产生的。 :-(

撰写回答