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 > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article mainly introduces "how to run Python programs and download dependent libraries". In daily operation, I believe many people have doubts about how to run Python programs and download dependent libraries. Xiaobian consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful to answer the doubts of "how to run Python programs and download dependent libraries". Next, please follow the editor to study!
Catalogue
How to run the Python program
Interactive programming
Write source files
On print function
Install PyCharm development tools
Download the installation package
Installation
Use
How to download dependent libraries?
Check to see if the installation
How to run the Python program
The Python language is an interpreted scripting language, which generally supports two ways of running code.
Interactive programming
Enter the code directly in the command line window, press enter to run the code, and you can immediately see the running result. After executing one line of code, you can continue to execute the next line of code, enter again and view the results. It's like talking to a computer. It can be run from the command line or terminal or Python's IDLE. As shown in the following figure, the Python code is run through the terminal under Mac OS. Enter the command python3 in the terminal to enter the interactive programming window. The code is executed line by line.
You can exit the interactive programming window with the exit () command. Through IDLE, you can directly enter the Python code you want to run.
Interactive programming can only deal with some simple programs, but in actual programming, we still use the way of writing Python source files to run.
Write source files
Create a source file, put all the code in the source file, and let the interpreter read and execute the code in the source file line by line, until the end of the file, that is, batch execution of the code.
The Python source file is a plain text file without any special format inside, and you can open it using any text editor, such as notepad, EditPlus, and so on.
Here I write the following code in notepad:
Print ("Hello, World") a = 120b = 230print (a + b)
Then name the file demo_1.py. Because all Python source files are suffixed with .py. There are also two modes of operation here.
Run the source file using the IDLE tool that comes with Python
Open the IDLE tool, then click the file- > open menu to open the demo_1.py source file to run the source file. Run the source file in a command line tool or terminal
Enter the command line tool, change to the directory where demo_1.py is located, and enter the following command
Python3 demo_1.py
You can run the source file. The running result is shown in the following figure:
On print function
Statements like print ("Hello, World") appear many times in the previous example, and the print function is used to output strings on the screen. This function is used as follows:
Print ("string contents")
Or
Print ('string content')
This means passing the string to print in parentheses () and asking print to display the string, which is called a Function in Python. However, it should be noted that quotation marks and parentheses must be entered in English half-corner.
The print function can also output numbers like print (a + b) above.
You can also pass in multiple items that you want to output into the print. Print ('Hello', 1)
However, you cannot directly concatenate strings and numbers and pass them to the print function, like print ('Hello' + 1) is not allowed.
You must convert the number to the string print ('Hello' + str (1)) and pass it to the print function in concatenation, which will be described in more detail in a later article.
Install PyCharm development tools
If you want to do a good job, you must first sharpen its tools. In actual development, we all code through IDE (integrated development environment), so why use IDE? This is because IDE integrates language editors, automatic building tools, debuggers and other tools that make it very convenient for us to develop quickly. For example, we can think of the integrated development environment as a desktop. Although it only needs the host to run, it still needs a monitor, keyboard and so on.
PyCharm is such an IDE development tool that makes people feel good about it. Here is a brief introduction to its installation process.
Download the installation package
Click on the link https://www.jetbrains.com/pycharm/download/
Go to the next page, PyCharm has professional version and community version. Among them, the professional version needs to be purchased before it can be used, while the community version is free. The community version is sufficient for day-to-day Python development. So we chose the community version of PyCharm to download and install. Click the button shown in the figure below to download the installation package.
Installation
After the installation package is downloaded, we double-click the installation package to install it. The installation process is relatively simple. Basically, you only need to install the default settings by clicking the Next button every step, but you need to set it up when the window below appears.
After setting up, click Next to proceed to the next step of installation, until all the installation is complete.
Use
The only thing to note when using here is to set the interpreter. By default, the No interpreter is prompted in the selection box of Project Interpreter, that is, the interpreter is not selected.
So you need to click the set button to set the interpreter, and here select Add Local to set the local interpreter.
After opening the settings page of the interpreter, the tab page Virtualenv Environment is selected by default
Here, Location is used to set up the virtual environment of the project. For more information, please see pycharm setting Virtual Environment and changing Image tutorials Base interpreter to set the path of the interpreter.
At this point, the scaffolding for developing Python is ready, and the next step is coding.
How to download dependent libraries?
The next thing you need to introduce is Python's package management tool pip, which is used to download and install the third-party libraries that the Python project depends on. Of course, you can also find and uninstall third-party libraries.
Check to see if pip is installed-- version # Python2.x version command pip3-- version # Python3.x version command
If it is not already installed, you can use the following methods to install it:
Curl https://bootstrap.pypa.io/get-pip.py-o get-pip.py # download the installation script sudo python3 get-pip.py # run the installation script
Install the package:
Pip install [packagename] # latest version pip install [packagename] = = 1.0.1 # specified version pip install [packagename] > = 1.0.1 # minimum version
For example, I want to install the requests package.
Pip install requests==2.21.0
View installed packages
Pip list
Uninstall the package
Pip uninstall [packagename]
Search package
Pip search [packagename]
Display installation package information
Pip show
View the details of the specified package
Pip show-f [packagename] at this point, the study on "how to run Python programs and download dependent libraries" is over. I hope I can solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!
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.