Skip to content

Commit

Permalink
Update Google_Colab.md
Browse files Browse the repository at this point in the history
Table of contents modified + new subtopics
  • Loading branch information
WellcomeConnectingScienceAdmin authored Oct 23, 2024
1 parent 9e47389 commit c799b1d
Showing 1 changed file with 139 additions and 34 deletions.
173 changes: 139 additions & 34 deletions Google_Colab.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,43 @@
[Wellcome Connecting Science GitHub Home Page](https://github.com/WCSCourses) <br />
[Wellcome Connecting Science Website](https://coursesandconferences.wellcomeconnectingscience.org/)

## Table of Contents:
1. [What is Google Colab?](#what-is-google-colab)
2. [How Does Google Colab Work?](#how-does-google-colab-work)
3. [Getting Started with Google Colab](#getting-started-with-google-colab)
4. [Using Google Colab for Python](#google-colab-for-python)
5. [Using R in Google Colab](#using-r-in-google-colab)
6. [Conda Installation in Google Colab](#conda-installation-in-google-colab)
7. [Using the Terminal in Google Colab](#using-the-terminal-in-google-colab)
8. [Helpful Links](#helpful-links)
9. [Helpful Communities](#helpful-communities)

## What is Google Colab?
## Table of Contents
1. [What is Google Colab?](#1-what-is-google-colab)
2. [How Does Google Colab Work?](#2-how-does-google-colab-work)
3. [Getting Started with Google Colab](#3-getting-started-with-google-colab)
4. [Using Google Colab for Python](#4-using-google-colab-for-python)
a. [Opening Google Colab](#a-opening-google-colab)
b. [Running Python Code](#b-running-python-code)
c. [Using GPU/TPU](#c-using-gputpu)
5. [Using R in Google Colab](#5-using-r-in-google-colab)
a. [Installing R](#a-installing-r)
b. [Running R Code](#b-running-r-code)
6. [Conda Installation in Google Colab](#6-conda-installation-in-google-colab)
a. [Install Miniconda](#a-install-miniconda)
b. [Initialize Conda](#b-initialize-conda)
c. [Creating a Conda Environment](#c-creating-a-conda-environment)
7. [Using the Terminal in Google Colab](#7-using-the-terminal-in-google-colab)
a. [Open Terminal](#a-open-terminal)
b. [Running Commands](#b-running-commands)
8. [Managing Files in Google Colab](#8-managing-files-in-google-colab)
a. [Different Ways to Add Files in Google Colab](#a-different-ways-to-add-files-in-google-colab)
- [Upload from Local Machine](#upload-from-local-machine)
- [Mount Google Drive](#mount-google-drive)
- [Use GitHub Repositories](#use-github-repositories)
- [Download from a URL](#download-from-a-url) </br>
b. [Zipping Files](#b-zipping-files)
c. [Unzipping Files](#c-unzipping-files)
d. [Adding Data Before Zipping](#d-adding-data-before-zipping)
10. [Google Colab Frequently Asked Questions (FAQs)](#9-google-colab-frequently-asked-questions-faqs)
11. [Helpful Links](#10-helpful-links)
12. [Helpful Communities](#11-helpful-communities)


## 1. What is Google Colab?

Google Colab, or "Collaboratory," is a cloud-based platform that allows you to write and execute Python code in a web browser. It is particularly popular for data analysis, machine learning, and artificial intelligence projects because it provides free access to powerful computing resources, including GPUs and TPUs.

## How Does Google Colab Work?
## 2. How Does Google Colab Work?

Google Colab integrates seamlessly with Google Drive, making it easy to save and share your notebooks. Each notebook consists of code cells and text cells, allowing you to combine code, comments, and visualizations. Colab supports various Python libraries and frameworks, enabling you to run code without needing to set up a local environment.

Expand All @@ -29,49 +50,49 @@ Key features of Google Colab include:
- **Pre-installed Libraries:** Colab comes with many popular libraries pre-installed, such as TensorFlow, NumPy, and Pandas.
- **Easy Integration:** You can easily import datasets from Google Drive, GitHub, and other sources.

## Getting Started with Google Colab
## 3. Getting Started with Google Colab

To get started with Google Colab using a shared link from Google Drive:

1. **Open the Shared Link:** Click on the shared link provided to you. It will usually look like this: `https://drive.google.com/file/d/...`.
a. **Open the Shared Link:** Click on the shared link provided to you. It will usually look like this: `https://drive.google.com/file/d/...`.

2. **Make a Copy:** If the link opens a view-only version of the notebook, you can create your own editable copy by selecting **File > Save a copy in Drive**. This will save the notebook to your Google Drive.
b. **Make a Copy:** If the link opens a view-only version of the notebook, you can create your own editable copy by selecting **File > Save a copy in Drive**. This will save the notebook to your Google Drive.

3. **Open Your Copy:** Once the copy is saved, you can open it from your Google Drive. You can also access it anytime through Google Colab by selecting **File > Open notebook** and navigating to your Drive.
c. **Open Your Copy:** Once the copy is saved, you can open it from your Google Drive. You can also access it anytime through Google Colab by selecting **File > Open notebook** and navigating to your Drive.

---

## Google Colab for Python
## 4. Using Google Colab for Python

Google Colab allows you to write and execute Python code in the cloud, with access to free GPUs and TPUs. Here’s a quick start guide for Python in Colab.

### 1. Opening Google Colab
### a. Opening Google Colab

- Go to [Google Colab](https://colab.research.google.com/).
- Select **File > New notebook** to create a new notebook.

### 2. Running Python Code
### b. Running Python Code

Create a code cell and run:

```python
print("Hello, Colab!")
```
### 3. Using GPU/TPU
### c. Using GPU/TPU
Enable GPU/TPU by going to **Runtime > Change runtime type** and selecting **GPU** or **TPU**.

---

### Using R in Google Colab
### 5. Using R in Google Colab
You can use R in Google Colab by installing the necessary packages and changing the runtime.

#### 1. Installing R
#### a. Installing R
In a code cell, run the following command to install R:

```bash
!apt-get install r-base
```
#### 2. Running R Code
#### b. Running R Code
After installing R, you can run R code by prefixing your code cell with %%R. For example:

```bash
Expand All @@ -81,58 +102,142 @@ print("Hello, R in Colab!")

---

### Conda Installation in Google Colab
### 6. Conda Installation in Google Colab
You can install Conda in Google Colab to manage your Python packages and environments. Follow these steps:

#### 1. Install Miniconda
#### a. Install Miniconda
In a code cell, run the following command to install Miniconda:

```bash
!wget -qO- https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh | bash
```

#### 2. Initialize Conda
#### b. Initialize Conda
After installation, initialize Conda with:

```bash
import sys
!conda init
```

#### 3. Creating a Conda Environment
#### c. Creating a Conda Environment
Create a new environment by running:

```bash
!conda create --name myenv python=3.8
```

#### Activate the environment:
#### d. Activate the environment:

```bash
!source activate myenv
```

---
### Using the Terminal in Google Colab
### 7. Using the Terminal in Google Colab
You can access the terminal in Google Colab by using the following command:

#### 1. Open Terminal
#### a. Open Terminal
In a code cell, run:

```bash
!bash
```
This will open a terminal session where you can execute standard Linux commands.

#### 2. Running Commands
#### b. Running Commands
You can run any command as you would in a typical terminal environment. For example:

```bash
ls
```
---

## Helpful Links
## 8. Managing Files in Google Colab

#### a. Different Ways to Add Files in Google Colab
#### Upload from Local Machine:

To upload files directly from your local machine to Google Colab, use the following code:

```bash
from google.colab import files
uploaded = files.upload()
```

#### Mount Google Drive:

You can mount your Google Drive to access files stored there. Use the following code to do this:

```bash
from google.colab import drive
drive.mount('/content/drive')
```
After executing this, you’ll need to follow the authorization steps. Once mounted, you can access your Google Drive files under the /content/drive directory.

#### Use GitHub Repositories:

You can clone a GitHub repository to access files directly. Use the following command:

```bash
!git clone https://github.com/username/repo.git
```
Replace the username and repo with the appropriate GitHub username and repository name.

#### Download from a URL:

If you have a direct link to a file, you can use wget or curl to download it:
```bash
!wget 'http://example.com/path/to/file'
```
or

```bash
!curl -O 'http://example.com/path/to/file'
```

#### b. Zipping Files
You can zip files or folders in Google Colab using the following command:

```bash
!zip -r '/content/folder/filename.zip' /path/to/folder
```
This will create a zip file called filename.zip in the /content/folder/ directory.

#### c. Unzipping Files
To unzip a file in Google Colab, use the following command:

```bash
!unzip /path/to/file.zip
```
This will extract the contents of the zip file.

#### d. Adding Data Before Zipping
To add data to a zip file, move the necessary files or directories into a folder, and then zip the entire folder. For example:

```bash
!mkdir /content/folder
!cp /path/to/file /content/folder
!zip -r '/content/folder/filename.zip' /content/folder
```
This will copy the file to a folder and then zip the entire folder.

### 9. Google Colab Frequently Asked Questions (FAQs)

Q: How long can I run my notebook?
A: The maximum runtime per session is 12 hours. You can restart the session if needed.

Q: What happens if I leave my notebook idle?
A: After 90 minutes of inactivity, Colab will stop the session. You will need to reconnect and rerun your code.

Q: Can I save my work if my session stops?
A: Yes, save your notebooks to Google Drive or manually download files before the session expires.

Q: Can I increase the runtime limit?
A: Google Colab has a fixed runtime limit of 12 hours per session. You cannot extend this limit, but you can reconnect and restart the session.

---
## 10. Helpful Links

- [Google Colab Documentation](https://colab.research.google.com/notebooks/welcome.ipynb)
Official documentation to help you get started with Google Colab.
Expand All @@ -150,7 +255,7 @@ Feel free to reach out if you have any questions or need further assistance!

---

## Helpful Communities
## 11. Helpful Communities

- [Stack Overflow](https://stackoverflow.com/questions/tagged/google-colaboratory)
A large community for developers and data scientists to ask questions about Google Colab.
Expand Down

0 comments on commit c799b1d

Please sign in to comment.