Let’s take the translation program as an example. Last time, I talked to you about application packaging under Windows. This time, I will tell you that Python files can be executed by themselves under Linux, so there is no need for python xxx.py. It's very simple, just add the following sentence at the top of the Python source file! #!/usr/bin/python3 /usr/bin/python3 is the directory where the python3 interpreter is located under Ubuntu. You can use which python3 to view it. Then execute chmod +x ./xxx.py to add executable permissions to the Python script For example, here sudo chmod +x ./translate.py Finally run ./translate.py Then... an error was reported -bash: ./translate.py: /usr/bin/python3^M: interpreter error: no such file or directory Why? This is the source code I wrote under Win7, and then transferred it to Ubuntu using WinSCP. This caused a problem: the code written under DOS is incompatible with Linux. Solution: sudo vim translate.py :set ff=unix Then execute ./translate.py OK, it runs perfectly, but if you look closely, it seems not perfect, because every time you have to switch to the directory where the file is located to run it, in order to use the program more conveniently, we can connect translate.py to /usr/bin, or /usr/local/bin, etc., in the directory where the system environment variables are configured. sudo ln -s /xxxx/xxxx/xxxx/translate.py /usr/local/bin/dict /xxxx/xxxx/xxxx/ is the absolute path where translate.py is located /usr/local/bin/dict, dict is the name of translate.py after soft linking Operation effect OK, won’t there be a ready-made translation program in my Ubuntu system from now on? Isn’t it wonderful! The above method of implementing Python scripts to run directly under Ubuntu is all the content that the editor shares with you. I hope it can give you a reference, and I also hope that you will support 123WORDPRESS.COM. You may also be interested in:
|
<<: Why do select @@session.tx_read_only appear in DB in large quantities?
>>: How to implement real-time polygon refraction with threejs
1. Test environment name Version centos 7.6 docke...
This document records the installation and config...
1. Docker Network Mode When docker run creates a ...
In fact, many companies have functions similar to...
1. Download the zip installation package Click he...
When using Docker in a production environment, da...
This article shares with you how to use Navicat t...
What should I do if Linux does not support all co...
Written in front I have been writing a special to...
Vue $http get and post request cross-domain probl...
Based on daily development experience and relevan...
Table of contents 1. What is a JavaScript engine?...
This article shares the specific code for WeChat ...
IDEA is the most commonly used development tool f...
The offline installation method of MySQL_8.0.2 is...