datastructures-in-python
  • Home
  • Downloads & Misc-Assets
  • README
  • Navigation
  • Curriculum
    • Outline
      • General Content
      • Python-Data-Structures-Unit
    • wk17
      • Outline-w17
      • homework
      • D1-Module 01 - Python I
        • Configuring Ubuntu for Python Web Development
        • Install Python
      • D2- Module 02 - Python II
      • D3- Module 03 - Python III
      • D4-Module 04 - Python IV
    • wk18
      • Outline-W-18
      • D1- Module 01 - Number Bases and Character Encoding
      • D2- Module 02 - Hash Tables I
        • Hash Table / Hash Map In Python:
        • Hash Table Use Cases
        • Practice
      • D3-Module 03 - Hash Tables II
      • D4- Module 04 - Searching and Recursion
    • wk19
      • Outline-W-19
      • D1- Module 01 - Linked Lists
        • Homework
          • Helpful Resource
      • D2- Module 02 - Queues and Stacks
      • D3- Module 03 - Binary Search Trees
        • BST Definition:
      • D4- Module 04 - Tree Traversal
        • Tree Traversals (Inorder, Preorder and Postorder)
    • wk20
      • Outline-W-20
      • D1-Graphs I
      • D2-Graphs 2
      • DFS
      • D4
  • Utilities
    • Utilites
      • Python Libraries
      • YouTube
      • Code Lab Notebook Embeds From Lecture
    • Code lab Notebooks
    • Repl.IT
      • Trinket
  • Abstract Data Structures
    • Algorithms
      • Algo-Resources
        • List-Of-Solutions-To-Common-Interview-Questions
      • Dijkstra's algorithm
      • Calculate a Factorial With Python - Iterative and Recursive
      • DFS
      • BFS
        • BFS Examples
      • Palendrome
    • Data Structures Overview
      • General Data Structures Notes
        • DS-Explained-Simple
      • Untitled
      • Algorithms
      • Dictionary
    • Abstract Data Structures:
      • Array
        • Extra-Array
        • Array Practice
      • Binary Search
      • Binary Tree
        • Binary Tree Explained
        • Find the maximum path sum between two leaves of a binary tree
      • Binary Search Tree
        • BST Explained
        • BST Insert
        • BST-Largest-Sub-Tree
      • Exotic
        • Tire
        • Dynamic Programming
      • Graphs
        • Overflow Practice Problems
        • Graphs Explained
        • Earliest Ancestor
        • _Mini Graph-Projects
          • # Social Graph
          • number of 1 islands
          • Searching and Generating Graphs
        • Graph FAQ
          • Graph DFS
        • Connected Components
        • Randomness
        • Graph BFS
        • Topological Sort
      • Hash Table
        • Hashmap or Hash tables
        • Hash Table and HashMap in Python
      • Heap
        • Heap Examples
      • String
      • Map
        • Examples
      • Queue
        • Queue Continued...
        • Queue Sandbox
        • Dequeue
      • Tree
        • In Order Traversal
        • Tree Equal ?
        • Ternary-search-trees
        • Red_Black Tree
        • Tree Mirror:
        • Tree Traversal
      • Recursion
        • Recursion Explained
          • Recursion Examples
      • Linked List
        • Linked List Background
        • Double Linked List
        • List Example
        • Examples (LL) continued
        • List Operations
      • Set
        • Set
        • Set Intersection Union
        • Disjoint Set
      • Sorting
        • In JavaScript
        • Merge Sort
        • Iterative Sorting
        • Recursive Sorting
        • Graph Topological Sort
        • SelectionSort
        • Quick Sort
        • Merge Sort
        • Insertion Sort
      • Stack
        • Stack Continued
        • Stack Part 3
      • Searching
        • Binary Search
        • Searching & Sorting Computational Complexity (JS)
  • practice
    • GCA Sprint Prep:
      • Practice Problems
      • Code Signal CGA Sprint Resources
      • CGA-Sprint Prep
    • Supplemental Practice:
      • Practice
      • JavaScript Algorithms
      • Industry Standard Algorithms
        • Interview Practice Resources
        • Write a Program to Find the Maximum Depth or Height of a Tree
      • Random Examples
      • Prompts
      • JS_BASICS
  • Resources
    • Python Cheat Sheet
      • Cheatsheet-v2
      • List Of Python Cheat Sheets
    • Youtube
    • PDF Downloads
    • Intro 2 Python
    • Dictionaries
      • Dictionaries Continued
    • Python VS JavaScript
    • Misc. Resources
    • Things To Internalize:
      • Functions
    • Intro To Python w Jupyter Notebooks
    • Calculating Big O
    • Useful Links
      • Awesome Python
      • My-Links
      • Beginners Guide To Python
  • Docs
    • Docs
      • Strings
        • Strings Continued
      • Touple
      • Values Expressions & Statments
      • Dictionaries, sets, files, and modules
        • Modules
      • Built-in Types
      • Built In Functions
        • Zip Function
      • Functions
      • Classes and objects
        • Inheritance
        • Classes
          • Python Objects & Classes
          • index
      • Dictionaries
      • Conditionals and loops
      • Lists
        • Reverse A List
        • Python Data Structures
        • More On Lists
        • Examples
          • More-Examples
        • List Compehensions
      • Basic Syntax
      • String-Methods
    • Queue & Stacks
  • quick-reference
    • My Medium Articles
    • Free Python Books
    • WHY Python?
    • Debugging
    • Python Snippets
    • Python3 Regex
    • Python Module Index:
      • Requests Module
    • Creating Python Modules
    • Useful Info
    • Python Glossary
    • Python Snippets
  • MISC
    • Built-in Methods & Functions
    • Data Structures Types
    • Math
    • Unsorted Examples
    • Outline
    • About Python
      • Python VS JavaScript
      • Python Modules & Python Packages
      • Misc
      • Python's Default Argument Values and Lists
      • SCRAP
  • Interview Prep
    • Interview Resources
      • By Example
        • Algo-Prep
      • Permutation
      • How to Write an Effective Resume of Python Developer
      • Interview Checklist
      • 150 Practice Problems & Solutions
  • Installations Setup & Env
    • python-setup
    • Installing Python Modules
    • Set Up Virtual Enviornment
  • Aux-Exploration
    • Related Studies
      • Self-Organizing Maps: Theory and Implementation in Python with NumPy
      • List Directory Contents
      • Employee Manager
      • OS Module
      • server-side-scripting
      • Web Scraping
      • Reading and Writing to text files in Python
      • General Data Structures
      • Touple
      • How to round Python values to whole numbers?
      • Python Array Module
      • Data Structures In JavaScript
      • Dunder Methods
      • Python GitHub API
      • JS-Event Loop
      • JavaScript Event Loop
      • Manipulating Files & Folders
  • experiments
    • Untitled
