How to install Python common modules __python

Source: Internet
Author: User
Tags mkdir git clone

Python Module Installation method


One, Method 1: Single File module
Copy the file directly to the $python _dir/lib

Two, Method 2: Multi-file module, with setup.py

Download module package, unpack, enter module folder, execute:
Python setup.py Install

Iii. method 3:easy_install mode

Download the ez_setup.py first, run the Python ez_setup to install the Easy_install tool, and then use Easy_install to install package.
Easy_install PackageName
Easy_install Package.egg

Iv. method 4:pip mode

Install the PIP tool First: The Easy_install pip (the PIP can be installed through Easy_install and will also be mounted under the Scripts folder). )

Installation: Pip Install PackageName

Update: Pip install-u packagename

Removal: Pip Uninstall PackageName

Search: Pip Search PackageName

Help: Pip helps


Note: Although Python modules can be copied for installation, it is generally recommended to make an installation package, that is, to write a setup.py file to install.
The use of the setup.py file is as follows:
% python setup.py build #编译
% python setup.py install #安装
% python setup.py sdist #制作分发包
% python setup.py bdist_wininst #制作windows下的分发包
% python setup.py bdist_rpm

Preparation of setup.py documents
Setup.py mainly executes a setup function, most of which are descriptive things, the most important is the packages parameters, listing all the package, you can use the Find_packages to dynamically obtain package. So the setup.py file is actually very simple to write.
A simple example:
setup.py file:

From Setuptools import Setup, find_packages
Setup
Name = "MyTest",
Version = "0.10",
Description = "My Test module",
Author = "Robin Hood",
url = "Http://www.csdn.net",
license = "LGPL",
Packages = Find_packages (),
Scripts = ["scripts/test.py"],
)

mytest.py

Import Sys
Def get ():
Return Sys.path

scripts/test.py

Import OS
Print Os.environ.keys ()

The scripts in Setup says that the file is placed in the scripts directory of Python and can be used directly. OK, simple installation is successful, you can run the enumerated commands to build the installation package, or install the Python package. The native test succeeded (WIN32-PYTHON25).


Note: Setuptools tool installation Method (method i). Install setuptools using ez_setup.pyEnter Https://pypi.python.org/pypi/setuptools Download ez_setup.py
This is setuptools proud of a way to install, only need a 8K as a script ez_setup.py, you can automatically install the user including Setuptools itself many Python packages. In this way, users only need to download ez_setup. Py and run, you can automatically download and install the appropriate setuptools egg files for the current Python version of the user (of course, users need Python 2.3.5 or more, and 64-bit OS users need more than Python 2.4 versions). In addition, this script installs the executable Easy_install script to the user's all operating system where the Python executable script should normally be installed (for example, Windows users will be installed in the Scripts directory under the Python installation directory). For more detailed instructions and precautions on this installation method, please refer to its official instructions (see extended reading). The simple installation commands are as follows: Wget-q Ez_setup. PY Download address (see extended reading) When you are finished installing, it is best to ensure that(Method II). Install Setuptools with the full installation packageOf course, users can also install them directly using the Setuptools release version. This is also a handy way for users who use Windows, and the official package management warehouse for many Linux distributions contains a version of Setuptools. For example, if you're using Ubuntu like I do, installing setuptools is simply doing the following:
# Apt-get Install Python-setuptoolsInstall Easy_install package-name, such as Easy_install Pylab Module Uninstall Easy_install-m package-name, such as Easy_install-m Pylab easy_install-m The package name, you can uninstall the package, but remove the legacy files manually after uninstalling.

Setuptools It can automatically install the module, only need you to give it a module name can be, and automatically help you solve the problem of module dependencies. In general, the modules that are installed with Setuptools are automatically placed in a directory where the suffix is. Egg.

In Windows, easy_install This command in the Python installation directory in the scripts inside, so you need to add scripts to the environment variable path, which is more convenient to use, Linux does not need to pay attention to this problem.






Install NumPy, scipy, matplotlib, OPENCV, etc. in Ubuntu

Unlike Python (x,y), you need to manually install the various modules of scientific computing in Ubuntu,

How to install Ipython, NumPy, scipy, Matplotlib, PyQt4, Spyder, Cython, SWIG, ETS, OpenCV:

Installing a Python module under Ubuntu can usually be usedapt-get and PIP commands。 The Apt-get command is the package Management command for Ubuntu, and the PIP is a tool for Python to install the extension module, and the PIP usually downloads the source code for the extension module and compiles the installation.

The Python2.7.3 is installed by default in Ubuntu 12.04, first installed by the following command Pip,pip is a Python tool for installing and managing the extension library.
sudo apt-get install Python-pip

