Python installation and create a virtual environment and install external libraries

Install Python, virtual environment, external libraries

A Python installation

1 Windows

  1. To the official website to download the corresponding version Download

  2. I chose Python3.6.8

  1. After the download is complete, double-click to run

!!! Check Add Python 3.6 to PATH

  1. Click "Install Now"
  2. Into the command line <win + r is then input cmd Enter>
  3. Enter the Windows version of the input python Enter. Linux / macOS version of the input python3 Enter
  4. Successfully entered the information should be printed version of python. Then will be __ ">>" __ represents the beginning of a command execution.
  5. This interpreter installed.

2 Linux / macOS

Two to create a virtual environment

Since installing python packages directly in the real environment can cause contamination of the environment, it is necessary to create a virtual environment, in principle, every project needs to have a unique virtual environment of their own

  1. Create a Virtual directory where you'd expect the place (folder)

  2. This directory into the command line <cd + path, e.g. cd d: \ Virtual>

  3. In the command line python -m -venv VirtualName.env <VirtualName into your desired name but ensure the extension name .env such as Bi-based virtual environment: gratuation.env even Monkey.env anything will do ok>

  4. Without any prompting, to prove that you have successfully created a

  5. Start the virtual environment

    1. Windows: .\VirtualName.env\Scripts\bin\activate.bat 回车
    2. Linux / macOS: source Virtual / base.env / bin / activate the Enter
  6. At this point you should be based on the command-line virtual environment were open header looks like this

Three install third-party packages

  1. 启动虚拟环境后 在命令行中输入 pip install django (以安装django为例)
    1. pip install django==1.11 # 这样安装表示安装指定版本的django 不指定版本 默认的安装最新的版本
    2. pip install django==1.11 -i http://mirrors.aliyun.com/pypi/simple/
      1. # -i 参数之后 表示从哪个镜像站点下载包 下面是国内的一些镜像源 速度很快
      2. # 使用其他的源 只是加快下载安装速度,下载下来的东西都是一样的。这一点不用担心。
        1. 阿里云 http://mirrors.aliyun.com/pypi/simple/
        2. 中国科技大学 https://pypi.mirrors.ustc.edu.cn/simple/
        3. 豆瓣(douban) http://pypi.douban.com/simple/
        4. 清华大学 https://pypi.tuna.tsinghua.edu.cn/simple/

注意 确保你启动了虚拟环境,再进行安装,否则会污染本地的python环境,对其他的工作造成不必要的麻烦

Guess you like

Origin www.cnblogs.com/monkey-code/p/12157215.html