Set up a Python development environment once and for all

Anaconda + Jupyter Notebook development environment is set up, really fragrant!

Like it and look again, develop a habit,

There are various online tutorials, and the readers complain about how to set up a  development environment  .

For Xiaobai, setting up a development environment is the first hurdle that must be passed   .

I remember that when I just learned Python and I was a novice, one of my favorite things to do was  toss the development environment  .

Many people learn python and don't know where to start.
Many people learn python and after mastering the basic grammar, they don't know where to find cases to get started.
Many people who have done case studies do not know how to learn more advanced knowledge.
For these three types of people, I will provide you with a good learning platform, free to receive video tutorials, e-books, and course source code! ??¤
QQ group: 828010317

Before I wrote a few lines of the code, I was tossed, took too many detours, and wasted too much time.

I have tossed about IDE, Eclipse, Pycharm, Sublime Text, etc.

After a few weeks of tossing, the code didn't write anything, and finally came "Hello World".

As an "algorithm mover" who has been working for two years, today I will tell you how to set up a development environment for "the big cows of the future, the little whites of today".

In the future, if a friend asks you about environment construction problems,  send the article directly to him  and tell him that this tutorial is really good!

Environment setup

We all know that Python is a scripting language with a wealth of  third-party libraries  .

Python comes with many  official libraries  that can be used directly, such as re, os, math, etc.

But third-party libraries need to be installed by ourselves.

It is like a normal person, born with his own eyes, nose, mouth, etc. This is the "official library".

If you want to buy a beautiful dress and make a beautiful hairstyle, you have to "install" it yourself. This is the "third-party library".

Python provides a lot of and powerful third-party libraries.

We set up a development environment to allow Python to have a variety of capabilities to meet our needs.

Many third-party libraries are individuals or teams, and are not officially developed by Python, so it is inevitable that they are diverse and messy.

Even sometimes, various versions of the library still have various conflicts.

This library is not compatible with that library, and various "nonsensical" errors are constantly emerging.

Once and for all, the way to solve or avoid such problems is to build a "robust" development environment.

Solution: Anaconda + Jupyter Notebook.

Good maintenance, good installation, hello and me,  everyone is really good  .

1、Anaconda

Anaconda is a tool for managing the third library, and it also supports "multi-open".

You can create multiple virtual environments with Anaconda   .

What do you mean?

virtual environment is  like a person:

Cultivate Xiao Wang as a mathematician, specializing in math-related matters.

Cultivate Xiao Li as a linguist who is responsible for language-related matters.

Reflected in the virtual environment, it is like this:

I created many virtual environments.

base is a basic environment that comes with the installation of Anaconda. Others are independent environments created according to their own needs.

For example, the environment named jack is a general development environment. The environment named faceswap is an environment I built specifically for the face-changing algorithm, because its dependencies conflict with some general third-party library packages.

Anaconda is also cross-platform and can be installed on Windows, MacOS, and Linux.

2、Jupyter Notebook

Xiaobai recommends Jupyter Notebook, why not recommend IDEs like Pycharm?

Because Jupyter is easy to install and easy to use, it can run on multiple platforms.

After work, algorithms are often run on the server.

Can you still use Pycharm without a server without a graphical interface?

Jupyter Notebook is a  web-  based interactive computing notebook environment.

 The perfect combination of text and code is realized  . You can even  take notes while learning  . The text editor also supports the Markdown format, so you can insert various  mathematical formulas  .

And because Jupyter Notebook is web-based, you can open the service on the server side, open the web page on your local computer, and run various server-side codes.

If you are  a novice who is doing algorithms, crawling, just learning Python, and does not involve the development of vast Python projects, then do  n't hesitate to use Jupyter Notebook.

3. Installation

The benefits of Anaconda + Jupyter Notebook are everywhere.

So, how to install it?

Anaconda download link:

www.anaconda.com/products/in…

Choose the installation package according to your environment:

The installation is very simple, the next step is to install the fool.

After Windows is installed, you need to  manually add  environment variables.

Linux and MacOS will prompt whether to set  environment variables during the installation process  .

To add environment variables in Windows, you need to set it in Computer -> Right Mouse Button -> Properties -> Advanced System Settings -> Environment Variables -> Path.

D:\Anaconda is the installation directory of Anaconda, just add the following two addresses to Path.

D: \ Anaconda 

D: \ Anaconda \ Scripts 
Copy the code

After everything is configured, you can use Anaconda to build the environment in cmd or Anaconda Prompt.

Input command:

conda create -n your_name jupyter notebook 
copy the code

The meaning of this sentence is to create a virtual environment named your_name, and this virtual environment additionally installs a third-party library of jupyter notebook.

You can change your_name to your favorite name, this name is the name of your virtual environment, you can pick it up, such as jack.

Then, enter y to install:

After installation, you can check the existing environment by command conda info -e.

As you can see from the above figure, there are two environments, one is base, the built-in basic environment, and the other is our newly created environment called jack.

After installing the environment, we can use the command to activate the jack environment:

As you can see, our environment has changed from base to jack.

Next, we can install the third-party libraries we want in this environment, such as requests.

For packages that cannot be found by conda, you can also use pip to install:

python -m pip install xxx 
copy the code

After installing the third-party libraries that need to be installed, you can use the command to directly open Jupyter Notebook:

The effect is as follows:

Create a new notebook:

After entering the code, press Ctrl + Enter shortcut key to run the program:

The environment used by this Jupyter Notebook is a virtual environment called jack.

If you want to install Pytorch, you can install it directly in this virtual environment.

to sum up

The use of Anaconda + Jupyter Notebook to build an environment is very suitable for novices.

Jupyter Notebook is also very powerful, it is definitely a good helper for you to learn algorithms and analyze data!

If you like this kind of tutorials, forward, like, and support many people, we will continue to show some tips for using these tools in the future   .

Guess you like

Origin blog.csdn.net/Python_sn/article/details/111266165