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 Environment in Python

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

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

In this issue, the editor will bring you about how to build the environment in Python. The article is rich in content and analyzes and narrates it from a professional point of view. I hope you can get something after reading this article.

Python version:

The Python versions used in this course are all 3.x. To have a certain Python foundation, know the use of lists, strings, functions, etc.

Anaconda:

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.). The download address is as follows: https://www.anaconda.com/distribution/ (if the official website is too slow, you can download it from the open source software site of Tsinghua University: https://mirrors.tuna.tsinghua.edu.cn/anaconda/archive/). 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.

Anaconda 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.

Anaconda Navigator:

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

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.

Use the pose of jupyter notebook:

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

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

The 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:

Pythonactivate xxxconda install numpy

Here are some more commands commonly used in package management:

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

Conda install [package name]-n [environment name]

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 above is how to build the environment in the Python shared by the editor. If you happen to have similar doubts, please refer to the above analysis to understand. If you want to know more about it, you are welcome to follow the industry information channel.

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