Python third party library management in the virtual learning environment ape #


 

 

Management ## third-party libraries

> Python relatively fast hardware in place is provided by a large number of third-party libraries you use.

Management of third-party libraries website https://pypi.org/ ####

#### How to install third-party libraries

####  pip

> Pip is the python package management tools to solve the immediate package dependencies. It can easily manage third-party libraries (package).

>

> Similar to PHP in Composer, or Nodejs in npm, or in Linux yum.

How to use the ### pip

`Pip install the package name (library name)`

Note: If you have multiple python environments circumstances, you may need to use pip3

Such as installing pymysql library

`pip install pymysql`

### install the specified version of the package

`Pip install the package name == 'version

### search already installed package

`` Pip show package name

### view all installed packages

`pip list`

Replacement of the mirror source ### pip

```

PIP replace domestic installation source

Some pip domestic mirror

  Ali cloud http://mirrors.aliyun.com/pypi/simple/

  China University of Science and Technology https://pypi.mirrors.ustc.edu.cn/simple/

  Watercress (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/

Modify the source method:

temporary use:

It can be followed by the -i parameter specifies pip pip in the use of the source

pip install scrapy -i https://pypi.tuna.tsinghua.edu.cn/simple

Permanent modifications:

linux:

Modify ~ / .pip / pip.conf (not create one), reads as follows:

[global]

timeout = 6000

index-url = https://pypi.tuna.tsinghua.edu.cn/simple

trusted-host = pypi.tuna.tsinghua.edu.cn

windows:

Create a directory pip directly in the user directory, such as: C: \ Users \ xx \ pip, pip directory in the new document pip.ini, reads as follows

Or in accordance with the recommendations of friends: win + R to open the user directory% HOMEPATH%, pip create a folder in this directory, create a file in pip.ini pip directory, as follows

[global]

timeout = 6000

index-url = https://pypi.tuna.tsinghua.edu.cn/simple

trusted-host = pypi.tuna.tsinghua.edu.cn

```

## Virtual Environment

> Virtual environment is in the current system environment, in addition to the configuration of a python runtime environment, it can create a number of different virtual environments.

>

> Python virtual environment independent of each other.

+ Virtual environment can be installed in the new library without permission (problems may arise Linux system)

+ Different applications can use different or different repositories.

+ Library upgrade virtual environment does not affect other environmental

+ Virtual environment can be used as proprietary environment of a project. When you need to deploy, a key export items needed package

### How to use python virtual environment

1. You can create a virtual environment directly in the pycharm

#### 2. Install their own independent virtual environment

1. #### to create a virtual environment

`Python -m venv name` virtual environment

2. #### into the virtual environment, activate the virtual environment

  + linux

  ```shell

  # Use the source command to execute activate under v1 / bin / directory

  localhost:code yc$ source v1/bin/activate

  (v1) localhost:code yc$

  ```

  + windows

  ```shell

  # Windows system required to enter v1 / Scripts / directory

  cd v1/Scripts/

  # Run activate.bat file

  activate.bat

  (v1) F:\code>

  ```

3. #### then you can install some packages in a virtual environment

`pip install pymysql`

4. #### to see whether a package is installed

`Pip show pymysql` if installed is able to display information.

5. Exit virtual environment ####

  + linux :  deactivate

  + Windows: direct ctrl + c

6. #### export package in the current environment of all installed

```shell

# View all installed packages

pip list

'''

Package      Version

------------ -------

Click        7.0   

Flask        1.1.1 

itsdangerous 1.1.0 

Jinja2 2.10.3

MarkupSafe  1.1.1 

pip          19.0.3

PyMySQL      0.9.3 

setuptools  40.8.0

tool 0.16.0

'''

# Export all packets to files

pip freeze > ./requirements.txt

```

7. Delete #### environment

After exiting the virtual environment, just delete the folder to a virtual environment

 

Mastery learning method, as will bend to overtake!

Learning to ape: the achievements of their own just a boutique!

Guess you like

Origin www.cnblogs.com/itxdl/p/12522596.html