In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
How to publish your Python application, I believe that many inexperienced people do not know what to do, so this article summarizes the causes of the problem and solutions, through this article I hope you can solve this problem.
I remember reading an article that said that Brother long was going to sell foxmail, and the buyer was Lei Jun. Lei Jun meant: I can write about it. So there was no deal.
My feeling is that the software written by programmers is valuable only if it is used by people who do not understand the technology. Otherwise, what I get is: I can also write this.
We are not Brother long, can not write a great foxmail, but it is possible to write an automated script, even a small script, as long as it can help, other people also have a need.
So how do you publish your program to others?
I have tried some common packaging tools, py2exe,pyinstaller, which have some disadvantages:
Unstable. Obviously, my own computer can run, but if I put it on another computer, it will report an error and flash, indicating that the system is missing xxx.dll dynamic link library files.
The configuration file is complex. Simple packaging may not be able to meet the needs, more complex ones have to write configuration files, and sometimes clearly written configuration files do not take effect.
The packing file is large and the startup is slow. Instead of compiling into executable files, these tools package the Python interpreter and dependent tripartite libraries together, and if packaged into a file, run very slowly because they are loaded into memory together.
Another way is to write Web applications and publish them in the form of Web sites, H5, WeChat Mini Programs, etc. This threshold is a bit high. You need to have some experience and be familiar with Web development, as well as buy servers or cloud products.
Today, let's share a very simple and feasible way to release Python applications. After release, users only need to double-click a file to start your application, and people who don't know any technology will use it.
The specific way is to use the embedded Python package released on the official website, but this only applies to Windows, which is not a big deal, most non-programmers use Windows. "if it's Mac, please use py2app to pack it."
Visit www.python.org to download Windows embeddable package. If your computer is 64-bit, download 64-bit. If you want to do something more generic, use 32-bit, because 64-bit computers can run 32-bit programs, and vice versa.
Here I choose python-3.9.5, decompress and get the python-3.9.5-embed-amd64 folder, which is an installation-free Python environment, which can run stably when copied to other Windows platforms. Enter the directory, execute.\ python, as long as it is a standard library can be imported.
However, we still need to make two changes before we can use it officially.
Install pip tools
It is impossible for us to write programs using only standard libraries, but also third-party libraries such as requests, so we need to configure pip for the Python environment.
Download the get-pip.py file from here
Https://bootstrap.pypa.io/get-pip.py
Store the get-pip.py in the python-3.9.5-embed-amd64 folder, and then go to that directory to execute:
.\ python get-pip.py-no-warn-script-location
To complete the installation of pip:
At this point, pip is installed under Lib\ site-packages.
Use pip
Now install requests and test it with import. I found that I had made a mistake and said that I couldn't find pip.
OK, now go to the Python interpreter environment, take a look at Python's search path sys.path, and find that there is no Lib\ site-packages, so let's add it.
Add search path
Go to the python-3.9.5-embed-amd64 folder and modify the file python39._pth file
After modification, the contents are as follows:
Python39.zip. .. # Uncomment to run site.main () automatically import site
Two changes have been made here, one is to add the parent directory, and the other is to uncomment import site.
The purpose of adding the parent directory is to store some self-written Python scripts outside the directory, so that the directory python-3.9.5-embed-amd64 can remain independent and not put in any self-written scripts, so that files related to the Python environment will not be contaminated.
Uncomment import site will automatically run site.main (). If you look at the source code of Python's Lib/site.py, you can see that site.main () will automatically add Lib\ site-packages to sys.path. Of course, it's more than that, and that's all we need to know first.
Next, check sys.path again and find that Lib\ site-packages is already inside:
Install requests again and import the test, successfully:
Release program
Now you can write the code release program. I have written a script main.py here to get the text entered by the user, automatically call Baidu translation, and return the translation result, as shown below:
Import json import requests url=' https://fanyi.baidu.com/sug' kw = input ('Please enter the text to be translated:') kw = {'kw':kw} header = {' User-Agent':'Mozilla/5.0 (Macintosh Intel Mac OS X 10: 15: 0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.132 Safari/537.36'} response = requests.post (url=url, data=kw, headers=header) response.raise_for_status response.encoding = response.apparent_encoding content_json = response.json () # is converted to ascii encoding by default, so it needs to be set to false content = json.dumps (content_json,ensure_ascii=False) result = json.loads (content) print (result ["data"])
Then put it side by side with the python-3.9.5-embed-amd64 text folder, considering that someone will not open the command window, we also need to make a bat script file, which the user can double-click to run our program, as follows:
Cmd.exe / K.\ python-3.9.5-embed-amd64\ python main.py
Here cmd passes in the / K parameter so that the command window is not closed after the program is run, so that we can see what the program returns, otherwise the window will be gone.
The final folder is as follows:
Now compress main.py, double-click run. Bat, python-3.9.5-embed-amd64 into a folder embed_python.7z and send it to the person who needs it. After he decompresses it, double-click the bat file to run your program:
After compression, it is only 10 MB in size, and it can be transmitted directly on Wechat.
After reading the above, do you know how to publish your Python application? If you want to learn more skills or want to know more about it, you are welcome to follow the industry information channel, thank you for reading!
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.