在 XP 上运行 IPython3 时出错:TypeError:_isdir() 需要 1 个参数(给出了 0 个)

在 XP 上运行 IPython3 时出错:TypeError:_isdir() 需要 1 个参数(给出了 0 个)

<UPDATE>从来没有让 IPython3 在 Windows 下工作过,但我设法让它在我的本地 CentOS 服务器上工作(经过多次挫折),最终发现了绝对不可或缺的虚拟环境工具。不确定 virtualenv 是否也能在 Windows 上发挥其魔力,但目前我满足于通过 SSH 使用 IPython。</UPDATE>

我是 Python 新手,决定尝试 Python 3.2。我喜欢该语言带有内置交互式解释器,但我正在寻找功能更齐全的东西,而 IPython 看起来符合要求。我安装了 Distribute,并从我的 C:\Python32\Scripts\ 目录中使用以下命令来获取 egg:

easy_install http://archive.ipython.org/release/0.11/py3/ipython-0.11-py3.2.egg

这已成功完成,尽管输出已超出我的回滚阈值,因此我无法在此处生成它。我运行ipython3 --help并生成了帮助屏幕,因此我知道至少部分内容已正确安装。但是,当我执行时,ipython3我收到以下错误:

$ ipython3
Error in sys.excepthook:
TypeError: _isdir() takes exactly 1 argument (0 given)

Original exception was:
Traceback (most recent call last):
  File "c:\Python32\Scripts\ipython3-script.py", line 9, in <module>
    load_entry_point('ipython==0.11', 'console_scripts', 'ipython3')()
  File "C:\Python32\lib\site-packages\ipython-0.11-py3.2.egg\IPython\frontend\terminal\ipapp.py", line 369, in launch_new_instance
    app.initialize()
  File "C:\Python32\lib\site-packages\ipython-0.11-py3.2.egg\IPython\frontend\terminal\ipapp.py", line 283, in initialize
    self.init_shell()
  File "C:\Python32\lib\site-packages\ipython-0.11-py3.2.egg\IPython\frontend\terminal\ipapp.py", line 303, in init_shell
    ipython_dir=self.ipython_dir)
  File "C:\Python32\lib\site-packages\ipython-0.11-py3.2.egg\IPython\config\configurable.py", line 295, in instance
    inst = cls(*args, **kwargs)
  File "C:\Python32\lib\site-packages\ipython-0.11-py3.2.egg\IPython\frontend\terminal\interactiveshell.py", line 112, in __init__
    user_global_ns=user_global_ns, custom_exceptions=custom_exceptions
  File "C:\Python32\lib\site-packages\ipython-0.11-py3.2.egg\IPython\core\interactiveshell.py", line 384, in __init__
    self.db = PickleShareDB(os.path.join(self.profile_dir.location, 'db'))
  File "C:\Python32\lib\site-packages\ipython-0.11-py3.2.egg\IPython\utils\pickleshare.py", line 52, in __init__
    if not self.root.isdir():
TypeError: _isdir() takes exactly 1 argument (0 given)

除此之外,--help我还没有找到任何其他不会产生此错误的参数。我在 C:\Python32\lib\site-packages\ipython-0.11-py3.2.egg\IPython\ 中搜索了“_isdir”,在名为 tempdir.py 的文件中只找到了两个对它的引用,均显示在此处:

# XXX (ncoghlan): The following code attempts to make
# this class tolerant of the module nulling out process
# that happens during CPython interpreter shutdown
# Alas, it doesn't actually manage it. See issue #10188
_listdir = staticmethod(_os.listdir)
_path_join = staticmethod(_os.path.join)
_isdir = staticmethod(_os.path.isdir)
_remove = staticmethod(_os.remove)
_rmdir = staticmethod(_os.rmdir)
_os_error = _os.error

def _rmtree(self, path):
    # Essentially a stripped down version of shutil.rmtree.  We can't
    # use globals because they may be None'ed out at shutdown.
    for name in self._listdir(path):
        fullname = self._path_join(path, name)
        try:
            isdir = self._isdir(fullname)

在同一目录中搜索“isdir”会返回大约 100 个匹配项;其中大约 50% 使用 1 个参数,其余 0 个。我不确定这是继承或范围的问题还是其他问题,也不知道前面的下划线的重要性。谷歌搜索“TypeError: _isdir()”不会返回任何匹配项。

有任何想法吗?

答案1

最后决定再试一次,并成功了。解决方案是更改文件中的两行ipython-0.11-py3.2.egg\IPython\utils\pickleshare.py,即第 52 行:

前:

if not self.root.isdir():
    self.root.makedirs()

后:

if not os.path.isdir(self.root):
    os.makedirs(self.root)

相关内容