Python

From GeilThings

Jump to: navigation, search
Python
Python-logo-master-v3-TM.png
General
Version 3.3.2
Stable 3.3.2
Function Programming Language
Package Manager easy_install, pip
Environment Manager virtualenv
Scripts


Contents


General

Package Managers

Installing setuptools:

# http://stackoverflow.com/questions/3390558/installing-setuptools-in-a-private-version-of-python
wget http://pypi.python.org/packages/source/s/setuptools/setuptools-0.6c11.tar.gz#md5=7df2a529a074f613b509fb44feefe74e
tar -zxvf setuptools-0.6c11.tar.gz
cd setuptools-0.6c11/
python2.7 setup.py install
# easy_install is installed as /opt/python2.7.2/bin/easy_install-2.7
#
# From http://stackoverflow.com/questions/2192323/what-is-the-python-egg-cache-python-egg-cache:
# In case it is needed later, create the environment variable PYTHON_EGG_CACHE and
# point it to /tmp/python-eggs so there is a directory accessible by the web server user where
# python eggs can be unzipped.
mkdir /tmp/python-eggs
# Being sure that the web server user (apache) can access it:
chown -R apache. /tmp/python-eggs/
# In /home/username/.bashrc, add the line:
# export PYTHON_EGG_CACHE=/tmp/python-eggs

Environment Managers

Installing Python

Installing Python 3.x in CentOS 6.x


######### START EDIT #########
 
APPNAME=python
# The directory where I want to download the files.
DOWNLOADDIRECTORY=/opt
 
######### END OF EDIT #########
 
RAWOLDVERSION=`python3 -V 2>&1`
OLDVERSION=${RAWOLDVERSION:7}
echo $OLDVERSION
 
RAWNEWVERSION=`curl -sd "action=ask&query=[[Python]]|%3FStable&format=json" http://www.geilthings.com/api.php` 
# Get Version as Substring.  
# Using grep to sed to extract STRING between first occurrence of MATCH1 and next occurrence of MATCH2:  
# http://stackoverflow.com/questions/4392106/sed-extract-string-between-first-occurrence-of-match1-and-next-occurrence-of-m  
NEWVERSION=`echo "$RAWNEWVERSION" | grep -Po '^.*?\K(?<=Stable\":\[\").*?(?=\")'`  
echo $NEWVERSION
 
yum install openssl-devel bzip2-devel expat-devel gdbm-devel readline-devel sqlite-devel
# To avoid the message after make:
# Python build finished, but the necessary bits to build these modules were not found: _lzma
yum install lzip xz xz-devel xz-libs
 
cd ${DOWNLOADDIRECTORY}
wget http://www.python.org/ftp/python/${NEWVERSION}/Python-${NEWVERSION}.tgz
tar -xzvf Python-${NEWVERSION}.tgz
cd Python-${NEWVERSION}
./configure --prefix=/opt/python3
make 
make install
 
cd ${DOWNLOADDIRECTORY}
# Use a link for easier administration if need to upgrade python3.x later.
rm -f ${DOWNLOADDIRECTORY}/python3
ln -s ${DOWNLOADDIRECTORY}/Python-${NEWVERSION} ${DOWNLOADDIRECTORY}/python3
# Add this alias to /etc/bashrc file for all users or ~/.bashrc file for myself.
alias python3='/opt/python3/bin/python3'
# Run it using "python3" instead of "python". 
 
# Test.
python3 -V

Installing Python 2.7 in CentOS 5.x, 6.x

yum install gcc tcl tk sqlite-devel readline-devel gdbm-devel 
yum install tkinter ncurses-devel libdbi-devel tk-devel zlib-devel
yum install openssl-devel bzip2-devel
cd /opt
# Python 2.7 so django and mod_wsgi work.
wget http://www.python.org/ftp/python/2.7.3/Python-2.7.3.tgz
tar -xzvf Python-2.7.3.tgz
./configure
make 
make altinstall prefix=/opt/python2.7.3
cd /opt
# Use a link for easier administration if need to upgrade python2.7 later.
ln -s /opt/python2.7.3 /opt/python2.7
# Add this alias to /etc/bashrc file for all users or ~/.bashrc file for myself.
alias python2.7='/opt/python2.7/bin/python2.7'
# make altinstall will install the new Python as Python2.7; it will not collide with the default Python (2.4.x in CentOS 5.x, 2.6.6 in CentOS 6.2). 
# Run it using "python2.7" instead of "python".

