current position:Home>[centos7] how to install and use Python under Linux
[centos7] how to install and use Python under Linux
2022-02-01 01:43:18 【Vegetable cake without vegetable】
Access permissions
- In the graphical interface (ctrl+ alt+F2 Switch ), The application in the upper left corner , Select terminal , Input :
su
Then enter the password according to the prompt , You can enter and get root jurisdiction
Copy code
Based on the environment
- First install several necessary packages , In order to facilitate the subsequent operation
* yum install wget gcc make
* # wget For downloading the source package
* # gcc and make Used to compile
Copy code
download python package
Open the web page ,www.python.org, stay download Find the version to download in the page ( Here is python3.6.5), Save to home In the folder , Then decompress .( extract )
- compile
* cd Python-3.6.5
* ./configure --prefix=/usr/local/python3.6 --enable-optimizations
*
Copy code
First explain the above parameters ,--prefix
Is the expected installation directory ,--enable-optimizations
It's optimization options (LTO,PGO etc. ) Add this flag After compiling , Performance has 10% Optimization of left and right ( If I remember correctly ), But this will significantly increase the compilation time . But about LTO and PGO In fact, it is not within the scope of today's article , It is suggested that those who are interested can have a look GCC in LTO The concrete realization of . I should be less likely to write relevant articles Ha ha ha After all, you can't stop writing .
Next
* make
* make install
Copy code
You'll see an error , Tips zlib not available
therefore , We need to pretend to rely on
* yum install zlib-devel
Copy code
Then why do you need this dependency package , Because Python There is a very important built-in module zipimport
For from Zip Import module in compressed package . And if not zlib My bag , Then you can't decompress , Naturally, the module cannot be used .
When our dependencies are installed , Re execute the above steps of compiling and installing , Found execution successful .
* /usr/local/python3.6/bin/python3 --version
Python 3.6.5
Copy code
- Check
Compiling and installing is not enough , Let's do some tests .
When we run Python terminal , Input import bz2
When , You will find that there is no such module . If you are not familiar with this module , It doesn't matter . We type in import sqlite3
be familiar with Python My classmates should be right sqlite3 Not too strange , But if you're still unfamiliar , Then press the direction key to try . Did you find , The output becomes ^[[D^[[A
Something like this ?
be familiar with Python Source code students , You must know what I'm going to say . But if you're not familiar with , No problem , I'll tell you . Normally speaking , Under the terminal, we expect that when the up arrow key is input , The previous command will be displayed , Enter the left direction key , You can move the cursor to the left . But the reality is different from our expectations , What's the cause of the ?
Here's a little bit about the historical reasons for the input device , Simply put, a module is needed to escape the user's input . Back to the point of this article , That is, when we compile and install, we lack readline
This module . Now that the problem has been found , The solution is actually very simple
* yum install readline-devel
Copy code
After installation , Repeat the above steps , compile && Can be installed .
Use python Write code
Pip
Install well python after , The next thing you have to install is pip 了 .
curl https://bootstrap.pypa.io/get-pip.py | python
Copy code
Set up pip Install source , Increase download speed
Create folder
mkdir home/pip
Copy code
utilize cd Order to enter pip In the folder , establish pip.conf file
vi pip.conf
Copy code
Enter the following command , And then click Esc, Input :wq Save and exit .
[global]
index-url = https://pypi.tuna.tsinghua.edu.cn/simple
Copy code
install setuptool
pip install ez_setup
Copy code
Try installing scrapy, Report errors :error: command 'gcc' failed with exit status 1
terms of settlement :
yum install gcc libffi-devel python-devel openssl-devel
Copy code
To write python Code :
vi xxx.py
Copy code
(Esc,:wq Save and exit )
function :
python xxx.py
Copy code
Reference link :segmentfault.com/a/119000000…
copyright notice
author[Vegetable cake without vegetable],Please bring the original link to reprint, thank you.
https://en.pythonmana.com/2022/02/202202010143158362.html
The sidebar is recommended
- Python avatar animation, come and generate your own animation avatar
- leetcode 1884. Egg Drop With 2 Eggs and N Floors(python)
- leetcode 1910. Remove All Occurrences of a Substring(python)
- Python and binary
- First acquaintance with Python class
- [Python data collection] scrapy book acquisition and coding analysis
- Python crawler from introduction to mastery (IV) extracting information from web pages
- Python crawler from entry to mastery (III) implementation of simple crawler
- The apscheduler module in Python implements scheduled tasks
- 1379. Find the same node in the cloned binary tree (Java / C + + / Python)
guess what you like
-
Python connects redis, singleton and thread pool, and resolves problems encountered
-
Python from 0 to 1 (day 11) - Python data application 1
-
Python bisect module
-
Python + OpenGL realizes real-time interactive writing on blocks with B-spline curves
-
Use the properties of Python VTK implicit functions to select and cut data
-
Learn these 10000 passages and become a humorous person in the IT workplace. Python crawler lessons 8-9
-
leetcode 986. Interval List Intersections(python)
-
leetcode 1860. Incremental Memory Leak(python)
-
How to teach yourself Python? How long will it take?
-
Python Matplotlib drawing pie chart
Random recommended
- Django paging (II)
- Concurrent. For Python concurrent programming Futures or multiprocessing?
- Programmers over the age of 25 can't know a few Chinese herbal medicines. Python crawler lessons 9-9
- Python crawler from introduction to pit full series of tutorials (detailed tutorial + various practical combat)
- The second bullet of class in Python
- Python object oriented programming 03: class inheritance and its derived terms
- How IOS developers learn Python Programming 13 - function 4
- Python crawler from introduction to mastery (VI) form and crawler login
- Python crawler from entry to mastery (V) challenges of dynamic web pages
- Deeply understand pandas to read excel, TXT, CSV files and other commands
- Daily python, Chapter 18, class
- "I just want to collect some plain photos in Python for machine learning," he said. "I believe you a ghost!"
- Django view
- Python implements filtering emoticons in text
- When winter comes, python chooses a coat with temperament for mom! Otherwise, there's really no way to start!
- Python crawler - get fund change information
- Highlight actor using Python VTK
- Python crawler actual combat: crawling southern weekend news articles
- leetcode 406. Queue Reconstruction by Height(python)
- leetcode 1043. Partition Array for Maximum Sum (python)
- Python * * packaging and unpacking details
- Python realizes weather query function
- Python from 0 to 1 (day 12) - Python data application 2 (STR function)
- Python from 0 to 1 (day 13) - Python data application 3
- Numpy common operations of Python data analysis series Chapter 8
- How to implement mockserver [Python version]
- Van * Python! Write an article and publish the script on multiple platforms
- Python data analysis - file reading
- Python data De duplication and missing value processing
- Python office automation - play with browser
- Python series tutorial 127 -- Reference vs copy
- Control flow in Python: break and continue
- Teach you how to extract tables in PDF with Python
- leetcode 889. Construct Binary Tree from Preorder and Postorder Traversal(python)
- leetcode 1338. Reduce Array Size to The Half(python)
- Object oriented and exception handling in Python
- How to configure load balancing for Django service
- How to embed Python in go
- Python Matplotlib drawing graphics
- Python object-oriented programming 05: concluding summary of classes and objects