Python environment installation (Anaconda+VS code+Win 10)

This article is suitable for beginners to learn

Many beginners who learn python even learn it for a while and feel that they have no way to start when they come into contact with Anaconda. The main reason is that they don't understand what Anaconda is for, what it is for, and why it is done.
At the beginning, I didn't understand why I need Anaconda in addition to python. What is the connection and difference between it and python, and why it can be used to manage python.
After using it, I gradually discovered what anaconda is actually doing, and why we need them to manage our python environment.

problem

1. Should I install Python2 or Python3?
2. Package management
3. Environment chaos

Anaconda

Anaconda is on the stage, let us install Anaconda first and then solve our above problems one by one.
Download link: link
recommends downloading the python3 version. The
installation is relatively simple. Follow the instructions of the installer and install it step by step.

After the installation is complete, the following applications will be briefly introduced:

Anaconda Navigtor

The graphical user interface used to manage the toolkit and environment, and many management commands involved in the follow-up can also be implemented manually in Navigator.

Jupyter notebook

The web-based interactive computing environment can edit documents that are easy for people to read to show the process of data analysis.

qtconsole

An imitation terminal graphical interface program that can execute IPython. Compared with the Python Shell interface, qtconsole can directly display the graphics generated by the code, realize multi-line code input and execution, and have many useful functions and functions built-in.

spyder

A cross-platform, scientific computing integrated development environment using Python language.

Manage virtual environments

Open Anaconda Prompt in the start directory (preferably open in administrator mode)

Insert picture description here

The opening interface is as follows:

Insert picture description here
Enter conda --version.
If you output conda 4.8.5, it means that Anaconda is installed successfully. As shown in the figure below:
Insert picture description here
Then, in order to avoid possible errors, we enter conda upgrade --all on the command line to upgrade all toolkits.

conda change source

To speed up downloading the installation package, copy the following directly to the above interface.

#添加清华anaconda镜像:
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/
conda config --set show_channel_urls yes

Next, we can use Anaconda to create an independent python environment.

Create a virtual environment named WHL and specify the python version as 3.7

conda create -n WHL python=3.7

Switch to the WHL environment we created

activate WHL

If we forget the name, we can use the following command to view all the environments

conda env list

The current WHL environment has no other packages except some official packages that come with python. We can check:
first enter python to open the python interpreter and then enter

>>> import requests

It will report an error that the requests package cannot be found, which is normal. Next we will demonstrate how to install the requests package

exit()

Exit python interpreter

Install third-party packages

Install package commands

conda install requests

or

pip install requests


Let's install the requests package. After the installation is complete, we enter python into the interpreter and import the requests package, this time it must be successful.
Insert picture description here
Uninstall package command

conda remove requests

or

pip uninstall requests

Anaconda common commands

conda --version或者conda -V     #显示conda版本信息
conda update –all     #更新当前环境下安装的全部package到最新版本
conda update -n base conda        #update最新版本的conda
conda create -n xxxx python=3.7   #创建python3.7的xxxx虚拟环境
conda activate xxxx               #开启xxxx环境
conda deactivate                  #关闭环境
conda env list                    #显示所有的虚拟环境
conda list         #查看已经安装的文件包
conda list  -n xxx       #指定查看xxx虚拟环境下安装的package
conda update xxx   #更新xxx文件包
conda install xxx==版本   #安装xxx文件包
conda uninstall xxx==版本   #卸载xxx文件包

conda install tensorflow==1.3.0  -i https://pypi.tuna.tsinghua.edu.cn/simple (-i后面的表示临时指定的国内pip镜像源)
#添加清华anaconda镜像:
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/
conda config --set show_channel_urls yes

So where is the environment we created? An envs can be seen in the Anaconda installation directory. Here is the entrance to the various virtual environments we created. Click to enter and you can see all the created virtual environments.

In this way, what Anaconda calls creating a virtual environment is actually installing a real python environment, but we can switch our current python environment at will through activate, conda and other commands, using different versions of interpreters and different packages Environment to run python scripts.

VS code

VS code is a free and open source modern lightweight code editor suitable for Python beginners.

The VS code python parser is directly downloaded from the official website, and is installed by default (check PATH when installing python).
Download link: link .
Insert picture description here
This is the windows 64-bit version. Please choose according to your own computer.
The installation is relatively simple. Follow the instructions of the installation program and install it step by step.

Open the installed VS code

Press the shortcut key Ctrl+Shift+X to enter the plug-in management page, search for the python keyword in the search box, and click the one with the highest download to install, usually the first one.
Insert picture description here

Create new folders and files

Create a new file, note that the suffix is ​​.py,
Insert picture description here
you can also directly open a new folder (similar to opening a project)
File—Open Folder…
Insert picture description here

Compile and run

There are three ways to compile and run.
The shortcut keys are: F5 or Fn+F5, to save, compile, and run the code and display it on the terminal. Related buttons are on the left: Run- green triangle symbol
Insert picture description here

Switch compilation environment

Mouse click on Python 3.7.9-bit('whl':conda) to switch to other virtual environments.
Insert picture description here
After clicking, all environment options appear at the top of the software.
Insert picture description here
​ Alright! ! At this point we can happily write code and adjust the program! ! !

I have limited abilities, and the explanation is not clear. If you encounter any problems, you can leave a message or private message. You can refer to multiple blogs at the same time to complete the environment. All subsequent CS231N jobs are edited and run in this environment. This is also the beginning of the road to deep learning, everyone must pay attention to the construction of the environment to avoid stepping on pits in the future

This article hopes to be helpful to everyone. Of course, if there is something wrong with the above, please correct me.

Sharing decision heights, learning to open the gap

Guess you like

Origin blog.csdn.net/qq_42078934/article/details/108973215