Home > Backend Development > Python Tutorial > Packaging and publishing of Python code

Packaging and publishing of Python code

不言
Release: 2018-04-24 15:25:27
Original
2509 people have browsed it

This article mainly introduces the method of packaging and publishing Python code. Friends in need can refer to it

In the python program, a .py file is regarded as a module and is defined in each module different functions. When we want to use a function in a module, we must first import the module, otherwise the function will be undefined.

Recorded below is the method of packaging and installing the package.

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

The logIn.py file code is as follows:

pwd=int(raw_input('please input your passward: '))
if pwd==123:
  print 'success'
else:
  print 'error'
Copy after login

1. Packaging

1. First create a folder. This folder 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 in the distribution folder with the following code:

from distutils.core import setup
setup(
 name='logIn',  #这个是最终打包的文件名
 version='1.0.0',
 py_modules=['logInr'], #要打包哪些,.py文件,
 )
Copy after login

3. In the final step, cd to the distrbution folder, and then run the following command:

python setup.py sdist
Copy after login

This way There are a few more files in the folder. In the dist folder, logIn-1.0.0.tar.gz is our release package;

2. Install the package to the local copy Medium:

sudo python setup.py install
Copy after login

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

The above is the detailed content of Packaging and publishing of Python code. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template