python 2.7 - 3.5 upgrade path (a): preparation phase development environment - pip3, vitualEnv, pycharm

background

Since before the project uses version is Python2.7, taking into account the Python 2.7 the next year (after 2020 will stop updating), and in order to better adapt to the Chinese and embrace new features. We decided to upgrade to the latest from python 2 python 3. 

The actual online environment is Ubuntu16.04LTS, the default install python 2.7 & 3.5 versions. Therefore, after considering the actual situation decided to upgrade to 3.5, later transition to the latest 3.7.

 

Use pip3 matching python 3

pip difference with pip3

  • When the computer at the same time there are several versions of python, pip3 can automatically determine the use python3 to install the library, in order to avoid conflict with python2.
  • If your computer only installed python3, use pip or pip3 is the same.

pip install xxxxxx
newly installed library will be placed behind the list below: python2.7 / site-packages

pip3 install xxxxxx
newly installed library will be placed behind the list below: python3.6 / site-packages

If you use python3 program execution, you can not import python2.7 / site-packages in the library.

 

Since Ubuntu16.04 installed by default python 2.7 & 3.5 in two versions, so we need to use pip3 responsible for the management and use of python3 dependent. Installation pip3 command is as follows:

sudo apt-get install python3-pip

 

 

Use virtualENV

What is virtualenv

virtualenv is a Python tool for creating virtual environments.

What virtual environment is it? It is a private copy of the Python interpreter, you can install proprietary package in this environment, without affecting system installed in the global Python interpreter.
Python when running multiple applications on a single host, use the virtual environment can effectively avoid the confusion and package versions conflict.

Installation virtualENV

sudo pip3 install virtualenv

 

Creating virtualENV for python3 

cd somedir
virtualenv -p python3 venv3

 

 

Use pycharm load virtualENV 

Load virtualENV, as shown in

 

We can file path to the right of "interpreter path" folder icon selection virtualEnv (selection: to python3 file, for example: xxx / venv3 / bin / python3.5), as shown:

 

Mounting dependence on the development of package terminal pycharmd

First of all, first of all depend organized into a requirement.txt as follows,

 

 

Then open terminal pycharm using pip3 installation dependencies

 

Upon completion, pycharm will automatically sense changes to re-update interpreter.

 

This, our development environment preparations are completed. Welcome to leave a message exchange.

 

reference:

https://www.jianshu.com/p/94a047301f4a

https://blog.csdn.net/chengyq116/article/details/83794489

Guess you like

Origin www.cnblogs.com/atuotuo/p/11224610.html