TypeError while using 'cd' #2764

Closed
topher200 opened this Issue Jan 9, 2013 · 5 comments

Comments

Projects
None yet
4 participants

I am getting the following error while running the magic 'cd' in ipython:

In [1]: cd ..
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-1-56af63bcfcf6> in <module>()
----> 1 get_ipython().magic(u'cd ..')

C:\Python27\lib\site-packages\IPython\core\interactiveshell.pyc in magic(self, a
rg_s)
   2134         magic_name, _, magic_arg_s = arg_s.partition(' ')
   2135         magic_name = magic_name.lstrip(prefilter.ESC_MAGIC)
-> 2136         return self.run_line_magic(magic_name, magic_arg_s)
   2137
   2138     #-------------------------------------------------------------------
------

C:\Python27\lib\site-packages\IPython\core\interactiveshell.pyc in run_line_magi
c(self, magic_name, line)
   2060                 args.append(sys._getframe(stack_depth).f_locals)
   2061             with self.builtin_trap:
-> 2062                 result = fn(*args)
   2063             return result
   2064

C:\Python27\lib\site-packages\IPython\core\magics\osm.pyc in cd(self, parameter_
s)

C:\Python27\lib\site-packages\IPython\core\magic.pyc in <lambda>(f, *a, **k)
    189     # but it's overkill for just that one bit of state.
    190     def magic_deco(arg):
--> 191         call = lambda f, *a, **k: f(*a, **k)
    192
    193         if callable(arg):

C:\Python27\lib\site-packages\IPython\core\magics\osm.pyc in cd(self, parameter_
s)
    342                 if oldcwd != cwd:
    343                     dhist.append(cwd)
--> 344                     self.shell.db['dhist'] = compress_dhist(dhist)[-100:
]
    345
    346         else:

C:\Python27\lib\site-packages\IPython\utils\pickleshare.py in __setitem__(self,
key, value)
     79         fil = self.root / key
     80         parent = fil.parent
---> 81         if parent and not parent.isdir():
     82             parent.makedirs()
     83         # We specify protocol 2, so that we can mostly go between Python
 2

TypeError: _isdir() takes exactly 1 argument (0 given)

I am running ipython version 0.13.1 for Python 2.7.3 on Windows 7. I got the Windows binary installer from this site: http://www.lfd.uci.edu/~gohlke/pythonlibs/

This patch fixes the issue for me:

From 95c16637375414e90ebe41751fb3d7384368dad8 Mon Sep 17 00:00:00 2001
From: Topher Brown <chris.brown@farsounder.com>
Date: Wed, 9 Jan 2013 18:02:21 -0500
Subject: [PATCH] pickleshare: fix issue with isdir()

---
 IPython/utils/pickleshare.py | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/IPython/utils/pickleshare.py b/IPython/utils/pickleshare.py
index 0d4a443..f66a3aa 100755
--- a/IPython/utils/pickleshare.py
+++ b/IPython/utils/pickleshare.py
@@ -49,8 +49,8 @@ class PickleShareDB(collections.MutableMapping):
     def __init__(self,root):
         """ Return a db object that will manage the specied directory"""
         self.root = Path(root).expanduser().abspath()
-        if not self.root.isdir():
-            self.root.makedirs()
+        if not os.path.isdir(self.root):
+            os.makedirs(self.root)
         # cache has { 'key' : (obj, orig_mod_time) }
         self.cache = {}

@@ -79,8 +79,8 @@ def __setitem__(self,key,value):
         """ db['key'] = 5 """
         fil = self.root / key
         parent = fil.parent
-        if parent and not parent.isdir():
-            parent.makedirs()
+        if parent and not os.path.isdir(parent):
+            os.makedirs(parent)
         # We specify protocol 2, so that we can mostly go between Python 2
         # and Python 3. We can upgrade to protocol 3 when Python 2 is obsolete.
         with fil.open('wb') as f:
@@ -94,8 +94,8 @@ def __setitem__(self,key,value):
     def hset(self, hashroot, key, value):
         """ hashed set """
         hroot = self.root / hashroot
-        if not hroot.isdir():
-            hroot.makedirs()
+        if not os.path.isdir(hroot):
+            os.makedirs(hroot)
         hfile = hroot / gethashfile(key)
         d = self.get(hfile, {})
         d.update( {key : value})
-- 
1.7.11.msysgit.1

I got the idea for the solution from http://superuser.com/questions/318655/error-running-ipython3-on-xp-typeerror-isdir-takes-exactly-1-argument-0-gi

Contributor

bfroehle commented Jan 10, 2013

@topher200: What does the following return, if anything?

import path
print(path.__file__)
print(path.__version__)
Contributor

bfroehle commented Jan 10, 2013

This looks like a duplicate of #737 -- which is surprising since that issue was resolved over a year ago.

Owner

takluyver commented Jan 10, 2013

If you have an older version of path.py installed on your system, that could still have the bug. You could upgrade it, or uninstall it so that IPython uses its bundled copy.

Good call - print(path.__file__) returns an older, local version of path.py. With it removed, unmodified ipython works perfectly. Thanks!

@topher200 topher200 closed this Jan 10, 2013

@minrk minrk added this to the no action milestone Mar 26, 2014

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment