current position：Home>[Python from introduction to mastery] (II) how to run Python? What are the good development tools (pycharm)
[Python from introduction to mastery] (II) how to run Python? What are the good development tools (pycharm)
2022-01-30 10:03:19 【Mainong Feige】
Hello! , I'm Manon Feige , Thank you for reading this article , Welcome to three links with one button . This is a Pyhon The second in a series , This article mainly introduces how to run Python Program and installation PyCharm development tool .
Dry cargo is full. , Recommended collection , I need to use it. I need to look at it from time to time . If you have any questions and need , Welcome to leave a message ~ ~ ~.
In the last article, we mainly introduced Python The basic concept of language , Understand what it is , What are the advantages and disadvantages . This article mainly introduces how to run Python Program , How to install PyCharm Development tools and how to use PyCharm To run the Python Program .
How to run Python Program
Python Language is an interpretive scripting language , Such a programming language generally supports two code running modes .
Enter the code directly in the command line window , Press enter to run the code , And you can see the running results immediately , Execute a line of code , You can continue to execute the next line of code , Enter again and see the results , It's like talking to a computer . You can use the command line or the terminal or Python Of IDLE To run the . As shown in the figure below, it is through Mac OS Terminal operation under Python Code . Enter command in terminal
python3 You can enter the interactive programming window . The code is executed line by line . adopt
exit() Command to exit the interactive programming window . adopt IDLE If so, you can directly enter the desired Python Code .
Interactive programming can only deal with some simple programs , In actual programming, we still use writing Python Source file to run .
Write source file
Create a source file , Put all the code in the source file , 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 code . Python The source file is a plain text file , There is no special format inside , You can open it with any text editor , Like Notepad ,EditPlus wait . Here I write the following code with Notepad ：
print(" Hello , The world ") a = 120 b = 230 print(a + b) Copy code
Then name the file demo_1.py. Because of all the Python The suffix names of source files are .py. There are also two modes of operation .
- Use Python Self contained IDLE The tool runs the source file open IDLE Tools , And then click
file->openThe menu opens demo_1.py The source file can be run .
- Run the source file in the command line tool or terminal
Enter command line tools , Switch to demo_1.py directory , Then type the following command
python3 demo_1.py Copy code
You can run the source file . The results are shown in the following figure :
About print function
In the previous example, something like
print(" Hello , The world ") Such a statement ,print The function outputs a string on the screen . The use of this function is ：
print(" String content ") Copy code
print(' String content ') Copy code
That is, put the string in parentheses () In the passed to print, Give Way print Display the string , It's written in Python Is called a function in （Function）. But here's the thing Both quotation marks and parentheses must be entered in English half width state . print Functions can also output numbers, like the above
print(a + b). Also you can ask the print Pass in multiple contents you want to output .
print(' Hello ', 1)
However, you can't directly splice strings and numbers and pass them to print function , image
print(' Hello '+1) It's not allowed .
You must convert a number to a string
print(' Hello '+str(1)) Then pass it to print function , About str function , The following article will introduce in detail .
install PyCharm development tool
If a worker wants to do a good job, he must sharpen his tools first , In actual development, we are all through IDE（ Integrated development environment ） To code , Why use IDE Well ？ This is because IDE Integrated language editor , Auto build tool , Debugger and other tools can greatly facilitate our rapid development . For example We can think of an integrated development environment as a desktop . Although it only needs a host to run , however , Still need a monitor , The keyboard can only be used very well . PyCharm It's such a cool one IDE development tool . Here is a brief introduction to its installation process
Download installation package
Click the link www.jetbrains.com/pycharm/dow…
Go to the next page ,PyCharm Professional edition and Community Edition . among , The professional edition needs to be purchased to use , The Community Edition is free . Community Edition for everyday Python Development is completely enough . So we choose PyCharm Download and install the community version of . Click the button shown in the figure below to download the installation package .
After the installation package is downloaded , We can double-click the installation package to install , The installation process is relatively simple , Basically, you only need to install the default settings. Click... At each step Next button , However, when the following window appears, you need to set . After setting, click Next Go to the next step of installation , Until all installations are complete . After the installation is completed, you can use .
- Double click on the diagram 1 Click the icon in the to open PyCharm Start the programming journey .
2. After double clicking the icon and waiting for a while, the following interface will appear , For the first time PyCharm If so, a picture will appear 2 Interface in . The interface has three options ： 1. Create New Project If you want to create a new Python project , You can click this option 2. Open If you want to open an old Python project , You can click this option 3. Check out from Version Control If you want to go from Git perhaps SVN Click this option if you want to pull items up . 3. Click on Create New Project The operation will enter the interface shown in Figure 3 , In this interface, we can modify the project name and path , And set up A virtual environment . Here we will change the name from untitled Change to hello_world, And then click Create Press the button to enter figure 4 page
- In the figure 4 On the page, we can see the newly created project , Selected items Right click -->New You can create a list of files. We can create ordinary files , Folder ,Python Packages and Python file .
Here I create a file called hello.py Of Python file . 5. Write code and run debugging stay hello.py In the file, I wrote two pieces of output code . then , In the Right click the edit window area Choose Run 'hello' perhaps Debug 'hello' Run . . among **Run 'hello'** It's a normal operating mode ,Debug 'hellow' It's debug mode . 6. Choose Run ' hello' The program running results will be output in the console : 7. Choose Debug 'hello' The following operation diagram box will appear , There are debugging windows and console windows . What is used here is native Python Environmental Science , If you need to specify a virtual environment , You can make the following settings . So you need to click the set button to set the interpreter , Choose here Add Local Set the local interpreter . After opening the setup page of the interpreter , The default is Virtualenv Environment This tab page , here Location Is the virtual environment used to set up the project , For details, please refer to pycharm Summary of the use of , Set up the virtual environment , Replace image source Base interpreter Used to set the path of the interpreter .
How to download dependency Libraries ？
What we need to introduce next is Python Package management tools pip, Its function is to download and install Python Third party libraries that the project relies on . Of course, you can also find , Uninstall third party libraries .
See if it is installed
pip --version # Python2.x Version command pip3 --version # Python3.x Version command Copy code
If not already installed , You can use the following methods to install ：
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 Copy code
- Installation package ：
pip install [packagename] # The latest version pip install [packagename]==1.0.1 # Specify the version pip install [packagename]>=1.0.1 # Minimum version Copy code
For example, I want to install requests package .
pip install requests==2.21.0 Copy code
- View installed packages
pip list Copy code
- Uninstall package
pip uninstall [packagename] Copy code
- Search package
pip search [packagename] Copy code
- Show installation package information
pip show Copy code
- View the details of the specified package
pip show -f [packagename] Copy code
This article mainly introduces how to run Python Program , First, it introduces how to run through the command line Python Program . then , Describes how to install IDE development tool PyCharm. I hope it can help readers .
The whole network has the same name 【 Manon Feige 】. Short step , A thousand miles , Enjoy sharing I'm Manon Feige , Thank you again for reading this article .
author[Mainong Feige],Please bring the original link to reprint, thank you.
The sidebar is recommended
- Similarities and differences of five pandas combinatorial functions
- Python beginner's eighth day ()
- Necessary knowledge of Python: take you to learn regular expressions from zero
- Get your girlfriend's chat records with Python and solve the paranoia with one move
- My new book "Python 3 web crawler development practice (Second Edition)" has been recommended by the father of Python!
- From zero to familiarity, it will take you to master the use of Python len() function
- Python type hint type annotation guide
- leetcode 108. Convert Sorted Array to Binary Search Tree（python）
- For the geometric transformation of Python OpenCV image, let's first talk about the extraordinary resize function
- leetcode 701. Insert into a Binary Search Tree （python）
guess what you like
For another 3 days, I sorted out 80 Python datetime examples, which must be collected!
Python crawler actual combat | using multithreading to crawl lol HD Wallpaper
Complete a python game in 28 minutes, "customer service play over the president card"
The universal Python praise machine (commonly known as the brushing machine) in the whole network. Do you want to know the principle? After reading this article, you can write one yourself
How does Python compare file differences between two paths
Common OS operations for Python
[Python data structure series] linear table - explanation of knowledge points + code implementation
How Python parses web pages using BS4
How do Python Network requests pass parameters
Python core programming - decorator
- Python Network Programming -- create a simple UPD socket to realize mutual communication between two processes
- leetcode 110. Balanced Binary Tree（python）
- Django uses Django celery beat to dynamically add scheduled tasks
- The bear child said "you haven't seen Altman" and hurriedly studied it in Python. Unexpectedly
- Optimization iteration of nearest neighbor interpolation and bilinear interpolation algorithm for Python OpenCV image
- Bilinear interpolation algorithm for Python OpenCV image, the most detailed algorithm description in the whole network
- Use of Python partial()
- Python game development, pyGame module, python implementation of angry birds
- leetcode 1104. Path In Zigzag Labelled Binary Tree（python）
- Save time and effort. 10 lines of Python code automatically clean up duplicate files in the computer
- Learn python, know more meat, and be a "meat expert" in the technical circle. One article is enough
- [Python data structure series] "stack (sequential stack and chain stack)" -- Explanation of knowledge points + code implementation
- Datetime module of Python time series
- Python encrypts and decrypts des to solve the problem of inconsistency with Java results
- Chapter 1: introduction to Python programming-4 Hello World
- Summary of Python technical points
- 11.5K Star！ An open source Python static type checking Library
- Chapter 2: Fundamentals of python-1 grammar
- [Python daily homework] day4: write a function to count the number of occurrences of each number in the incoming list and return the corresponding dictionary.
- Python uses turtle to express white
- Some people say Python does not support function overloading?
- "Python instance" was shocked and realized the dirty words and advertisement detection of the chat system with Python
- Introduction to Python - CONDA common commands
- Python actual combat | just "4 steps" to get started with web crawler (with benefits)
- Don't know what to eat every day? Python to tell you! Generate recipes and don't worry about what to eat every day!
- Are people who like drinking tea successful? I use Python to make a tea guide! Do you like it?
- I took 100g pictures offline overnight with Python just to prevent the website from disappearing
- Binary operation of Python OpenCV image re learning and image smoothing (convolution processing)
- Analysis of Python event mechanism
- Iterator of Python basic language
- Base64 encryption and decryption in Python
- Chapter 2: Fundamentals of python-2 variable
- Python garbage collection summary
- Python game development, pyGame module, python takes you to realize a magic tower game from scratch (1)
- Python draws a spinning windmill with turtle
- Deep understanding of Python features
- A website full of temptations for Python crawler writers, "lovely picture network", look at the name of this website
- Python opencv Canny edge detection knowledge supplement
- Complex learning of Python opencv Sobel operator, ScHARR operator and Laplacian operator
- Python: faker extension package