This file covers many of the common commands used with Python through the command line interface. Traditionally, one could only find such a collection by either going to the docs, or by following a tutorial/guide.
The purpose of consolidating snippets of common commands is to lessen the obstacle of using command lines in the programming environment.
As a beginner, using the command line interface can be a daunting process (as opposed to simply using an interpreter), thus I hope this helps beginners build their confidence using these tools.
pip is a package management system that is used to install and manage libraries with Python.
Install the specified library
pip install <specified library>Install all required libraries specified by requirements.txt (applicable for virtual environments)
pip install -r requirements.txtList all the installed libraries within the active Python interpreter
pip listList all the installed libraries and their version numbers
pip freezeSave a list of all the installed libraries and their version numbers to requirements.txt . This is useful when you are using virtual environments (virtualenv), and you need to specify the libraries to install (including dependencies).
pip freeze > requirements.txtVirtual environments are used to isolate libraries for different projects by creating virtual Python environments for each project.
virtualenv is a library that can easily create these virtual Python environments in a specified folder.
pip install the virtualenv library (not included in the Python standard library)
pip install virtualenv
#
# Install virtualenv into a Python version which isn't the system default
# Windows: /c/Users/<User>/<Python Install Folder>/Scripts/pip.exe install virtualenv
# Linux: /home/<User>/<Python Install Folder>/bin/pip install virtualenvMake a directory one folder up (from your main project code) for the virtual environment called 'virtualenv'
mkdir ../virtualenvCreate the virtual environment in a specified folder ('virtualenv', which we created above)
virtualenv ../virtualenv
#
# Creating a virtual environment from a different Python version (i.e. Python 2.7 while Python 3.4 is the system default)
# Windows: /c/Users/<User>/<Python Install Folder>/python.exe /c/Users/<User>/<Python Install Folder>/Lib/site-packages/virtualenv.py ../virtualenvActivate the virtual environment
# OSX/'nix: source ../virtualenv/bin/activate
#
# Windows: source ../virtualenv/Scripts/activateDeactivate the virtual environment (once finished using it)
deactivateCheck which python is running (shows the complete folder path)
which pythonFirst, install libpq-dev:
sudo apt-get install libpq-dev python-devMight also require:
sudo apt-get install postgresql-server-dev-allThen use PIP to install psycopg2:
pip install psycopg2sudo yum install python-devel postgresql-devel
pip install psycopg2It is easiest to use the prebuilt binary Psycopg wheel provided by Christoph Gohlke on his Python Extension Packages page.
Fabric is a Python 2.7 ONLY library for application deployment and system administration tasks. It provides operations on a local or remote machine (via ssh).
Install pycrypto (dependency)
Windows 64bit: easy_install http://www.voidspace.org.uk/downloads/pycrypto26/pycrypto-2.6.win-amd64-py2.7.exeInstall Fabric
pip install fabricDeploy (using the class 'deploy' within fabfile.py)
fab deploy:host=<user name>@appname-staging.server.com