Install Python, virtual environment, external libraries
A Python installation
1 Windows
To the official website to download the corresponding version Download
I chose Python3.6.8
- After the download is complete, double-click to run
!!! Check Add Python 3.6 to PATH
- Click "Install Now"
- Into the command line <win + r is then input cmd Enter>
- Enter the Windows version of the input python Enter. Linux / macOS version of the input python3 Enter
- Successfully entered the information should be printed version of python. Then will be __ ">>" __ represents the beginning of a command execution.
- 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
Create a Virtual directory where you'd expect the place (folder)
This directory into the command line <cd + path, e.g. cd d: \ Virtual>
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>
Without any prompting, to prove that you have successfully created a
Start the virtual environment
- Windows: .\VirtualName.env\Scripts\bin\activate.bat 回车
- Linux / macOS: source Virtual / base.env / bin / activate the Enter
At this point you should be based on the command-line virtual environment were open header looks like this
Three install third-party packages
- 启动虚拟环境后 在命令行中输入 pip install django (以安装django为例)
- pip install django==1.11 # 这样安装表示安装指定版本的django 不指定版本 默认的安装最新的版本
- pip install django==1.11 -i http://mirrors.aliyun.com/pypi/simple/
- # -i 参数之后 表示从哪个镜像站点下载包 下面是国内的一些镜像源 速度很快
- # 使用其他的源 只是加快下载安装速度,下载下来的东西都是一样的。这一点不用担心。
注意 确保你启动了虚拟环境,再进行安装,否则会污染本地的python环境,对其他的工作造成不必要的麻烦