Python Setup

1. Introduction to Python

1.1. Original python download

1.2. What you need more for python development

  • IDE (Integrated Development Environment)
    • Editor
    • Debugger
  • Additional Packages
  • C compilers for extension development
  • other tools (SWIG, etc)

1.3. Python Implementations

  • Cpython (C)
  • Jython (Java)
  • IronPython (.NET)
  • PyPy (Python)
  • Stackless (C)
  • Most useful packages are implemented as a c(pp) library -> recommend CPython

1.4. Python Version Selection

  • 2.x vs. 3.x
    • difference grammar
  • Official 2.x version is 2.7.1
  • Official 3.x version is 3.2
  • Most useful packages are compatible with 2.6.x -> recommend 2.6.x

2. Before Python Installation

UNINSTALLATION and REGISTRY CLEANING
For all installations, I recommend the following procedure:
1. open control panel
2. remove all python packages
3. remove all python cores
4. delete python and package directory
5. open regedit.exe
6. remove HKEY_CURRENT_USER\Software\Python(x,y), HKEY_CURRENT_USER\Software\Python, HKEY_CURRENT_USER\Software\PyQt4 if exist
7. remove HKEY_LOCAL_MACHINE\Software\Python(x,y), HKEY_LOCAL_MACHINE\Software\Python, HKEY_LOCAL_MACHINE\Software\PyQt4 if exist

RECOMMENDATIONS:
For all installations, I recommend the following procedure:
1. create download directory. For instance, C:\python_download
2. download installation files or source files in C:\python_download
3. open console windows with administrator's privilege
4. change directory to C:\python_download
5. type the execution file name in the console window

3. Python Distributions

3.1. Comparisons

  • recommend Python (x,y)
Distributions Python (x, y) Enthought Python Distribution (EPD) Active Python
web site http://www.pythonxy.com/ http://www.enthought.com/products/epd.php http://www.activestate.com/activepython
licence free commercial commercial1
python version 2.6 2.7 1.6 thru 3.2
OS windows all all
64bit included No Yes Yes
IDE Eclipse & PyDev None Komodo IDE
compile env. mingw32 - -

3.2. Python (x, y) Installation

download

  • http://www.pythonxy.com/
  • create download directory (e.g.: c:\python_download )
  • download Python(x,y)-2.6.6.1.exe in the download directory

Installation

  • open console window with administrator's privilege
  • move to C:\python_download and execute Python(x,y)-2.6.6.0.exe
c:\> cd c:\python_download
c:\python_download>"Python(x,y)-2.6.6.1.exe"
  • select "Full" installation
  • select default options for other choices

Registry check

  • make the files for all users
  1. open regedit.exe
  2. export HKEY_CURRENT_USER\Software\Python(x,y) to registry file, reg_pythonxy.reg
  3. export HKEY_CURRENT_USER\Software\Python to registry file, reg_python.reg
  4. export HKEY_CURRENT_USER\Software\PyQt4 to registry file, reg_pyqt4.reg
  5. replace HKEY_CURRENT_USER with HKEY_LOCAL_MACHINE
  6. import Python(x,y) registry file, reg_pythonxy.reg
  7. import Python registry file, reg_python.reg
  8. import PyQt4 registry file, reg_pyqt4.reg

3.3. Check Installation

  • open console window
C:\Users\user>python
Python 2.6.6 (r266:84297, Aug 24 2010, 18:46:32) [MSC v.1500 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> exit()

C:\Users\user>python "C:\Python26\Scripts\xyhome.pyw"

C:\Users\user>python "C:\Python26\Scripts\spyder"

C:\Users\user>"C:\Program Files\pythonxy\console\Console.exe" -t "IPython (Qt)"
  • type !dir in ipython Console and check if you can see Korean language properly

4. Other Win32 Python Package Installation

4.1. Method 1: Install other win32 binary packages

  • http://www.lfd.uci.edu/~gohlke/pythonlibs/
  • recommended packages not included in Python(x, y)
    • Base-11.5.23.win32-py2.6.‌exe
    • pyzmq-2.1.7.1.win32-py2.6.‌exe
    • zope.interface-3.6.3.win32-py2.6.‌exe
    • Twisted-11.0.0.win32-py2.6.‌exe
    • greenlet-0.3.1.win32-py2.6.exe
    • gevent-0.13.6.win32-py2.6.‌exe
    • MySQL-python-1.2.3.win32-py2.6.‌exe

4.2. Method 2: use easy_install

Official Python Package Repository

C:\Users\user>easy_install -U hangulize
Searching for hangulize
Reading http://pypi.python.org/simple/hangulize/
Best match: hangulize dev
Downloading http://github.com/sublee/hangulize/zipball/master#egg=hangulize-dev
Processing master
Running sublee-hangulize-fbee608\setup.py -q bdist_egg --dist-dir c:\users\user\appdata\local\temp\easy_install-sehtd2\sublee-hangulize-fbee608\egg-dist-tmp-02e
f5j
Adding hangulize 0.0.1 to easy-install.pth file

Installed c:\python26\lib\site-packages\hangulize-0.0.1-py2.6.egg
Processing dependencies for hangulize
Finished processing dependencies for hangulize

C:\Users\user>

4.3. Method 3: source download and build

  • setting up compilers
  • vcvars32.bat problem

5. Directory Structure

5.1. Python Directory Structure

  • C:\Python26
    • DLLs : essential python dynamic library
    • Doc
    • ets
    • GDAL
    • gnuplot
    • include : header files
    • Lib : python packages
      • site-packages : non-standard python packages
    • libs : essential python static library
    • Scripts : scripts (easy_install, ipython, etc)
    • share
    • tcl
    • Tools
    • VTKData

5.2. Python(x,y) Directory Structure

  • C:\Program Files\pythonxy
    • console
    • doc
    • eclipse
    • gettext
    • icons
    • installers
    • logs
    • mingw
    • SciTE-2.21
    • swig
    • veusz
    • WinMerge-2.12.4
    • xydoc

6. Development Using IDEs

  • If you install Python(x,y) with full installation option, all IDEs including IPython, Spyder, Eclipse, PyDev are automatically installed .

6.1. Using IPython

6.2. Using Spyder

6.3. Using Eclipse PyDev

Eclipse

  • IDE for java development

PyDev

(optional) workspace change

  • File > Switch Workspace

python environment setting

  • Window > Preferences > PyDev > Interpreter - Python > Auto Config > OK > OK > OK

create project

  • File > New > PyDev Project
  • File > New > Python module
    • if there is no package, leave Package name blank
    • set Name to file name (without .py)

execute and debug

  • execute : Run > Run As > Python Run
  • debug : Run > Debug As > Python Run
  • Perspective and Views
    • Debug View
    • Variables View
    • Expressions View
    • Console View