Files
python-2020-5-day-class/docs/day0.md

11 KiB

Day 0

When you start programming half the battle is getting your bearings. Suddenly it matters where you put your files. You need to know where you home directory is, you need to understand file permissions, you need to understand what a file actually is. Trying to program without first learning about the thing you are programming will cause headache.

Fortunately we can do some things to make your life easier. We can install an IDE: a program that lets you visualize your files and folders and quickly switch between them. We can install a version control system that will let you "snapshot" your code and save it to the cloud so you never lose it. We can organize our project to be repeatable, and more importantly, unloseable.

I have a Windows PC

(or skip to I have a Mac)

Install Git (windows)

Git is a version control program, but you can think of it as your best friend in the cold, dark world of data loss. Git will make sure you don't lose progress. It lets you save your code at various stages and revert back to previous saves if you need to.

  1. Head to https://git-scm.com/

  2. Click Download

    git_download

  3. Run through the default install process

Install Python (windows)

  1. Head to https://www.python.org/

  2. Hover over Downloads and click the most recent version

    download_for_windows

  3. Run through the install process - uncheck "install for all users" and check "add python 3.9 to path"

    python_windows_install

Install VSCode (windows)

Your most important tool as a programmer is a proper editor. It should offer you a wide selection of tools but get out of your way when you don't need it. VSCode is a great option in 2020. It has tons of extensions and support for almost every language you can throw at it.

  1. Head to https://code.visualstudio.com/

  2. Click on the download link

    vscode_download

  3. Run through the installer, select default options

  4. Open VSCode

    vscode_open

  5. Uncheck "Show welcome page on startup"

    vscode_uncheck

  6. Close out of the welcome page

    close_welcome

  7. Open the terinal with ++ctrl++ + ~

  8. Click the dropdown that says 1: powershell and click Select Default Shell

    select_default_shell_windows

  9. Select Command Prompt

    select_cmd_prompt

  10. Kill the terminal by clicking the trash can icon

    kill_terminal

  11. Click the "extensions" button on the left to open the extensions page

    extension

  12. Search for "python"

    search_python

  13. Click on the first Python extension and click "install"

    install_python

  14. When the extension has finished installing, close out of the welcome window

    close_welcome

  15. Close out of the extension window

    close_extension

  16. Reopen your document view by clicking the "documents" icon

    select_docs

Create a "Projects" folder (windows)

I keep all my projects in a folder called "Projects" in my home directory. On Windows this is at C:\Users\<your username>\Projects. Create this folder now. Bookmark it, put it in your favorites, don't lose it.

  1. In your Projects folder create another folder called my_website

  2. Switch to VSCode You can use ++alt+tab++ to quickly switch between windows. Press ++ctrl++ + K + O and select the projects/my_website folder

    ctrl_ko

Create a virtual environment (windows)

A python virtual environment is a folder that will hold your python installation for the project you're working on. You'll have a virtual environment for every project you create.

  1. With your "my_website" folder open in VSCode open the terminal with ++ctrl++ + ~

    open_terminal_windows

  2. Type python --version

    python_version_windows

  3. If you see Python 3.9.# you have the correct version, if you see another version try typing python3.9 --version. If that doesn't work you'll need to reinstall python 3.9.

  4. Type python -m venv venv. You'll see a folder appear on the left side of VSCode.

    venv_windows

  5. Source your venv: type venv\Scripts\activate. You'll see a (venv) appear next to your terminal cursor.

    source_venv_windows

Install Django (windows)

Django is a pip package. Pip packages are other people's python code that you can download for free. In much the same way you downloaded VSCode and Python itself with your browser, we can download pip packages with "pip". Pip comes preinstalled with Python.

  1. Make sure you followed step 5 above, you should have a (venv) next to your terminal cursor. Type pip install django

    pip_django

  2. If you have a warning like above you can ignore it for now. Type django-admin startproject config .

    startproject

  3. Click on manage.py. You should see VSCode activate python extensions in the bottom left and select an interpretor. ('venv': venv) should be selected. You can ignore the message that says "linter pylint is not installed" - just close out of it.

    open_manage

  4. Close out of manage.py by clicking the 'x' at the top.

  5. Type python manage.py runserver

    runserver

  6. Open a browser and navigate to http://localhost:8000

    localhost8000

  7. You should see an install success page. If so, congratulations! You have successfully installed Django.

  8. Stop running server by clicking in the terminal and typing ++ctrl++ + C. You have successfully completed Day 0!

