Python package installation and installation package production

Source: Internet
Author: User

1. Single File module : Copy files directly to $python_dir/lib this is the class library directory (you can directly place a single file or a single package here)


2. Multi-file module , with Setup.py:python setup.py install uninstall can only be manually deleted, generally installed in the System Class library directory

Python setup.py install--record files.txt Log the path to the file after installation (uninstall Cat Files.txt | Xargs RM-RF Delete these files)

3.easy_ins Tal L Way

1) Download ez_setup.py, run Python ez_setup

2) Easy_install PackageName

Easy_install Package.egg

Easy_install *.egg

4.pip mode

Install the PIP tool First: Easy_install PIP (Pip can be installed by Easy_install and also loaded into the Scripts folder. )

Install: Pip Install PackageName

Update: Pip install-u packagename

Removal: Pip Uninstall PackageName

Search: Pip Search PackageName


5. Homemade setup.py Installation Kit

Although Python modules can be copied and installed, it is generally recommended to make an installation package, which is to write a setup.py file to install.


Use of setup.py file:

% python setup.py build #编译

% python setup.py install #安装

% python setup.py sdist #制作分发包

% python setup.py bdist_wininst #制作windows下的分发包

% python setup.py bdist_rpm


setup.py File Writing:

The main implementation of a setup function in setup.py, most of which is descriptive, the most important is the packages parameter, lists all the package, you can use their own find_packages to dynamically obtain the package. So the setup.py file is actually very simple to write.


A simple example:

(1). Suppose you want to distribute a module called foo, file name foo.py

{Import Sys

Def get ():

Return Sys.path

},

Then the setup.py content is as follows:

From Distutils.core Import Setup

#from setuptools Import Setup, find_packages

Setup (name= ' foo ',

Version= ' 1.0 ',

py_modules=[' foo '),

)

(2). Then, run Python setup.py sdist create a source package for the module

In the current directory, a dist directory is created with a file named Foo-1.0.tar.gz, which is a package that can be distributed (if you use command python setup.py Bdist_egg, Then the Foo-1.0-py2.7.egg package is generated in the Dist directory, and the first sentence in setup.py needs to be changed from Setuptools Import Setup). After the user gets the package, unzip it and execute it in the foo-1.0 directory: Python setup.py install, then, Foo.py will be copied to the Python classpath and can be imported (if installed as an egg file, the egg file will be copied to the Dist-packages directory).


This article from "Tech record" blog, declined reprint!

Python package installation and installation package production

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.