Powered by GitBook
On this page
  • Installing Python 3
  • Note for Anaconda users
  • Testing the Install
  • macOS
  • Windows

Was this helpful?

Export as PDF
  1. Curriculum
  2. wk17
  3. D1-Module 01 - Python I

Install Python

PreviousConfiguring Ubuntu for Python Web DevelopmentNextD2- Module 02 - Python II

Last updated 3 years ago

Was this helpful?

Installing Python 3

Brian "Beej Jorgensen" Hall edited this page on May 29, 2020 ·

NOTE: pipenv is optional! We don't use it in CS. But it's a neat package manager if you get into more complex Python projects. It can be a headache of an install for some people. You can safely ignore anything about pipenv below if you don't want to mess with it.

We'll want to install Python 3 (version 3.x), which is the runtime for the language itself. The runtime is what allows you to execute Python code and files by typing python [file_or_code_to_execute] in your terminal. You can also open up a Python REPL (Read-Eval-Print Loop) to quickly and easily mess around with Python code once you've gotten the runtime installed. If you recall how Node let's you execute and run JavaScript code locally on your machine instead of having to rely on the browser, the Python runtime pretty much let's you do the same thing but with Python code.

Additionally, we'll be talking about how to install the (optional) pipenv virtual environment manager. Think of it as the npm of Python (though pipenv is also capable of performing a bunch of other tasks as well, most notably running your Python projects in an isolated virtual environment).

Note for Anaconda users

Unfortunately, we haven't found a way to get Anaconda to play nicely with pipenv. If you get them working together, please let your instructor know how you did it.

Testing the Install

If you can run python or python3 and see a 3.7 or later version, you're good to go:

$ python3 --version
Python 3.6.5

or on some systems, Python 3 is just python:

$ python --version
Python 3.6.5

And optionally try pipenv:

$ pipenv --version
pipenv, version [some remotely recent date, probably]

Otherwise, keep reading. :)

macOS

While macOS comes with Python 2, we need to get Python 3 in there as well.

Use Brew to install Python and pipenv at the Terminal prompt:

brew install python pipenv

Windows

