程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

How to install Python environment of other versions on Linux ECS with actual combat applet

編輯:Python

Hello everyone , I'm an old watch ~

A previous article use Python Set up a fund inquiry robot , It can also expand !, need Python The environment is 3.7 And above , For the first time in Linux Installation on Python( The previous ones were all built-in Python3.6.8), Record .

1、 Download from the official website Python Source code

It is recommended to download locally ( Download faster ), Then through the pagoda , Upload the file to the server .

First of all, the following URL of the local browser service , Find what you want to download python edition , Click to download .

https://www.python.org/downloads/source/

Be careful , On the left is the stable version , On the right is the pre release version , What I choose here is Python3.7.9, Click on Download XZ compressed source tarball.

We will download the good Python The source compressed package is uploaded to the specified folder of the server through the pagoda ( I am here root/Project One is created under the folder soft Folder ), After uploading , Right click inside the pagoda to decompress .

If you don't know how to install and use the pagoda panel , You can read the articles in the past :Linux Inside “ pagoda ”, The real pagoda ! Detailed tutorial

2、 install Python

Next we can still use the pagoda , Click... On the pagoda panel terminal , Enter the following commands in sequence .

  • cd Get into Python Source directory
  • ./configure --prefix Set the installation position
  • make Compile the source code , Generate executable files
  • make install Install the executable generated by compilation to the through configure Set the installation directory

The final installation directory I set here is /usr/local/python3.7

cd /root/soft/Python-3.7.9
./configure --prefix=/usr/local/python3.7
make
make install

After successful installation , The installation directory will also be printed out , This prompt indicates that this directory has not been added to the environment variable , We can add , Or directly configure the soft link .

  • Mode one : Configure environment variables

The first use of nano Open profile ~/.bashrc, Add a line at the end export PATH="/usr/local/python3.7/bin:$PATH", preservation sign out , Finally, run the configuration file .

nano ~/.bashrc
# After adding environment variables , Run the configuration file
source ~/.bashrc

But even so , Still have to set up a soft link , Or use python3.7 Get into Python Program .

  • Mode two : Set up soft links

What we use here is ln Instructions , take python3.7 Executable software links directly to /usr/bin Medium python3,pip3.7 link to /usr/bin Medium pip3, So we can use it directly python3 pip3 It corresponds directly to 3.7 Version of the .

  • ln -s Indicates soft linking
  • ln -f Indicates that the link is forced , If you have previously linked to other directories , Delete the previous link first , Then make a new link
ln -sf /usr/local/python3.7/bin/python3.7 /usr/bin/python3
ln -sf /usr/local/python3.7/bin/pip3.7 /usr/bin/pip3

Set it up , We can type in python3 --version See if the link is successful .

3、 Easy to use

  • Set image source

Create a .pip Folder , For storage pip The configuration file .

mkdir .pip && cd .pip

We still use nano Directive to edit the file ,

nano pip.conf

Copy the following to it , Then press ctrl+o Save the file , Press again ctrl+x Exit the edit mode .

[global]
index-url = https://mirrors.aliyun.com/pypi/simple
[install]
trusted-host = mirrors.aliyun.com

Except alicloud image , You can also choose other image sources ,

 University of science and technology of China https://pypi.mirrors.ustc.edu.cn/simple
douban http://pypi.douban.com/simple
Tsinghua University https://pypi.tuna.tsinghua.edu.cn/simple
University of science and technology of China http://pypi.mirrors.ustc.edu.cn/simple
  • Install third party package

The first thing to install is pipenv, Easy to create 、 Manage virtual environments , Install requests Crawl data , Install another pandas Processing data .

pip3 install pipenv rquests pandas
  • Write a little program : Generate random password

Let's talk about the train of thought : From numbers 、 Case letters 、 Select the number of characters of specified length randomly in special characters , Then form a string .

1> Character set

We can input by ourselves , You can also use ready-made bags , such as string, yes Python A built-in package for , You can quickly get all kinds of characters .

import string
string.printable
2> Random function

It's also Python Built in package random, There are mainly built-in :randint、random、randrange、choice、choices Such as function .

import random
random.choices('abc', k=2)
3> Random password generator
import string
import random
while True:
try:
password_len = int(input(' Please enter the password length ( It's just numbers ):'))
password = ''.join(random.choices(string.printable.strip(), k=password_len))
print(f' Your new password is :{password}, Please keep it ~')
except Exception as e:
print(f'【 Error 】 See if there is an input error , It may be that non digital content has been entered , error message :{e}')
print('*** If you want to finish, enter 0 Well !!!***')
print('*** Press enter to continue generating a new password ***')
flag = input(' Continue to generate new password :')
if flag == '0':
break
print('******************************************')

There's time later , I'll optimize it , Hey, hey, hey ~


  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved