简体   繁体   中英

Why do I get error when trying to change directory to the mounted drive in Google Colab?

When using the command

        %cd '/content/gdrive/MyDrive/'

I get the error:

        ERROR:root:Internal Python error in the inspect module.
        Below is the traceback from this internal error.

        Traceback (most recent call last):
          File "/usr/local/lib/python3.6/dist-packages/IPython/core/interactiveshell.py", line 2882, in 
        run_code
            exec(code_obj, self.user_global_ns, self.user_ns)
          File "<ipython-input-48-1d7f4f899579>", line 1, in <module>
            get_ipython().magic("cd '/content/gdrive/MyDrive/'")
          File "/usr/local/lib/python3.6/dist-packages/IPython/core/interactiveshell.py", line 2160, in 
        magic
            return self.run_line_magic(magic_name, magic_arg_s)
          File "/usr/local/lib/python3.6/dist-packages/IPython/core/interactiveshell.py", line 2081, in 
        run_line_magic
            result = fn(*args,**kwargs)
          File "<decorator-gen-91>", line 2, in cd
          File "/usr/local/lib/python3.6/dist-packages/IPython/core/magic.py", line 188, in <lambda>
             call = lambda f, *a, **k: f(*a, **k)
          File "/usr/local/lib/python3.6/dist-packages/IPython/core/magics/osm.py", line 288, in cd
            oldcwd = py3compat.getcwd()
        FileNotFoundError: [Errno 2] No such file or directory

        During handling of the above exception, another exception occurred:

        Traceback (most recent call last):
          File "/usr/local/lib/python3.6/dist-packages/IPython/core/interactiveshell.py", line 1823, in 
        showtraceback
            stb = value._render_traceback_()
          AttributeError: 'FileNotFoundError' object has no attribute '_render_traceback_'

        During handling of the above exception, another exception occurred:

        Traceback (most recent call last):
          File "/usr/local/lib/python3.6/dist-packages/IPython/core/ultratb.py", line 1132, in 
        get_records
            return _fixed_getinnerframes(etb, number_of_lines_of_context, tb_offset)
          File "/usr/local/lib/python3.6/dist-packages/IPython/core/ultratb.py", line 313, in wrapped
            return f(*args, **kwargs)
          File "/usr/local/lib/python3.6/dist-packages/IPython/core/ultratb.py", line 358, in 
        _fixed_getinnerframes
            records = fix_frame_records_filenames(inspect.getinnerframes(etb, context))
          File "/usr/lib/python3.6/inspect.py", line 1490, in getinnerframes
            frameinfo = (tb.tb_frame,) + getframeinfo(tb, context)
          File "/usr/lib/python3.6/inspect.py", line 1448, in getframeinfo
            filename = getsourcefile(frame) or getfile(frame)
           File "/usr/lib/python3.6/inspect.py", line 696, in getsourcefile
              if getattr(getmodule(object, filename), '__loader__', None) is not None:
             File "/usr/lib/python3.6/inspect.py", line 725, in getmodule
          file = getabsfile(object, _filename)
          File "/usr/lib/python3.6/inspect.py", line 709, in getabsfile
                return os.path.normcase(os.path.abspath(_filename))
          File "/usr/lib/python3.6/posixpath.py", line 383, in abspath
               cwd = os.getcwd()
          FileNotFoundError: [Errno 2] No such file or directory
---------------------------------------------------------------------------

It was working fine before but when I removed one folder and added one, it started to show this error.

There is a space in between My Drive .

Try using:

%cd '/content/gdrive/My Drive/'

or

%cd '/content/gdrive/My\ Drive/'

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM