Python Code packaging and publishing detailed _python

Source: Internet
Author: User

In a Python program, a. py file is treated as a module, and different functions are defined in each module. When we want to use one of the functions in a module, we must first import the module, otherwise the function is undefined.

The following is a documented method for packaging and installing packages.

The example in this article is to establish a program that simulates logins:

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. Create a folder to store the. py file that we will use for publishing (now we have 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 setup
setup (
 name= ' logIn ',  #这个是最终打包的文件名
 version= ' 1.0.0 ',
 py_ modules=[' Loginr '], #要打包哪些,. py file,
 )

3. In the end, the CD is in the Distrbution folder, and then the motion line follows the following command:

Python setup.py sdist

This in the folder will be 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

The 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.