'Change directory in Jupyter Lab not working
Solution 1:[1]
The !cd datasets
command did work. However, you aren't understanding what is going on with the use of the exclamation point. What the exclamation point does is open a separate temporary shell instance and does work returning what gets returned. The separate shell instance goes away. Poof
What you were trying to do was change the working directory within your notebook. And so you wanted to use:
%cd dataset
You'll want to learn about the many IPython/ Jupyter magic commands and use them. See here for the IPython ones that Jupyter inherits as Jupyter grew out of the IPython notebook project and so when using a Python-based kernel, you have those utilities. There are some others that are cell and line specific and specific to Jupyter. Here looks like good overview of this.
Note that generally in modern Jupyter, auto-magics is enabled by default. For all the shell commands you show in your post, you want to use the magic command equivalents. And so you are better off trying without any symbol first. Auto-magics will usually add the %
behind the scenes. If that fails, then add the %
if you are sure there is a magic equivalent that is the same as a shell command because maybe automagics aren't on by default on the system you are on. Finally, some of the similar tasks you'd perform in the shell have different syntax as a magic command in IPython/Jupyter. The example of the %store
line magic comes to mind. It makes sense it is different though because the main thing it does is different than shell. However, there is dome overlap with abilities the shell has. For example %store foo >a.txt
that lets you send a value of a Python variable directly into a text file. (Note that it doesn't allow a space after the redirect symbol! Unlike shell.)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 |