working with Python and Environment Setup and Jupyter Notebooks
Before working on each homework, you need to setup a few things:
Installing Python 3.5+: To use python3, make sure to install version 3.5 or 3.6 on your local machine. If you are on Mac OS X, you can do this using Homebrew with brew install https://raw.githubusercontent.com/Homebrew/homebrew-core/f2a764ef944b1080be64bd88dca9a1d80130c558/Formula/python.rb. You can find instructions for Ubuntu here.
Setting up a virtual environment: we strongly recommend working using a virtual environment for each homework. This will allow you to have a working environment with all the package dependencies within the repository of your homework, without messing up your work environment in other repositories.
To set up a virtual environment with name .env, run the following inside your homework directory (ex: inside cs663/yourDirectoryName):
sudo pip install virtualenv # You will need to do this only once virtualenv -p python3 .env # Creates a virtual environment with python3 source .env/bin/activate # Activate the virtual environment pip install -r requirements.txt # Install all the dependencies # Work on the assignement for a while... deactivate # Exit the virtual environment when you're done
Note that every time you want to work on the assignment, you should run source .env/bin/activate (from within your assignment folder) to re-activate the virtual environment, and deactivate again whenever you are done.
Working with Jupyter notebooks: in your assignment repository, start the notebook with the jupyter notebook command. You might have issues if you are in a virtual environment, as the notebook might not recognize your virtual environment and might not find the kernel located in .env to execute code. In this case, refer to this page and do the following within your virtual environment:
python -m ipykernel install --user --name=my-virtualenv-name
If you are unfamiliar with Jupyter notebooks, you can also refer this IPython tutorial. (from Stanford U)
When working with a Jupyter notebook, you can edit the *.py files either in the Jupyter interface (in your browser) or with your favorite editor (vim, Atom...). Whenever you save a *.py file, the notebook will reload their content directly.