Installing Python 2.7 in Windows 7 64 Bit

  • As of October 2011:
  1. Set the path variable:
    Start / Computer / (Top Menu) System Properties / (Left Menu) Advanced System Settings / ("Advanced" Tab) Environment Variables / System Variables / (Edit) Path
    Add at the beginning C:\Python27;
    Close by clicking OK
    Restart cmd.exe
  • Typing "python" should open the Python console


Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Python]

[HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Python\PythonCore]

[HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Python\PythonCore\2.7]

[HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Python\PythonCore\2.7\Help]

[HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Python\PythonCore\2.7\Help\Main Python Documentation] @="C:\\Python27\\Doc\\python272.chm"

[HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Python\PythonCore\2.7\InstallPath] @="C:\\Python27\\"

[HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Python\PythonCore\2.7\InstallPath\InstallGroup] @="Python 2.7"

[HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Python\PythonCore\2.7\Modules]

[HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Python\PythonCore\2.7\PythonPath] @="C:\\Python27\\Lib;C:\\Python27\\DLLs;C:\\Python27\\Lib\\lib-tk"

Interesting Modules

  • NetworkX: Package for the creation, manipulation, and study of the structure, dynamics, and functions of complex networks. http://networkx.lanl.gov/
  • Setuptools: Package Manager. yum install python-setuptools
  • Yolk: Command-line script to query for installed Python modules. yum install python-yolk
    • yolk -l: List installed Python packages.
  • PyYAML: YAML parser.
    • If errors below appear, python-devel package needs to be installed.
      • ext/_yaml.c:4:20: error: Python.h: No such file or directory
      • ext/_yaml.c:6:6: error: #error Python headers needed to compile C extensions, please install development version of Python.


# libyaml is in the epel repository.
yum install libyaml
 
# Header files are needed.
yum install python-devel
 
# Using yum:
yum install PyYAML
 
# From source:
cd /opt
wget http://pyyaml.org/download/pyyaml/PyYAML-3.10.tar.gz
tar zxvf PyYAML-3.10.tar.gz
cd PyYAML-3.10
# python setup.py --with-libyaml install failed with 
# ext/_yaml.h:2:18: error: yaml.h: No such file or directory
python setup.py install

Upgrading Phython3

Upgrading Python 3.x in CentOS 6.x.


######### START EDIT #########
 
APPNAME=python
# The directory where I want to download the files.
DOWNLOADDIRECTORY=/opt
 
######### END OF EDIT #########
 
RAWOLDVERSION=`python3 -V 2>&1`
OLDVERSION=${RAWOLDVERSION:7}
echo $OLDVERSION
 
RAWNEWVERSION=`curl -sd "action=ask&query=[[Python]]|%3FStable&format=json" http://www.geilthings.com/api.php` 
NEWVERSION=`echo "$RAWNEWVERSION" | grep -Po '^.*?\K(?<=Stable\":\[\").*?(?=\")'`  
echo $NEWVERSION
 
cd ${DOWNLOADDIRECTORY}
rm -rf python3
wget http://www.python.org/ftp/python/${NEWVERSION}/Python-${NEWVERSION}.tgz
tar -xzvf Python-${NEWVERSION}.tgz
cd Python-${NEWVERSION}
./configure --prefix=/opt/python3
make 
make install
 
cd ${DOWNLOADDIRECTORY}
ln -s ${DOWNLOADDIRECTORY}/Python-${NEWVERSION} ${DOWNLOADDIRECTORY}/python3
# Run it using "python3" instead of "python". 
 
# Test.
python3 -V
 
rm -f ${DOWNLOADDIRECTORY}/Python-${NEWVERSION}.tgz
mv ${DOWNLOADDIRECTORY}/Python-${OLDVERSION} ${DOWNLOADDIRECTORY}/old_Python-${OLDVERSION}

Programming

See also Jython


Web Frameworks

Versions

Software name Version number Version date
Python 3.3.0
3.3.1
3.3.2
23 March 2013
27 April 2013
18 May 2013

Comments

blog comments powered by Disqus