Ubuntu deploys the development and running environment for python3.5

  • 2020-05-15 03:28:38
  • OfStack

1 overview

Since all the recent projects have changed from python2.x to python3.x (using the latest python3.5.1), the default version of python of the previous cloud host is facing upgrade, so please record the corresponding steps after the upgrade as a learning note.

Server operating environment:

ubuntu 14 LTS Server

This installation method has the following characteristics:

Does not affect the existing python environment Incremental installation Completely isolated sandbox environment You don't even need root permissions

2 download

Download the python 3.5 environment on the python website under the specified platform


wget https://www.python.org/ftp/python/3.5.1/Python-3.5.1.tgz

For example, the downloaded file is Python-3.5.1.tgz

3 decompression

Then decompress:


tar -xvzf Python-3.5.1.tgz

Generate the directory Python-3.5.1

4 the installation

Enter the directory Python-3.5.1 and configure:


./configure --prefix=/usr/local/python35

Compile and install:


make
make install

5. Create a virtual environment

When using the python development environment, 1 is usually built in the virtual environment, which can form the isolation of the project operation environment and prevent the interference of different dependent projects.

Since python3.5 comes with the pyvenv tool, there is no need to reinstall virtualenv's 3-cube library:


webapp@iZ25torzzzzZ:/usr/local/python35/bin$ ll|grep pyvenv
lrwxrwxrwx 1 webapp webapp    10 Jun 3 19:44 pyvenv -> pyvenv-3.5*
-rwxrwxr-x 1 webapp webapp   245 Jun 3 19:44 pyvenv-3.5*

After entering the current user Home directory, directly run:


/usr/local/python35/bin/pyvenv py3venv

You can generate a copy of the virtual environment with python 3.5.1, and then run:


source ./py3venv/bin/activate

The current terminal environment can be changed into an python3.5.1 environment. The terminal dropout with py3venv indicates success:


(py3venv) webapp@iZ25torzzzzZ:~/py3venv/bin$

Then enter the command python, and you will see the following interface:


(py3venv) webapp@iZ25torzzzzZ:~$ python
Python 3.5.1 (default, Jun 3 2016, 19:37:46)
[GCC 4.8.4] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>

6 installed pip

After setting up the virtual environment, the next step is to install the third party library management tool pip for the virtual environment

Execute under py3venv virtual environment:


curl https://bootstrap.pypa.io/get-pip.py|python

You can then use pip in this environment to manage the third party library of python.

7 frequently asked questions -HTTPS error prompt

When it is sometimes necessary to upgrade pip, execute:


tar -xvzf Python-3.5.1.tgz
0

HTTPS error:


tar -xvzf Python-3.5.1.tgz
1

You need to install es1064en-dev:


tar -xvzf Python-3.5.1.tgz
2

Then recompile and install python3.5:


make
make install

Related articles: