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:
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