Python code packaging and release details, python code details
In a python program, A. py file is used as a module and different functions are defined in each module. When we want to use a function in a module, we must first import this module. Otherwise, the function will be undefined.
The following describes how to package and install packages.
In this example, a simulated logon program is created:
The logIn. py file code is as follows:
pwd=int(raw_input('please input your passward: '))if pwd==123: print 'success'else: print 'error'
I. Packaging
1. Create a folder to store the. py file that we will use for release. (now we create a folder named distribution and put logIn. py in this folder)
2. Create a new setup. py file in the distribution folder. The Code is as follows:
From distutils. core import setupsetup (name = 'login', # This is the final packaged file name version = '1. 0.0 ', py_modules = ['logint'], # what to pack ,. py file ,)
3. In the end, cd is included in the distrbution folder, and then the following command is run:
python setup.py sdist
This example shows several more files in the folder. In the distfolder, login-1.0.0.tar.gz is our release package;
Ii. Install the package to a local copy:
sudo python setup.py install
Path:/usr/local/lib/python2.7/dist-packages
How to Package Multiple python programs
What is the package? You can use a py2exe plug-in to compress an exe file.
Python packaging problems
This is related to the current path of cmd.
Try:
D:
Python d: \ nester \ setup. py sdist