In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
This article to share with you is about how to package Python applications for Linux, Xiaobian feel quite practical, so share with you to learn, I hope you can gain something after reading this article, not much to say, follow Xiaobian to see it.
One way to install Python apps on Debian-based operating systems such as Debian or Elementary OS is to use the dh_virtualenv tool. It can build a.deb package that encapsulates a Python virtual environment outside of the app and deploy it at installation time.
Packaging with dh_virtualenv
First, you need to install the tools required for dh_virtualenv. The documentation for dh_virtualenv provides all installation options. On a Debian-based system, I type:
apt-get install dh-virtualenv devscripts
Although the devscripts package is not required, it simplifies subsequent operations.
Now, create a directory to store the source code. Since this is a native, unofficial HTTP ie package, I'll call it myhttp. Next, let's create some files within myhttp that provide metadata to the Debian build system.
First, create the debian/control file:
Source: myhttpSection: pythonPriority: extraMaintainer: Jan Doe Build-Depends: debhelper (>= 9), python3.7, dh-virtualenv (>= 0.8)Standards-Version: 3.9.5 Package: myhttpArchitecture: anyPre-Depends: dpkg (>= 1.16.1), python3.7, ${misc:Pre-Depends}Depends: ${misc:Depends}Description: http client Useful for doing stuff
So what is this information? As the Debian documentation points out:
"Lines 1 - 7 contain control information for the source package. Lines 9 - 13 contain control information for binary packets. "
Here are what I use:
The value of Section is mostly meaningless to us, but it needs to exist. It makes sense to provide information to the bootstrapped UI installer, but for this package, it doesn't.
The correct value for Priority for third-party packages like this is extra.
It is strongly recommended that you fill in the Maintainer field with the correct contact information. But it doesn't have to be your personal email, if the package is maintained by a team and you want to send questions to the team's email alias, such as Infrastructure Team.
The Build-Depends field identifies that you need debhelper, python, and dh-virtualenv to build the package: the package build process ensures that these dependencies are installed at package build time.
The Standards-Version field is primarily intended for people to see. It shows the guidelines you follow. This guide is based on dh-virtualenv's official documentation, which is based on Debian's 3.9.5 guide. It is always best to name source packages and binary packages the same.
The Architecture field should be Any, unless the virtual environment may contain architecture-specific files. Otherwise, it's better to select this field as any.
Keep the Pre-Dependents list the same: it's a very strict form of dependency, and you'll rarely need more than the minimal dependencies suggested here. Dependency items are usually calculated accurately by the build system, so there is no reason to specify them manually.
If your package is primarily intended for internal use, the Description field may require minimal information or a link to the company wiki, otherwise more information would be more useful.
Then create the debian/compat file, which exists primarily for historical purposes:
$ echo "9" > debian/compat
Next, an update log is created to inform package users of what has changed since the last release. The easiest way is to create a template using dch --create and then fill in the values.
After filling it out, it looks like:
myhttp (2.0.0-1) stable; urgency=medium * Initial release. -- Jan Doe Fri, 27 Mar 2020 01:09:22 +0000
Now you need to tell the tool to install HTTPie, but which version?
Create a looser version of the requirements.in file:
httpie
Typically, a looser requirements file will contain only the project's direct dependencies and specify the minimum version when needed. It is not always necessary to specify a minimum version: these tools often prefer to convert dependencies to the "latest version possible." If your Debian package corresponds to an internal Python package, which is a common case in internal applications, then the loose requirements file will look similar: a single line containing only the package name.
Then use pip-compile (available by installing PyPI package pip-tools):
$ pip-compile requirements.in > requirements.txt
This generates a strict dependency file called requirements.txt:
## This file is autogenerated by pip-compile# To update, run:## pip-compile requirements.in#certifi==2019.11.28 # via requestschardet==3.0.4 # via requestshttpie==2.0.0 # via -r requirements.inidna==2.9 # via requestspygments==2.6.1 # via httpierequests==2.23.0 # via httpieurllib3==1.25.8 # via requests
Finally, write a debian/rules file to create the package. Because dh_virtualenv handles all the hard stuff, the rules file is simple:
#!/ usr/bin/make -f %: dh $@ --with python-virtualenv --python /usr/bin/python3.7
Be sure to specify a Python interpreter. By default it uses/usr/bin/python, which is Python2, but you should use a supported Python version.
That's it. Next up is the build package:
$ debuild -b -us -uc
This generates a file in the parent directory similar to myhttp_2.0.0-1_amd64.deb. This file can be installed on any compatible system.
Generally, it is best to build Debian packages for a specific platform (e.g. Debian 10.0) on the same platform.
You can save this Debian package in a software repository and install it on all relevant systems using tools such as Ansible.
Packaging applications for Debian-based systems is a multi-step process. Using dh_virtualenv will make the process simple and straightforward.
The above is how to package Python applications for Linux, Xiaobian believes that some of the knowledge points may be what we see or use in our daily work. I hope you can learn more from this article. For more details, please follow the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.