Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

The Construction method of Python Environment

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/02 Report--

This article introduces the relevant knowledge of "how to build a Python environment". Many people will encounter such a dilemma in the operation of actual cases, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

Environment building

As we all know, Python is a scripting language with a rich third-party library.

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

But the third-party library needs to be installed by ourselves.

For example, a normal person is born with eyes, nose, mouth and so on. This is the "official library".

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

Python provides a super large and powerful third-party library.

We build the development environment so that Python has a variety of capabilities to meet our needs.

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

Even sometimes, there are all kinds of conflicts between different versions of the library.

This library is not compatible with that library, and all kinds of "Wulitou" errors emerge one after another.

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

Scheme: Anaconda + Jupyter Notebook.

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

1 、 Anaconda

Anaconda is a tool for managing the third library, while supporting "multi-open".

You can create multiple virtual environments with Anaconda.

What do you mean?

A virtual environment is like a person:

Train Xiao Wang to be a mathematician who specializes in mathematics-related matters.

Train Xiao Li to be a linguist who specializes in language-related matters.

Reflected in the virtual environment, it is like this:

I have created a lot of virtual environments.

Base is a basic environment that comes with installing Anaconda. Others are independent environments created according to their own needs.

For example, an environment called jack is a general development environment. The environment called faceswap is the 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 in Windows, MacOS and Linux.

2 、 Jupyter Notebook

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

Because Jupyter is easy to install and easy to use, it can run on a variety of platforms.

After work, the running algorithm is often run on the server.

Can you still use Pycharm for a server that doesn't even have an image interface?

Jupyter Notebook is an interactive computing notebook environment based on web pages.

Achieve the perfect combination of text and code, you can even learn while taking notes, text editing also supports Markdown format, it is easy to insert a variety of mathematical formulas.

And because Jupyter Notebook is web-based, you can open the service on the server side, open the web page on the local computer and run all kinds of server-side code.

If you are doing algorithms, doing crawlers, just learning the rookie of Python, and do not involve the development of huge Python projects, then do not hesitate to use Jupyter Notebook.

3. Installation

The benefits of Anaconda + Jupyter Notebook are Amway everywhere.

So, how to install it?

Download address of Anaconda:

Https://www.anaconda.com/products/individual#download-section

Choose the installation package according to your environment:

Installation is very simple, stupid next step installation can be.

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

During installation of Linux and MacOS, you will be prompted to set the environment variable.

Windows to add environment variables need to be set 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:\ AnacondaD:\ Anaconda\ Scripts

Once configured, you can use Anaconda in cmd or Anaconda Prompt to build the environment.

Enter instructions:

Conda create-n your_name jupyter notebook

This means to create a virtual environment named your_name, and this virtual environment installs additional jupyter notebook third-party libraries.

You can change your_name to your favorite name, which is the name of your virtual environment. Take whatever you want, such as jack.

Then, enter y to install:

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

As you can see from the figure above, there are two environments, one is base, the basic environment that comes with it, and the other is our newly created environment called jack.

After installing the environment, we can activate the jack environment with instructions:

Activate jack

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

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

Conda install requests

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

Python-m pip install xxx

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

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 or something, just install it in this virtual environment. It really smells good!

This is the end of the content of "how to build a Python Environment". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report