Python Code Packaging and publishing

Source: Internet
Author: User
This article mainly describes the Python code packaging and publishing methods, the need for friends can refer to the following

In a Python program, a. py file is treated as a module that defines different functions in each module. When we want to use a certain function in a module, we must first import the module, otherwise there will be a case where the function is undefined.

The following records are the methods for packaging and installing packages.

The example in this article is to create a program that simulates login:

The login.py file code is as follows:

Pwd=int (raw_input (' Please input your passward: ')) if pwd==123:  print ' success ' else:  print ' ERROR '

First, packaging

1. First create a folder that is used to store the. py file we will use for publishing, (now we create a folder named distribution, put login.py in this folder)

2. Create a new setup.py file code in the distribution folder as follows:

From Distutils.core import setupsetup (name= ' logIn ',  #这个是最终打包的文件名 version= ' 1.0.0 ', py_modules=[' Loginr '], #要打包哪些, . py file,)

3. In the end, CD into this distrbution folder, then move the line as follows:

Python setup.py sdist

So in the folder there are a few more files, in the Dist folder, Login-1.0.0.tar.gz is our release package;

Second, install the package to the local copy:

sudo python setup.py install

Path is:/usr/local/lib/python2.7/dist-packages

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.