🐍
My Docs
PYTHONNOTES
PYTHONNOTES
  • 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
  • Python3
  • Bottle
  • Vim
  • $HOME environment
  • Lumpy
  • Making a python script executable and runnable from anywhere
  1. Curriculum
  2. wk17
  3. D1-Module 01 - Python I

Configuring Ubuntu for Python Web Development

PreviousD1-Module 01 - Python INextInstall Python

Last updated 3 years ago

Note: the following instructions assume that you are connected to the Internet and that you have both the main and universe package repositories enabled. All unix shell commands are assumed to be running from your home directory ($HOME). Finally, any command that begins with sudo assums that you have administrative rights on your machine. If you do not — please ask your system administrator about installing the software you need.

What follows are instructions for setting up an Ubuntu 16.04 (Xenial) home environment for use with this book. I use Ubuntu GNU/Linux for both development and testing of the book, so it is the only system about which I can personally answer setup and configuration questions.

In the spirit of software freedom and open collaboration, please contact me if you would like to maintain a similar appendix for your own favorite system. I’d be more than happy to link to it or put it on the Open Book Project site, provided you agree to answer user feedback concerning it.

ThanksArlington, Virginia

Python3

Ubuntu 16.04 comes with both Python 2 and Python 3 installed. Typing python at the shell prompt still launches Python 2. Use the command python3 for Python 3.

In addition to the in the , we will be using Python software from the or PyPI. The tool for installing packages from PyPI is called . Since we want Python 3 packages installed which will work with the Python 3 already on our Ubuntu system, we will use the Ubuntu python3-pip debian package.

To add this package run following from the unix command prompt:

$ sudo apt install python3-pip

Now would also be a good time to install a few other packages you will want to have on your system:

$ sudo apt install python3-tk pep8 bzr

This will install the GUI toolkit, the Python style checker, and the revision control system which we will use to grab some program examples.

Bottle

is a micro written in Python. It is used in this book to introduce development.

To install bottle run:

$ sudo apt install python3-bottle

Then try:

>>> import bottle

at the python prompt to varify that it is working.

Vim

To use Vim, do the following:

  1. From the unix command prompt, run:

    $ sudo apt install vim
  2. Create a file in your home directory named .vimrc that contains the following:

    syntax enable
    filetype indent on
    set et
    set sw=4
    set smarttab
    map <f3> :w\|!python3 % <cr>
    map <f4> :w\|!python3 -m doctest -v % <cr>
    map <f8> :w\|!pep8 % -v <cr>

When you edit a file with a .py extension, you should now have color systax highlighting and auto indenting. Pressing the <f3> key should run your program, and bring you back to the editor when the program completes. <f4> runs the program with the verbose (-v) switch set, which will be helpful when running doctests. <f8> will run the pep8 style checker against your program source, which is useful in helping you learn to write Python programs with good styling.

To learn to use vim, run the following command at a unix command prompt:

$ vimtutor

$HOME environment

  1. From the command prompt in your home directory, create bin and lib subdirectories of your .local directory by running the following command:

    $ mkdir .local/lib .local/bin
  2. Now add a my_python subdirectory to .local/lib:

    $ mkdir .local/lib/my_python
  3. Add the following lines to the bottom of your .bashrc in your home directory:

    EDITOR=vim
    PATH=$HOME/.local/bin$PATH
    PYTHONPATH=$HOME/.local/lib/my_python
    
    export EDITOR PATH PYTHONPATH

    This will set your prefered editor to Vim, add your own .local/bin directory as a place to put executable scripts, and add .local/lib/my_python to your Python search path so modules you put there will be found by Python.

    Then run:

    $ . .bashrc

Lumpy

Making a python script executable and runnable from anywhere

On unix systems, Python scripts can be made executable using the following process:

  1. Add this line as the first line in the script:

    #!/usr/bin/env python3
  2. At the unix command prompt, type the following to make myscript.py executable:

    $ chmod +x myscript.py
  3. Move myscript.py into your .local/bin directory, and it will be runnable from anywhere.

can be used very effectively for Python development, but Ubuntu only comes with the vim-tiny package installed by default, so it doesn’t support color syntax highlighting or auto-indenting.

The following creates a useful environment in your for using pip3 to install packages into your home directory and for adding your own Python libraries and executable scripts:

to set these and prepend the .local/bin directory to your (note: logging out and back in will accomplish the same result).

Lumpy is python module that generates diagrams. It was written by as part of his suite of Python programs written for use with his textbooks.

The version here is modified to work with Python 3 on Ubuntu 16.04. Click on to download the module. Put this file in your .local/lib/my_python directory after your is configured.

Lumpy is used in several of the exercises in this book to help illustrate python .

Vim
home directory
environment varialbles
search path
UML
Allen B. Downey
Swampy
lumpy.py
$HOME environment
data structures
debian packages
Ubuntu Package archive
Python Package Index
pip
Tkinter
pep8
bzr
Bottle
web application framework
web application
Jeffrey Elkner