Installing the Python development environment"Can also be seen in Linux to build the Python development environment installation Pycharm IDE" To facilitate the future compilation of other extensions, Occupy space 92.8M:
sudo apt-get install Python-dev
IPython
In order to install the latest version of Ipython 0.13beta, you need to download the Ipython source code and execute the installation command. An improved version of Ipython notebook is provided in Ipython 0.13beta. The following command installs the version management software git first and then downloads the latest version of the Ipython source code from the Ipython development code base and executes the installation command by using the git command:
Cd
sudo apt-get install git
git clone https://github.com/ipython/ipython.git
CD Ipython
sudo python setup.py install
If you are installing the latest stable version, you can enter:
sudo apt-get install Ipython
After the installation is complete, enter the Ipython command to test whether it will start properly.
In order for Ipython notebook to work, you also need to install Tornado and PYZMQ:
sudo pip install tornado
sudo apt-get install Libzmq-dev
sudo pip install PYZMQ
sudo pip install pygments
The following test Ipython:
Cd
mkdir Notebook
CD Notebook
Ipython Notebook

In order to use the Latex mathematical formula offline in Ipython, you need to install Mathjax, first enter the following command to start Ipython notebook:
sudo ipython Notebook
In the Ipython Notebook interface, enter:
From IPython.external.mathjax import Install_mathjax
Install_mathjax ()


Install numpy,scipy and matplotlib

You can quickly install these three libraries through the Apt-get command:
sudo apt-get install Python-numpy
sudo apt-get install python-scipy
sudo apt-get install Python-matplotlib

To view the NumPy version and path:
Import NumPy
Print numpy.__version__
Print numpy.__file__


If you need to compile the installation via PIP, you can first install all the libraries needed for compilation with the Apt-get command:
sudo apt-get build-dep python-numpy
sudo apt-get build-dep python-scipy
Then install through the PIP command:
sudo pip install NumPy
sudo pip install scipy
Many libraries will be installed via BUILD-DEP, including Python 3.2.


PYQT4 and Spyder
The following command installs the PYQT4,QT interface Designer, PYQT4 development tools, and Documentation:
sudo apt-get install Python-qt4
sudo apt-get install Qt4-designer
sudo apt-get install Pyqt4-dev-tools
sudo apt-get install Python-qt4-doc
After installation, the document is located at:
/usr/share/doc/python-qt4-doc
After installing the PYQT4, install Spyder with the following command:
sudo apt-get install Spyder

Because Spyder is constantly updated, the following command allows you to install the latest version:
sudo pip install Spyder--upgrade


Cython and Swig
Cython and Swig are tools for writing Python extension modules:
sudo pip install Cython
sudo apt-get install Swig
Enter Cython--version and swig-version view versions.


Ets
ETS is a set of scientific computing packages developed by Enthought company, in which the Mayavi realizes three-dimensional visualization of data through VTK.
First install the libraries needed to compile the ETS by using the following command:
sudo apt-get install Python-dev libxtst-dev scons python-vtk pyqt4-dev-tools python2.7-wxgtk2.8 python-configobj
sudo apt-get install Libgl1-mesa-dev Libglu1-mesa-dev

Create an ETS directory and download ets.py in this directory, run ets.py can copy the latest version of the ETS source and install:
mkdir ETS
CD ETS
wget https://github.com/enthought/ets/raw/master/ets.py
Python ets.py clone
sudo python ets.py develop
#sudo python ets.py Install or run install installation

If everything works, then the input MAYAVI2 command will start the Mayavi.


OpenCV

PYTHON-OPENCV:

Environment
Ubuntu 12.04 LTS
Python 2.7.3
OpenCV 2.3.1-7

Installation dependencies
sudo apt-get install libopencv-*
sudo apt-get install PYTHON-OPENCV
sudo apt-get install Python-numpy

"Using OpenCV in Python"

"Python uses OpenCV for face recognition."

"Ubuntu 12.04 install OpenCV 2.4.2"

"Install OPENCV and test Python-opencv under Ubuntu"

"Ubuntu under OpenCV collaboration with Python"

"Install PYTHON-OPENCV configuration under Ubuntu"

Dpkg-l PYTHON-OPENCV command to see where the search is installed root@ubuntu:~ #dpkg-L PYTHON-OPENCV
/.
/usr
/usr/share
/usr/share/python-support
/usr/share/python-support/python-opencv.public
/usr/share/doc
/usr/share/doc/python-opencv
/usr/share/doc/python-opencv/copyright
/usr/share/pyshared
/usr/share/pyshared/cv.py
/usr/lib
/usr/lib/pyshared
/usr/lib/pyshared/python2.7
/usr/lib/pyshared/python2.7/cv2.so
/usr/share/doc/python-opencv/changelog. Debian.gz


Test OpenCV Install well no:

[python] view plain copy

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.