Note: Git Bash doesn't seem to cooperate if you're trying to install Python on Windows. Try another terminal like Powershell.

Recommend updating Windows to the latest version.

Windows Store

Python 3 is in the Windows Store and can be installed from there.

Official Binaries

When installing the official package, be sure to check the

[ ] Add to PATH

checkbox!!

Pipenv

This is what worked for Beej. YMMV.

  1. Install Python, as per above.

  2. Bring up a shell (cmd.exe or Powershell)

  3. Run py -m pip

  4. Run py -m pip install --user pipenv

    At this point, you should be able to always run pipenv with py -m pipenv, but that's a little inconvenient. Read on for making it easier.

  5. You'll see a message like this in the pipenv install output, but with a slightly different path:

    add C:\Users\username\AppData\Roaming\Python\Python38\Scripts to your path
  6. Select that path (not including any quotes around it), and copy it

  7. Go to the Start menu, type "environment" and run the program Edit Environment Variables

  8. In the System Properties popup, hit the Advanced tab, then Environment Variables

  9. On the list of environment variables, doubleclick Path

  10. Click New

  11. Paste that path from step 5 into the new entry slot. Make sure there aren't any quotes around it.

  12. Click OK, OK, OK.

  13. Relaunch any shells you have open.

  14. Now you should be able to just run pip and pipenv in Powershell without putting py -m in front of it.

Pipenv official instructions

Chocolatey

WSL

If you're running Windows 10+, you might want to install the Windows Subsystem for Linux. This gives you a mini, integrated Linux system inside Windows. You then install and use Python from there.

  1. Update Windows to latest if you haven't already.

  2. Go to the Microsoft store and install Ubuntu.

  3. Run Ubuntu to get a bash shell.

  4. Make a new username and password. This is completely separate from your Windows username and password, but I made mine the same so that I wouldn't forget.

  5. Upgrade the Ubuntu system. Run:

    sudo apt-get update
    sudo apt-get upgrade

    Give your newly-entered password if prompted.

  6. Running python3 --version should give you 3.6 or higher.

  7. Run pip install pipenv.

If you've installed VS Code, add the "Remote WSL" extension. This way you can run code from within Ubuntu.

In the Ubuntu shell, you can run explorer.exe . in any directory to open a Windows Explorer window in that directory.

Also in Windows Explorer, you can put \\wsl$ in the URL bar to see your Ubuntu drive. (If it doesn't show up, relaunch your Ubuntu shell.)

If you run into trouble with the above, try the following:

  1. Open cmd.exe as an administrator and start bash with bash

    1. Type Python -V' and 'Python3 -V

      1. If one of these responds with Python 3.6.8 use that command from now on

      2. If neither response is Python 3.6.8 but one is a higher version of Python, this means one of two things

        1. If you have manually installed a higher version of Python, we recommend uninstalling it

        2. If you have not, it is possible that Microsoft has updated WSL and you will need to adjust these instructions to accommodate

      3. Otherwise, update Ubuntu:

        1. sudo apt-get update

        2. sudo apt-get upgrade

    2. Repeat 2.1 above to determine if you should use Python or Python3 when using Python. Note: inside the shell, you will always use Python as the command.

  2. Make sure pip is installed for Python 3

    1. pip --version and pip3 --version. One of these needs to respond with a version that has a version of Python 3 at the end of the line.

    2. If you only have it for 2.7, you will need to install for 3 with:

      1. sudo apt update && sudo apt upgrade

      2. sudo apt install python3-pip

    3. Check versions and commands again. You will likely need to use pip3 for the next step, but it's possible it may be just pip. Use the one with the version associated with Python 3.6.8

  3. Make sure pipenv is installed for Python 3 python3 -m pipenv --version

    1. If not, install pipenv:

      1. sudo apt update && sudo apt upgrade (if you didn't just do this above)

      2. pip3 install --user pipenv

    2. Check the version again

  4. Try pipenv shell. If this fails, make sure that every reference in the error refers to Python 3.6. If not, review the above steps

    1. If the error does refer to 3.6:

      1. Confirm that python --version refers to 2.7.something

      2. Confirm that /usr/bin/python3 --version refers to 3.6.8

      3. pipenv --three --python=which python3`` NOTE that there are backticks (`) around which python3

      4. This should create the shell forcing it to use 3.6.8

If you don't have Brew installed, .

.

1 revision
follow the instructions on the brew website
Official Package
Install pipenv per these instructions
Install Chocolatey
Install Python 3 with Chocolatey
Install pipenv per these instructions
Install WSL from here