-
Notifications
You must be signed in to change notification settings - Fork 96
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #44 from tomvannuenen/master
naming edits
- Loading branch information
Showing
107 changed files
with
127,211 additions
and
0 deletions.
There are no files selected for viewing
122 changes: 122 additions & 0 deletions
122
1 Installation and Reproducible Data Science/1-1 Anaconda Installation.ipynb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"# [Computational Social Science] \n", | ||
"## 1-1 Anaconda Installation Instructions!\n", | ||
"\n", | ||
"This is a guide to help you properly install and set up Anaconda for the course -- you will want to have this done before you come to the next class so that you will have access to the first lab of the class! \n", | ||
"\n", | ||
"---\n", | ||
"\n", | ||
"### I. Installation Steps:\n", | ||
"\n", | ||
"1. Go to https://www.anaconda.com/download/\n", | ||
"\n", | ||
"2. Choose appropriate operating system and download **Python 3.8 version**\n", | ||
"\n", | ||
"3. Follow the installation instructions\n", | ||
"<div class=\"alert alert-block alert-info\">\n", | ||
"<b>IMPORTANT:</b> If you are a **Windows** user, choose to *also* install **Anaconda Prompt** -- this will be your terminal from which you will activate virtual environments and access your labs.\n", | ||
"</div>\n", | ||
"\n", | ||
"\n", | ||
"4. To verify that Anaconda has been installed, open up your terminal and \\*\\*run the following command: `conda --version`\n", | ||
"\n", | ||
"(\\*\\*type the exact command as written and hit enter)\n", | ||
"\n", | ||
"If your installation was successful, your message should say `conda` with the version number of your Anaconda. If you get an error at this point, please reach out to the GSI.\n", | ||
"\n", | ||
"\n", | ||
"---\n", | ||
"### II. Set-Up: Creating a Virtual Environment\n", | ||
"\n", | ||
"We create virtual environments to use different version of applications and libraries. Virtual environments allow you to use isolated python environments to install different versions of libraries. Here, we will make a new virtual environment called `legal-studies` and show you how to activate/deactive it.\n", | ||
"\n", | ||
"**Steps:**\n", | ||
"1. Open your Terminal (for Windows, open Anaconda Prompt)\n", | ||
"2. In your terminal, run the command:\n", | ||
" `conda create -n legal-studies python=3 anaconda`\n", | ||
" \n", | ||
" You've now created your virtual environment!\n", | ||
"3. To activate this virtual environment, run: \n", | ||
" - on Mac or Linux: `source activate legal-studies`\n", | ||
" - on Windows: `activate legal-studies`\n", | ||
"4. To deactivate virtual environment: \n", | ||
" - Mac or Linux: `source deactivate`\n", | ||
" - Windows: `deactivate`\n", | ||
" \n", | ||
" \n", | ||
"Remember to always activate your virtual environment first before you install packages or run a notebook! This prevents the potential of crashing your root Python/Anaconda installation.\n", | ||
"\n", | ||
"### III. Navigating Your Directories\n", | ||
"\n", | ||
"At this point, you can run the command to start your Jupyer Notebook server. However, it will open in your home directory and you will have to click through your folders to find the file you want to open. To prevent this, you can **navigate to the desired directory first** in the terminal, and open the server to that directory.\n", | ||
"\n", | ||
"A \"directory\" is just another term for \"folder\" -- your Desktop folder is a directory, as are your Downloads, Documents, and OneDrive folders. All you are doing here is laying out the path you will take from your home directory to whichever folder you want to work from.\n", | ||
"\n", | ||
"Here are some basic commands in the terminal:\n", | ||
"\n", | ||
"- `cd <path to directory>`: you can navigate through your directories from your root with the `cd` command by specifying a path to your desired directory.\n", | ||
" - e.g. If your home directory contains your 'Desktop' folder, `cd Desktop` takes you from Home to your Desktop directory.\n", | ||
" - e.g. If your 'Desktop' folder contains folder 'GoBears' which contains the folder 'Oski', the following command from your Home Directory takes you to the Oski folder: `cd Desktop/GoBears/Oski`\n", | ||
"- `cd ..`: this allows you to go back to the previous directory (called the parent directory)\n", | ||
" - e.g. 'GoBears' is the parent folder of 'Oski', so from the 'Oski' folder, `cd ..` will take you to the 'GoBears' folder.\n", | ||
"- `ls` or `dir`: lists all folders/files in the current directory. This is a good way to check, for example, if your parent folder contains your Desktop folder.\n", | ||
"\n", | ||
"Now you know how to navigate directories from your terminal! Find your desired directory **before** you run the JupyterHub Server to prevent clicking through layers of folders. \n", | ||
"\n", | ||
"---\n", | ||
"### Run Your First Notebook!\n", | ||
"\n", | ||
"Anaconda comes with Jupyter Notebooks which is what we will use throughout this course for all of our labs. In order to run your first notebook:\n", | ||
"\n", | ||
"1. Open your terminal (for Windows users, use Anaconda Prompt)\n", | ||
"\n", | ||
"2. Activate your virtual environment\n", | ||
"\n", | ||
"3. Navigate to your desired directory\n", | ||
"\n", | ||
"4. Run the following command on your terminal: `jupyter notebook`\n", | ||
"\n", | ||
"Your default browser window will open, and you should be in your specified directory. From here, you can create a new notebook, open and edit saved notebooks, and much, much more!\n", | ||
"\n", | ||
"To close the notebook server (and shut down all running notebooks), run the command: `jupyter notebook stop` OR simply hit `Ctrl + c` in your terminal.\n", | ||
"\n", | ||
"---\n", | ||
"\n", | ||
"Borrowed from [Legal Studies 123: Data, Prediction, and Law](https://github.com/Akesari12/LS123_Data_Prediction_Law_Spring-2019/tree/master/labs/Anaconda%20Installation%20Guide)\n" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "Python 3", | ||
"language": "python", | ||
"name": "python3" | ||
}, | ||
"language_info": { | ||
"codemirror_mode": { | ||
"name": "ipython", | ||
"version": 3 | ||
}, | ||
"file_extension": ".py", | ||
"mimetype": "text/x-python", | ||
"name": "python", | ||
"nbconvert_exporter": "python", | ||
"pygments_lexer": "ipython3", | ||
"version": "3.8.5" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 4 | ||
} |
110 changes: 110 additions & 0 deletions
110
1 Installation and Reproducible Data Science/1-2 Command Line Intro.m
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
# [Computational Social Science] | ||
## 1-2 Command Line Intro | ||
|
||
|
||
# Working With The Command Line | ||
|
||
You are probably used to interacting with your computer with **Graphical User Interfaces (GUIs)**. GUIs can make understanding and using software easy and intuitive, but come with some limitations too. Another way to interact with your computer is through the **Command Line Interface (CLI)**. CLIs allow you to interact with your computer directly through code. This feature has important implications for reproducibility and scientific research. Working with CLIs will enable you to work with big data, replicate code pipelines easily, and collaborate with other researchers efficiently. | ||
|
||
## Instructions for Windows | ||
|
||
Before we start with using the command line, Windows users will need to go through a couple of extra installation steps. macOS and Linux users can skip this section. Windows native command line, [Command Prompt](https://docs.microsoft.com/en-us/windows-server/administration/windows-commands/windows-commands) has some unique syntax and may not work with everything we'll do in this course. Instead, we recommend installing [Git Bash](https://gitforwindows.org/). There are other options for Windows command line as well, but we recommend starting with Git Bash to make sure you have all of the git tools we'll need when we introduce GitHub. The steps for installation are: | ||
|
||
1. Navigate to the [git for windows webpage](https://gitforwindows.org/), and click the "Download" buttom. | ||
|
||
![Download Git for Windows](https://github.com/dlab-berkeley/Computational-Social-Science-Training-Program/blob/master/images/Install_Git_for_Windows.png) | ||
|
||
2. Run the Git installer. For the most part, keep the defaults that the installer recommends. Importantly, you should make sure to keep the recommended settings for adding git to your PATH, and keeping the default behavior of git pull. The installer may ask if you want to install some beta features as well, we recommend not doing so as this could introduce some bugs. | ||
|
||
![Click Next Through the Installer Options](https://github.com/dlab-berkeley/Computational-Social-Science-Training-Program/blob/master/images/Git%20Installer.png) | ||
|
||
|
||
![Make sure Git is in your PATH](https://github.com/dlab-berkeley/Computational-Social-Science-Training-Program/blob/master/images/Git%20in%20PATH.png) | ||
|
||
|
||
![Keep the default "git pull" option](https://github.com/dlab-berkeley/Computational-Social-Science-Training-Program/blob/master/images/Default%20git%20pull.png) | ||
|
||
|
||
![Uncheck the Experimental Features](https://github.com/dlab-berkeley/Computational-Social-Science-Training-Program/blob/master/images/Beta%20features.png) | ||
|
||
|
||
## Basic Command Line Prompts | ||
|
||
Now we're ready to start working with the command line! See the table below for some common commands. | ||
|
||
| Command | Description | Example | | ||
|---------|--------------------|---------| | ||
| exit | close the terminal | exit | | ||
| cd | change directory | cd data | | ||
| pwd | present working directory | pwd | | ||
| ls | list files in directory | ls | | ||
| cp | copy file | cp ../data/test.txt ../images/test.txt| | ||
| mv | move file | mv ../data/test.txt ../images/test.txt| | ||
| mkdir | make a new directory | mkdir newdir | | ||
| rm | delete a file | rm test.txt | | ||
| rm -r | delete a directory | rm -r newdir | | ||
|
||
Try doing the following: | ||
|
||
1. Change your working directory to the "Reproducible Data Science" folder in this repository | ||
|
||
2. Make a new directory called "newdir" | ||
|
||
3. Copy "test.txt" from Reproducible Data Science to newdir | ||
|
||
4. Delete test.txt from Reproducible Data Science | ||
|
||
## Using the VIM editor | ||
|
||
Navigate to newdir and find test.txt. Next try the following command: | ||
|
||
vim test.txt | ||
|
||
Try following the instructions in the text file to add your name to the beginning of the file. Vim is a lightweight text editor that will allow you to create and edit basic text files. While you might mostly use applications like Notepad, [Sublime](https://www.sublimetext.com/), or [Visual Studio](https://visualstudio.microsoft.com/), vim can still be useful for making small edits and working with files on a server. | ||
|
||
## Running a Python Script | ||
|
||
The last thing we will cover is using the terminal to run Python code. We won't have you regularly do this for this course, but it is useful to know this is an option if you ever are working with a remote server. This is a fairly common situation when you are working with sensitive data (i.e. medical records) or big data. | ||
|
||
First, use `touch` to create a file called "hello.py". | ||
|
||
|
||
touch hello.py | ||
|
||
Now check the files in your current working directory to see if it's there. If so, use vim to add the following text: | ||
|
||
#!/usr/bin/env python3 | ||
|
||
print('Hello World!') | ||
|
||
Exit the vim editor, and then in the command line, run the following: | ||
|
||
python3 hello.py | ||
|
||
or if that doesn't work, try: | ||
|
||
python hello.py | ||
|
||
What happens when you run this? Ideally, it should have printed "Hello World!" to the console! As you progress with your coding skills, your projects may require you to run complicated Python scripts for long periods of time. Being able to run them on remote servers, or chain together many different scripts together will be a key skill in helping you manage that workflow. | ||
|
||
## Challenge Question | ||
|
||
Accomplish the following tasks using only Bash commands: | ||
|
||
1. Create a folder named challenge inside of your "newdir" directory | ||
|
||
2. cd into this directory | ||
|
||
3. Inside of the challenge directory, create a file named movies.txt | ||
|
||
4. Add your favorite movie to this file | ||
|
||
5. Copy this file to your Desktop | ||
|
||
6. Delete the file from your challenge folder | ||
|
||
7. Show the contents of movies.txt on your screen | ||
|
||
8. Open movies.txt | ||
|
||
BONUS: what happens if you try to delete the challenge folder while there is still a file inside of it? |
Oops, something went wrong.