Build Python development environment from scratch
- 2020-06-03 09:09:42
- OfStack
Environment: Ubuntu 16.04
The following commands operate on the server side if they do not have bold notes indicating that they operate on the local computer
Modify the Ubuntu software source
After the installation of Ubuntu, the server address of the software source is located outside China, so the speed will be slow. Therefore, it is suggested to modify the software source to be a domestic mirror, so that the installation and update of the software will be faster. Here, the open source software image of Tsinghua University is used
1.1 Backup the original software source list
sudo cp /etc/apt/sources.list /etc/apt/sources.list_backup
1.2 Modify the software source as a domestic mirror
With editor opens/etc apt/source list
sudo vi /etc/apt/sources.list
Empty the file and copy the following
# Source code mirroring is annotated by default to improve apt update Speed. Uncomment if necessary
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-updates main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-updates main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-backports main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-backports main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-security main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-security main restricted universe multiverse
# Pre-release software source, not recommended
# deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-proposed main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-proposed main restricted universe multiverse
2 Update software
Update software list
sudo apt-get update
Update local software
sudo apt-get upgrade
Create a new user
When logging in, the default is root user. Since root user has high permissions, which means it is more destructive, so a new user needs to be created as a daily user. When higher permissions are needed, sudo command is used to obtain the user.
Here we assume that the user name we want to create is 'xiaoming'
Create a user and create a user folder
useradd -m xiaoming
Set a password for the user
passwd xiaoming
Switch to the new user and enter the user folder
su - xiaoming
Give super administrator privileges to new users
sudo usermod -a -G adm xiaoming
sudo usermod -a -G sudo xiaoming
Install and log in remotely using ssh
(ssh installation and configuration in me another 1 article https: / / www ofstack. com article / 115994 htm already in detail, for the convenience of reading, after rearranging paste as follows)
Install the ssh service
sudo apt-get install openssh-server
Open ssh
sudo vi /etc/apt/sources.list
0
View the local IP address
The inet field is followed by your IP address
sudo ifconfig
Remote login
Enter ssh in the local computer terminal
<
username
>
@
<
server IP
>
Here we assume that the user name and IP address on the server are xiaoming and 192.168.1.1. Please automatically replace them with your own, which will not be described later
ssh xiaoming@192.168.1.1
5 Optimized configuration of ssh landing
(ssh installation and configuration in me another 1 article https: / / www ofstack. com article / 115994 htm already in detail, for the convenience of reading, after rearranging paste as follows)
5.1 Set the shortcut key for remote login
It's cumbersome to enter a username and password every time you log into the server, and the IP address is hard to remember, so you can change the.bashrc file to set the fast key for remote login
Open the.bashrc configuration file using the editor on your local computer
sudo vi /etc/apt/sources.list
3
Add the following at the end
sudo vi /etc/apt/sources.list
4
Close the file and reload the configuration file by entering the following command line
sudo vi /etc/apt/sources.list
5
Later, you can log in the server remotely by typing server in the terminal
5.2 Add public key authentication
Having to enter the server's password every time you log in is cumbersome and not very secure, so you can add public key authentication to avoid the hassle and security of entering the password
5.2.1 Generate key pairs
Enter the following command on your local computer
sudo vi /etc/apt/sources.list
6
The following will be prompted
Generating public/private rsa key pair.
Enter file in which to save the key (/home/python/.ssh/id_rsa):
Direct enter confirmed on the line
Next, the system will prompt you to set the password to ensure the security of the key. Just leave the password blank by enter, so that you can avoid the trouble of entering the password when using private key authentication
Switch to the key pair directory
cd ~/.ssh/
At this point, you can see the generated private keys id_rsa and the public key ES169en_rsa.pub, in the ~/.ssh directory, and remember not to expose your private key id_rsa under any circumstances
5.2.2 Copy public key to remote server
Enter the following command on your local computer
sudo vi /etc/apt/sources.list
9
5.3 Done!
To complete this configuration, you can enter the following command from your local computer to remotely log on to ssh
server
6 Install multiple versions of Python
Install python2
sudo apt-get install python
View version python2
python --version
Install python3
sudo apt-get install python3
View version python3
python3 --version
7 Install multiple versions of pip
Install pip2
sudo apt-get install python-pip
Install pip3
sudo apt-get install python3-pip
8 installation ipython
Install ipython2
pip2 install ipython
Install ipython3
pip3 install ipython