Skip to content

Instantly share code, notes, and snippets.

@vpayno
Last active December 21, 2015 17:09
Show Gist options
  • Save vpayno/6338724 to your computer and use it in GitHub Desktop.
Save vpayno/6338724 to your computer and use it in GitHub Desktop.
Python Cheat Sheets - Setting up your environment

Python Cheat Sheets

By Victor Payno

Setting up your environment

Windows

If you haven't already, create a HOME variable that points to %USERPROFILE%.

  • Download installer from http://www.python.org/download/ and install it. I'm using 2.7.x 64-bit. Make sure you add C:\Devel\Python\2.7\ and C:\Devel\Python\2.7\Scripts to your profile's PATH environment variable.

  • Download curl from http://curl.haxx.se/download.html and install curl.exe and it's dll files to C:\Devel\Tools. Make sure you add it to your profile's PATH variable. Run the mk-ca-bundle.vbs script from the C:\Devel\Tools directory and set the environment variable CURL_CA_BUNDLE to C:\Devel\Tools\ca-bundle.crt .

  • Download easy_install from https://pypi.python.org/pypi/setuptools

curl.exe https://bitbucket.org/pypa/setuptools/raw/bootstrap/ez_setup.py | python.exe
  • Install PIP
easy_install pip
  • Use pip to install the following packages.
pip install pyreadline

pip install nose

pip install pexpect

pip install ipython

pip install fabric
  • Setup .pythonrc

    • Create the environment variable PYTHONSTARTUP and set it to %USERPROFILE%.pythonrc . Next use notepad to create that file and add the following to it.
import atexit
import os
import re
import readline
import rlcompleter
import sys
import time
import timeit

history = os.path.expanduser('~/.python_history')
readline.read_history_file(history)
readline.parse_and_bind('tab: complete')
atexit.register(readline.write_history_file, history)

def t(*args):
    return timeit.Timer(*args).timeit()

This will add readline support, save your history to a file and creates a time function (like in BASH) that can be used to time code.

  • Download and install Console from http://sourceforge.net/projects/console/files/console-releases/1.5/ .

    • Extract the Console directory to C:\Devel\Tools\Console and add the path to your PATH variable.

    • Right click "console.inf" and pick "Install" to add the "Console Here" explorer context menu option.

  • Configure iPython.

    • Create %USERPROFILE%\ipy_user_conf.py and add the following to it.
from IPython import ipapi
ipapi.get().ex("from ipipe import *")

  • Create the Windows Command Script C:\Devel\Python\2.7\iPythonShell.cmd and add the following to it.
@ECHO OFF

cd %USERPROFILE%

ipython --profile sh
  • Create a shortcut in Start | Programs | Python that points to this script.

Cygwin

Linux

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment