Skip to content

Commit 956a3e3

Browse files
committed
Migrates old files to old/ folder.
1 parent 8c5df2f commit 956a3e3

File tree

5 files changed

+307
-1
lines changed

5 files changed

+307
-1
lines changed

old/installing-python-brexton.md

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
# Installing A Virtual Environment (Mac OS X and Linux)
2+
3+
Hi there!
4+
5+
This is a quick tutorial on how to set up pip and virtual environments on your local computer. These are crucial to have at the beginning of the quarter so you are able to install the appropriate dependencies and packages into your computer and also properly install them in the right places. Along with this, these are genuinely useful (& arguably necessary) for any external Python development that you will pursue. So, what are they?
6+
7+
## Pip
8+
Pip is a package management system used to install and manage software packages written in Python. You will most likely use pip to install most of your dependencies for your projects. To install pip on your system, open up your terminal, and type in and enter:
9+
10+
```
11+
sudo easy_install pip
12+
```
13+
14+
This will prompt your terminal to ask you for your system password, enter it, and then pip should be installed on your computer. To install any package on your computer globally, just use:
15+
16+
```
17+
pip install some-package-name
18+
```
19+
20+
You can easily remove the package by using:
21+
22+
```
23+
pip uninstall some-package-name
24+
```
25+
26+
But, before you install any more packages globally, let's talk about virtual environments.
27+
28+
## Virtual Environments
29+
A Virtual Environment is a tool to keep the dependencies required by different projects in separate places, by creating virtual Python environments for them. It solves the "Project X depends on version 1.x but, Project Y needs 4.x" dilemma, and keeps your global site-packages directory clean and manageable.
30+
31+
What does this mean? Well, when you install different libraries and software packages, you are constantly installing specific versions of those packages. If you install it straight on your terminal (globally) without a virtual environment, then your global system will have specific versions that might conflict with a project you might have that might require another version of the same package.
32+
33+
What do Virtual Environments do? They create folders that contain all the necessary executabels to use the packages that a Python project would need (yes, they are just normal folders found in either Finder or terminal). Virtualenv is a tool to create such isolated Python environments.
34+
35+
Install virtualenv via pip:
36+
37+
```
38+
$ pip install virtualenv
39+
```
40+
41+
Basic Usage
42+
1. Create a virtual environment for a project:
43+
44+
```
45+
$ cd my_project_folder
46+
$ virtualenv my_project
47+
```
48+
49+
`virtualenv my_project` will create a folder in the current directory which will contain the Python executable files, and a copy of the pip library which you can use to install other packages. The name of the virtual environment (in this case, it was `my_project`) can be anything; omitting the name will place the files in the current directory instead.
50+
51+
This creates a copy of Python in whichever directory you ran the command in, placing it in a folder named `my_project`.
52+
53+
You can also use the Python interpreter of your choice (like python3)
54+
55+
```
56+
$ virtualenv -p </path/to/python3> my_project
57+
```
58+
59+
2. To begin using the virtual environment, it needs to be activated:
60+
61+
```
62+
$ source my_project/bin/activate
63+
```
64+
65+
The name of the current virtual environment will now appear on the left of the prompt to let you know that it's active. From now on, any package that you install using pip will be placed in the my_project folder, isolated fromt he global Python installation.
66+
Install packages as usual, for example
67+
68+
```
69+
$ pip install requests
70+
```
71+
3. If you are done working in the virtual environment for the moment, you can deactivate it:
72+
73+
```
74+
$ deactivate
75+
```
76+
77+
This puts you back to the system's default Python interpreter with all its installed libraries. To delete a virtual environment, just delete its folder.
78+
79+
## Virtual Environment Wrappers
80+
Next, we'll install virtual environment wrappers. `virtualenvwrapper` provides a set of commands which makes working with virtual environments much more pleasant. It also places all your virtual environments in one place.
81+
82+
To install (make sure you do this AFTER virtualenv is already installed):
83+
84+
```
85+
$ pip install virtualenvwrapper
86+
$ export WORKON_HOME=$HOME/.virtualenvs
87+
$ source /usr/local/bin/virtualenvwrapper.sh
88+
```
89+
90+
Make sure the third line is the correct path to the virtualenvwrapper.sh on your computer. Run a simple "find" command or search within your Finder if you are not sure what the path is!
91+
92+
### Shell Startup File
93+
Add three lines to your shell startup file (.bashrc, .profile, etc.) to set the location where the virtual environments should live, the location of your development project directories, and the location of the script installed with this package:
94+
95+
```
96+
export WORKON_HOME=$HOME/.virtualenvs
97+
export PROJECT_HOME=$HOME/Devel
98+
source /Library/Frameworks/Python.framework/Versions/2.7/bin/virtualenvwrapper.sh
99+
```
100+
101+
To make sure that your .bashrc looks like the above, run this command in your terminal: vim ~/.bashrc
102+
After editing it, reload the startup file (e.g., run source ~/.bashrc in your terminal window).
103+
104+
virtualenvwrapper Quick-Start
105+
1. Run: `workon`
106+
2. A list of environments, empty, is printed.
107+
3. Run: `mkvirtualenv cs41`
108+
4. A new environment, `cs41` is created and activated.
109+
5. Run: `workon`
110+
6. This time, the temp environment is included.
111+
112+
References:
113+
- [The Hitchhiker's Guide to Python](http://python-guide-pt-br.readthedocs.io/en/latest/dev/virtualenvs/)
114+
- [Pip (package manager)](https://en.wikipedia.org/wiki/Pip_(package_manager))
File renamed without changes.

old/submitting-assignments.md

Lines changed: 147 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,147 @@
1+
# CS41 Submission Instructions
2+
3+
At a high level, submitting code for CS41 consists of 2 major parts.
4+
5+
1. Upload your files to Stanford's AFS server
6+
2. Submit your program using `/usr/class/cs41/tools/submit`
7+
8+
Easy, right? Let's chat in more detail.
9+
10+
If you've already taken CS107 and feel comfortable with Unix, skip to the section titled "Upload Files to Myth."
11+
12+
*In all of the below examples, content inside angle braces (`<sunet>`) should be replaced with the correct information.*
13+
14+
## Background Information
15+
16+
### Overview
17+
18+
Everything we'll do this quarter involves running commands on Unix. Developed in the 70s at Bell Labs, Unix is an operating system, like Windows, Android or MacOS. Over the years, Unix and its derivatives and cousins, including Linux, have become ubiquitous. In fact, MacOS X is built on Unix and lets you access its Unix insides through the Terminal (more on that later). Although technically Linux (that we'll use in this class) isn't Unix, but rather a copy-cat of Unix rebuilt from the ground up to address some of Unix's limitations. However, the interface that users (that's us!) see is so similar that for the purposes of this class "Linux" and "Unix" are synonymous.
19+
20+
In CS41, we'll be submitting assignments on "myth," a cluster of computers in the basement of Gates running Ubuntu Linux. The myth computers themselves are physically located in Gates B08. You can also use them remotely to do assignments, because the room is not always available to everyone.
21+
22+
### Logging into `myth` with SSH
23+
24+
The first step of this assignment is to set up your own computer to log in to myth. Logging in through a program called ssh will allow you to work on the myth computers in a way that is indistinguishable from being physically in the Gates B08 room. While some version of ssh is available on all kinds of computers, the exact details of this step will be different depending on what kind of computer you have:
25+
26+
- [MacOS](https://web.stanford.edu/class/cs107/assign0/macos.html): Use this if you have your own Mac or you are on a Stanford lab machine in libraries, dorms, etc.
27+
- [Windows](https://web.stanford.edu/class/cs107/assign0/windows.html): Use this if you have a Windows computer.
28+
- [Linux](https://web.stanford.edu/class/cs107/assign0/linux.html): Use this if you have a Linux computer.
29+
30+
Do not proceed until you have seen `myth`'s successful login welcome text, as shown at the links above.
31+
32+
### Upload/Downloading Files with FTP/SCP
33+
34+
The above instructions allow you to access `myth` to do things on `myth` - edit your code, run your code, debug your code, submit your code, and so on. What it doesn't allow you to do is to bring any files that are on `myth` back with you to your own computer. To do that, you'll need an FTP/SCP file transfer program. There are several options for this, again varying based on your operating system. But one reliable approach is probably just to use [Stanford's AFS web interface](https://afs.stanford.edu). You'll be asked to log in to Stanford as you would for Axess and other secure Stanford websites (unless you are already logged in to one of those at the moment). It will then take you to a list of all the files on your myth account. Click the download icon next to any file to download it. You can also upload files using this web interface, and files you add will be visible when you ssh to myth.
35+
36+
## Upload Files to Myth
37+
38+
**TL:DR**
39+
40+
```
41+
$ ssh <sunetid>@myth.stanford.edu "mkdir -p ~/cs41/assign{0,1,2,3,4}"
42+
$ scp -r <path/to/assignment/directory> <sunetid>@myth.stanford.edu:~/cs41/
43+
```
44+
45+
*Note: you should replace every instance of `<sunetid>` with your own SUNetID.*
46+
47+
### Create Folder Structure on AFS
48+
49+
First, you can optionally construct a folder for your submission to land in - we suggest `~/cs41/`.
50+
51+
If you're on a Macintosh or Linux computer, you can run
52+
53+
```
54+
$ ssh <sunetid>@myth.stanford.edu "mkdir -p ~/cs41/assign{0,1,2,3,4}"
55+
```
56+
57+
It may ask for your password, in which case you should type in your Stanford (SUNet) password. Don't worry if it doesn't appear as you type it - it's not supposed to!
58+
59+
If you're on a Windows computer, you can use a graphical interface ([SecureFX](https://uit.stanford.edu/software/securefx), [FileZilla](https://filezilla-project.org/), [Fugu](http://rsug.itd.umich.edu/software/fugu/)) or a specialized Unix-ish terminal ([cmder](http://cmder.net/), [powershell](https://msdn.microsoft.com/en-us/powershell/scripting/setup/installing-windows-powershell), [MobaXterm](http://mobaxterm.mobatek.net/)) to accomplish this task, but you can *also* do it with the [AFS web client](https://afs.stanford.edu)! Hooray!
60+
61+
Go to [afs.stanford.edu](https://afs.stanford.edu) and click "Create a New Folder" on the left hand side. Name the new folder `cs41`! Inside this folder, create five new folders:
62+
63+
```
64+
assign0/
65+
assign1/
66+
assign2/
67+
assign3/
68+
assign4/
69+
```
70+
71+
When done, you should see something like this:
72+
![AFS Structure](https://raw.githubusercontent.com/stanfordpython/python-handouts/master/img/afs-structure.png)
73+
74+
### Upload files to AFS
75+
76+
On Mac/Linux, you need to copy your files over to the FarmShare servers. You can do this via
77+
78+
```
79+
$ scp -r <path/to/assignment/directory> <sunetid>@myth.stanford.edu:~/cs41/
80+
```
81+
82+
where `<path/to/assignment/directory>` is a filepath identifying the directory your solution code is in, and `<sunetid>` is your SUNetID.
83+
84+
On Windows, if you have an `scp` tool, you can do the same thing. Otherwise, you can use one of the GUI programs or specialized terminals (described at the start of this file) or just upload your files manually via the [WebAFS client](https://afs.stanford.edu).
85+
86+
## Submitting Code!
87+
88+
**TL:DR**
89+
90+
```
91+
$ ssh <sunetid>@myth.stanford.edu
92+
myth$ cd ~/cs41/<assignment_folder>/
93+
myth$ /usr/class/cs41/tools/sanitycheck ./
94+
myth$ /usr/class/cs41/tools/submit ./
95+
```
96+
97+
We providing both a `sanitycheck` tool and a `submit` tool.
98+
99+
If you're on Windows, you'll need to SSH into Stanford FarmShare (`myth`, `corn`, etc.). Hopefully, you already know how to do this, but if not, University IT has some [good solutions](https://uit.stanford.edu/service/sharedcomputing/loggingin), if the earlier SSH solutions didn't work.
100+
101+
### sanitycheck
102+
103+
The `sanitycheck` script, in general, will exercise some basic functionality of your assignment. It isn't extensive, and we'll be testing your code on more advanced test cases, but it should provide you with some confidence that everything is at least set up correctly and working properly on basic inputs.
104+
105+
When logged into myth (or another of the Stanford computer clusters), first navigate to your submission directory. From there, you test your code by running
106+
107+
```
108+
myth$ /usr/class/cs41/tools/sanitycheck ./
109+
```
110+
111+
### submit
112+
113+
When you're ready to submit, make sure that you're currently in your submission directory (you can check by running `pwd` on myth), and run
114+
115+
```
116+
myth$ /usr/class/cs41/tools/submit
117+
```
118+
119+
You should get output that looks something like:
120+
121+
```
122+
Hello, sredmond
123+
Which assignment are you submitting?
124+
* Please enter the assignment number
125+
0: Welcome to Python
126+
1: Cryptography
127+
2: Quest for the Holy Grail
128+
3: Stylize
129+
4: Final Project
130+
> 0
131+
Submission for Assignment #0
132+
This isn't a question - but it's the last step... I'm about to upload all files in the current folder to AFS. Hit ENTER to confirm this is desired.
133+
```
134+
135+
Note that you have the option to run sanity check before submitting.
136+
137+
## Notes
138+
139+
There are a few important things to consider:
140+
141+
1. Every time that you want to submit a new version of your assignment, you must upload your changed files to AFS (myth), and run `/usr/class/cs41/tools/submit`
142+
2. We'll grade the most recent assignment that you submit.
143+
3. Make sure that you're running the `tools` scripts from inside your assignment directory! Otherwise there might be some weird errors.
144+
145+
## Credit
146+
147+
Several sections of this handout were copied, verbatim, from Cynthia's incredible [CS107 introductory materials](https://web.stanford.edu/class/cs107/assign0/), and some instructive commands (especially for SCPing from Windows) came from [CS221's submission instructions](http://web.stanford.edu/class/cs221/). It wouldn't be possible without them!

virtualenv.md renamed to old/virtualenv.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Virtual Environments
22

33
## What is a virtual environment?
4-
A virtual environment is simply an isolated folder that contains all the executables you need to build something awesome in Python, including code to run the interpreter, use the standard library (https://docs.python.org/3.4/library/), and install other 3rd-party libraries that we'll touch on towards the end of the quarter.
4+
A virtual environment is simply an isolated folder that contains all the executables you need to build something awesome in Python, including code to run the interpreter, use the standard library (https://docs.python.org/3.4/library/), and install other 3rd-party libraries that we'll touch on towards the end of the quarter.
55

66
## Why bother using virtual environments?
77
Of course, you can also develop Python projects without a virtual environment, but it's a good idea to become familiar with this tool because you can avoid dependency conflicts between your system-wide Python installations and your project-specific Python installations. For example, if you're using Python to build 3 separate Web apps because you're a beast, Project A might depend on Django version 1.2 while Project C depends on Django version 1.9 (yes, Django is the name of a real Web framework: https://docs.djangoproject.com/en/1.9/releases/). You can create a separate virtual environment for each project then install whichever version you need in each project. When you ship awesome projects later in your Python career, you'll know the exact libraries and versions that your project requires (:

virtual-environments.md

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# Virtual Environments
2+
3+
## What is a virtual environment?
4+
A virtual environment is simply an isolated folder that contains all the executables you need to build something awesome in Python, including code to run the interpreter, use the standard library (https://docs.python.org/3.4/library/), and install other 3rd-party libraries that we'll touch on towards the end of the quarter.
5+
6+
## Why bother using virtual environments?
7+
Of course, you can also develop Python projects without a virtual environment, but it's a good idea to become familiar with this tool because you can avoid dependency conflicts between your system-wide Python installations and your project-specific Python installations. For example, if you're using Python to build 3 separate Web apps because you're a beast, Project A might depend on Django version 1.2 while Project C depends on Django version 1.9 (yes, Django is the name of a real Web framework: https://docs.djangoproject.com/en/1.9/releases/). You can create a separate virtual environment for each project then install whichever version you need in each project. When you ship awesome projects later in your Python career, you'll know the exact libraries and versions that your project requires (:
8+
9+
## How to create virtual environment
10+
In class we audibled to using a piece of software called virtualenv to build virtual environments because some people had trouble with the virtualenvwrapper software. After you've installed Python3 and pip (see https://github.com/stanfordpython/python-handouts/blob/master/installing-python.md#linux if you need help with this step), you're almost done. Here's the rest of the commands to execute:
11+
12+
### Install the software (only do this once)
13+
`$ pip install virtualenv`
14+
15+
this uses pip to install the software used to build your virtual environments, called virtualenv
16+
17+
### Creating a virtual environment
18+
cd to your Desktop then execute
19+
20+
`$ virtualenv cs41`
21+
22+
this uses virtualenv to create a new virtual environment in the working directory named cs41. you should be able to see this folder on your Desktop now.
23+
24+
### Activating and deactivating a virtual environment
25+
To activate, simply cd into the environment we created above then execute
26+
27+
`$ source bin/activate`
28+
29+
Now you can play with the interactive interpreter inside your isolated environment using
30+
31+
`$ python3`
32+
33+
You can also create new files, modules, whatever you need to make a beautiful Python project ready to ship!
34+
To deactivate, type
35+
36+
`$ deactivate`
37+
38+
All done! If you want to read more about the above steps, check out http://docs.python-guide.org/en/latest/dev/virtualenvs/
39+
40+
If you want to read about the interactive interpreter, check out http://www.python-course.eu/python3_interactive.php
41+
42+
43+
44+
45+

0 commit comments

Comments
 (0)