I have a Mac

Install Git (mac)

Git is a version control program, but you can think of it as your best friend in the cold, dark world of data loss. Git will make sure you don't lose progress. It lets you save your code at various stages and revert back to previous saves if you need to.

  1. Head to https://git-scm.com/

  2. Click Download

    git_download

  3. Run through the default install process

Install Python (mac)

  1. Head to https://www.python.org/

  2. Hover over Downloads and click the most recent version

    download_python_mac

  3. Follow the standard install procss

    install_for_mac

Install VSCode (mac)

Your most important tool as a programmer is a proper editor. It should offer you a wide selection of tools but get out of your way when you don't need it. VSCode is a great option in 2020. It has tons of extensions and support for almost every language you can throw at it.

  1. Head to https://code.visualstudio.com/

  2. Click on the download link

    vscode_download

  3. Run through the installer, select default options

  4. Open VSCode

    vscode_open

  5. Uncheck "Show welcome page on startup"

    vscode_uncheck

  6. Close out of the welcome page

    close_welcome

  7. Click the "extensions" button on the left to open the extensions page

    extension

  8. Search for "python"

    search_python

  9. Click on the first Python extension and click "install"

    install_python

  10. When the extension has finished installing, close out of the welcome window

    close_welcome

  11. Close out of the extension window

    close_extension

  12. Reopen your document view by clicking the "documents" icon

    select_docs

Create a "Projects" folder (mac)

I keep all my projects in a folder called "Projects" in my home directory. On MacOS this is at /Users/<your username>/Projects. Create this folder now. Bookmark it, put it in your favorites, don't lose it.

  1. In your Projects folder create another folder called my_website

  2. Switch to VSCode You can use ++cmd+tab++ to quickly switch between windows. Press ++ctrl++ + O and select the projects/my_website folder

    ctrl_ko

Create a virtual environment (mac)

A python virtual environment is a folder that will hold your python installation for the project you're working on. You'll have a virtual environment for every project you create.

  1. With your "my_website" folder open in VSCode open the terminal with ++ctrl++ + ~

    open_terminal

  2. Type python3 --version

    python_version

  3. If you see Python 3.9.# you have the correct version, if you see another version try typing python3.9 --version. If that doesn't work you'll need to reinstall python 3.9.

  4. Type python3 -m venv venv. You'll see a folder appear on the left side of VSCode.

    venv_mac

  5. Source your venv: type source venv/bin/activate. You'll see a (venv) appear next to your terminal cursor.

    source_venv_mac

Install Django (mac)

Django is a pip package. Pip packages are other people's python code that you can download for free. In much the same way you downloaded VSCode and Python itself with your browser, we can download pip packages with "pip". Pip comes preinstalled with Python.

  1. Make sure you followed step 5 above, you should have a (venv) next to your terminal cursor. Type pip install django

    pip_django

  2. If you have a warning like above you can ignore it for now. Type django-admin startproject config .

    startproject

  3. Click on manage.py. You should see VSCode activate python extensions in the bottom left and select an interpretor. ('venv': venv) should be selected. You can ignore the message that says "linter pylint is not installed" - just close out of it.

    open_manage

  4. Close out of manage.py by clicking the 'x' at the top.

  5. Type python manage.py runserver

    runserver

  6. Open a browser and navigate to http://localhost:8000

    localhost8000

  7. You should see an install success page. If so, congratulations! You have successfully installed Django.

  8. Stop running server by clicking in the terminal and typing ++ctrl++ + C. You have successfully completed Day 0!