What happens when you type !ls or !pwd or any shell command on Google Colab? - jupyter-notebook

So while I was working on an online project on Google Colab I had to run some model which was automatically saved on Colab (wherever that was). On looking it up (using !ls) it was being saved in the '/content' directory which had some other files that were downloaded to Colab as a part of the project. Opening another notebook and running !ls on it showed the same but an empty '/content' directory. I noticed '/content' is also the default PWD and loading from google drive is through '/content/drive/My Drive'. So what is '/content' and the exact file structure working behind Google Colab and how? Can I transfer files from one notebook to another? Also any resources for more information on the same would be appreciated. Thanks.

/content on 2 notebooks are not the same. Because each notebook runs on a new computer in the cloud.
But if you mount drive, the directory /content/drive/My Drive will be the same. You can use it to transfer files between 2 notebooks.

Related

How to solve _netrc file issue while using NASAaccess package?

I wish to use the NASAaccess tool in R. I have installed the curl software in my system, and also have created the _netrc file in the home directory as instructed (including teh _netrc, .netrc, .urscookie). However when I try to run the code it asks to create the netrc files in the home directory which I have already done. What should be the problem here?
I re-installed the curl software, re-wrote the files in the home directory, praded the R version. It should have worked by now providing the rainfall data output.

How to open a local Jupyter Notebook directly on Google Colab without going for the extra step of uploading it on Google Drive?

I would like to load my jupyter notebook from my local repo directly on Colab, without uploading it first on GDrive. I'm well aware of the possibility to open Github notebooks directly on Colab, but that's not what I'm trying to make, since I would like to directly open notebooks from my local repo and then have the freedom to commit and push whenever I want. Is this possible or do I have to just give up and upload a copy on GDrive and then download the .ipynb everytime I want to save locally?
You can use my library to open Jupyter Notebook and open any local notebook in the same machine instance.
!pip install kora -q
from kora import jupyter
jupyter.start()
Then click the shown link. It should list local ipynb files. You can then click them to open and edit the files directly.

Download code from GCloud VM instance with expired RStudio Server license

I had created a Google compute engine (virtual machine) instance with RStudio Server being unaware that RStudio Server is a licensed software. Now, my trial license for RStudio has expired, and I cannot login to my R sessions anymore.
However, I had written some code which I need to recover. How do I download the files?
I have SSH-ed into my virtual machine but cannot find the relevant files or a way to download them.
I had a similar issue and I was able to recover the files by performing the following steps:
SSH to the virtual machine
Once you are in the virtual machine run the following command: cd ../rstudio-user/
Now ls there you will see the file structure you used to see in the RStudio Server interface}
Navigate using cd and ls between the folders to get to the desired file
Once you are in the desired location (where with an ls you can see the files you want to recover) run the following command: pwd
Click on the Engine and go to download file
Enter the full path of the file you want to download, it will be something like: /home/rstudio-user/FILENAME.R
Click on Download
You can do this for each of the files you want to recover.
In case you want to recover a full folder its easier to compress to a zip file and then to download it.

error loading jupyter notebook permission denied: ipynb

I was working in a jupyter notebook until it froze. It wouldn't save or shut down so I restarted my computer. I launched jupyter notebook from an anaconda prompt, my folder directory opens per usual. When i tried to open the notebook from before, I get an error loading screen that says permission denied: (name of notebook).ipynb. I hit close and the notebook shuts down.
I checked the folder permissions, I have full control. I can create a new ipynb without any issues. I can open other notebooks without any problem in the same folder. I tried to run a trust notebook through the anaconda prompt and it says the notebook is missing.
I need to recover this particular notebook as it has all my work. Help! Any ideas? Thanks in advance.
I work in the anaconda prompt in an environment other than the root, so this answer using sudo chmod doesn't work for me.
I had possibly the same problem. In my case the problem was that jupyter notebook must have crashed or had some problem whilst autosaving.
As a result, in the folder where the notebook is saved there's a temporary file called ".~nameofnotebook.ipynb".
This file didn't show up in jupyter notebook, but only in the explorer. I deleted the notebook file and renamed the temporary file to delete the ".~" prefix. Make sure to save a copy of the notebook file before deleting anything in case your problem is different.
The renamed temporary file opens fine and none of my data was lost.
Change the name of the file and you are good to go bro..

Repair corrupted Jupyter notebook / load previous version?

I had a hardware crash while running a Jupyter notebook. After repairing the system and trying to restart the notebook, I got the following error message:
Error loading notebook
Unreadable Notebook: D:\Eddy\Documents\1604 Udacity\1612 Self-driving car Nanodegree\P4\P4 Eduard van Kleef.ipynb NotJSONError("Notebook does not appear to be JSON: ''...",)
Does anyone know of a way to revert to any of Jupyter's previous 'checkpoints'? Or of a way to at least partially restore a JSON?
If you are lucky then the ipynb file is corrupted but still there. In that case you can try opening it in a text file and copying the contents to a new notebook. But check the size of the file. If it is zero bytes, then there is nothing there!
This actually happened to me when my server ran out of memory and somehow the notebook got completely erased. Totally sucks.
Try this
jupyter nbconvert filename.ipynb --clear-output
It worked for me since it has corrupted because of Plotly behavior with some big data.
in your file directory that contains your ipynb file there is a folder called '.ipynb_checkpoints'. this folder does not show in the jupyter application so find it through windows explorer.
inside there's will be a file called urfilenamehere-checkpoint.ipynb
copy paste it to your file directory and open through the jupyter application it should probably work.
if your corrupted file is 0B, you definitely have to rely on the checkpoints.
do not create a new notebook with the same name it will overwrite the checkpoint.

Resources