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

How to build the environment for Python

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

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

This article mainly explains "how to build the environment in Python". The content in the article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn how to build the environment in Python.

1. Anaconda

Anaconda is a software bundled with Python, conda, and other related dependent packages. Contains more than 180 learnable computing packages and their dependencies. Anaconda3 is an environment that integrates Python3, and Anaconda2 is an environment that integrates Python2. The packages that Anaconda integrates by default are those that belong to the built-in Python. And support most operating systems (such as Windows, Mac, Linux, etc.). According to your own operating system, download the corresponding version, because Anaconda has a lot of built-in packages, so the installation process takes a long time, you need to wait patiently when installing. After the installation is complete, there will be the following modules: Anaconda prompt, Anaconda Navigator, Spyder, jupyter notebook, which are introduced below.

II. Naconda prompt

Anaconda prompt is a terminal specially used to operate anaconda. If you do not add the relevant environment variables to the PATH of the environment variables after you install Anaconda, then if you want to use anaconda-related commands on the terminal in the future, you must do so in Anaconda prompt.

III. Anaconda Navigator

This is the equivalent of a navigation panel that organizes Anaconda-related software.

IV. Spyder

A dedicated development of Python software, students who are familiar with MATLAB will feel more intimate, but in the later learning process, we will not use this tool to write code, because there are better alternative tools.

5. Jupyter notebook

An Python editing environment that can view the running effect of the code in real time.

Use the pose of jupyter notebook:

1. Open Anaconda Prompt first, and then go to the directory where the project is located.

two。 Enter the command jupyter notebook to open the jupyter notebook browser.

VI. Basic use of conda

Conda is installed automatically with Anaconda installation. Conda can manage different environments like virtualenv, or you can manage packages in an environment like pip. Let's take a look at the usage of the two functions.

Environmental Management:

Conda can manage different Python environments like virtualenv. Different environments are isolated from each other and do not affect each other. Why do you need to create different environments? The reason is that sometimes there are many projects, but the packages that the projects rely on are different. For example, Project An is developed by Python2 and Project B is developed by Python3, so we need two different environments to support them on the same computer. The basic commands for creating an environment are as follows:

Shell# conda create-- name [environment name] for example: conda create-- name da-env

This creates an environment called da-env, whose python interpreter is based on anaconda. If anaconda is 3.7, then 3.7 will be used by default, and 2.7 will be used by default if anaconda has built-in 2.7. Then you can use conda install numpy to install the package, and the package installed in this way will only be installed in the current environment. Some students may want to ask, if you want to install a Python2.7 environment, there is no built-in Python2.7 in anaconda, then how to achieve it? In fact, we only need to specify the version of python at the time of installation, and if this version does not exist now, anaconda will automatically download it for us. Therefore, the environment in which Python2.7 is installed can be achieved using the following code:

Conda create-name xxx python=2.7

Here is a list of other commands for the conda management environment:

Specify the packages to be installed when you create them:

Conda create-name xxx numpy pandas

You need to specify both the package and the python environment when creating:

Conda create-name xxx python=3.6 numpy pandas

Enter into an environment

Windows: activate xxx mac/linux: source activate xxx

Exit the environment:

Deactivate

List all current environments:

Conda env list

Remove an environment:

Conda remove-name xxx-all

Package export and import in the environment:

Export: conda env export > environment.yml.

Import: conda env create-- name xxx-f environment.yml.

Package Management:

Conda can also be used to manage packages. For example, if we want to install packages (such as numpy) in a new environment after we have created it, we can do this through the following code:

Conda remove-name xxx-all

Here are some more commands commonly used in package management:

Install the package directly to the environment without entering the environment:

Conda remove-name xxx-all

List all packages in this environment:

Conda list

Uninstall a package:

Conda remove [package name]

Set the source of the installation package:

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 Thank you for reading. This is the content of "how to build an Environment in Python". After studying this article, I believe you have a deeper understanding of the problem of how to build an environment in Python. The specific use situation still needs to be verified by practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

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

Development

Wechat

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

12
Report