Table of Contents
1. Why choose Anaconda?
1.1 What is Anaconda?
1.2 What is conda?
1.3 Advantages of Anaconda?
2. How to install Anaconda?
Python package? " >3. How to manage Python package?
4. How Manage Python environment?
Home Backend Development Python Tutorial Python environment configuration analysis

Python environment configuration analysis

Apr 09, 2018 pm 05:28 PM
python environment parse

This time I will bring you Python environment configuration analysis. What are the precautions for Python environment configuration analysis? The following is a practical case, let’s take a look.

If you plan to learn Python for data analysis, are you encountering various troubles at the beginning?

Should I install Python2 or Python3?
Why do I always get errors when installing Python?
How to install the toolkit?

Why is it prompted that a bunch of other unknown tools must be installed before installing this tool?
I believe that most Python beginners have had headaches due to environmental issues, but you are not alone, everyone has suffered like this. In order to avoid detours when getting started, and to prevent the high enthusiasm from being too dampened, it is recommended to use Anaconda to manage your installation environment and various tool packages.

This article introduces the use of Anaconda. The full text outline is as follows:

Why choose Anaconda
* What is Anaconda
* What is conda
* Advantages of Anaconda

How to install Anaconda
How to manage Python packages
How to manage the Python environment

1. Why choose Anaconda?

1.1 What is Anaconda?

Anaconda is a Python distribution focused on data analysis, including more than 190 scientific packages such as conda and Python and their dependencies. As a curious baby, have you discovered a new term conda? Then you will definitely ask what is conda?

1.2 What is conda?

conda is a management system for open source packages and virtual environments.

  • packages management: You can use conda to install, update, and uninstall tool packages, and it focuses more on data science-related tool packages. When installing anaconda, packages commonly used in data analysis such as Numpy, Scipy, pandas, and Scikit-learn are pre-integrated. It is also worth mentioning that conda not only manages Python tool packages, it can also install non-python packages. For example, the R language integrated development environment Rstudio can be installed in the new version of Anaconda.

  • Virtual environment management: Multiple virtual environments can be established in conda to isolate different versions of tool packages required by different projects to prevent version conflicts. For students who are confused about the Python version, we can also create two environments, Python2 and Python3, to run different versions of Python code respectively.

While knowing what it is, we also need to ask why. So, why should you choose Anaconda?

1.3 Advantages of Anaconda?

The advantages of Anaconda can be summed up in eight words: saving time and worry, and being a powerful analysis tool.

  • Save time and worry: Anaconda greatly simplifies your workflow by managing tool packages, development environments, and Python versions. Not only can the tool package be easily installed, updated, and uninstalled, but also the corresponding dependency packages can be automatically installed during installation. At the same time, different virtual environments can be used to isolate projects with different requirements.

  • Analysis tool: Anaconda promotes itself on its official website as follows: a Python tool suitable for enterprise-level big data analysis. It contains more than 720 open source packages related to data science, covering many aspects such as data visualization, machine learning, and deep learning. Not only can it be used for data analysis, it can even be used in the fields of big data and artificial intelligence.

After solving the "what" and "why" questions, let's take a look at the "How".

2. How to install Anaconda?

You can download the Anaconda installer and view the installation instructions from here. Whether it is Windows, Linux or MAC OSX system, you can find the corresponding installation software. If your computer is 64-bit, try to choose the 64-bit version. As for whether the Python version is 2.7 or 3.x, it is recommended that you use Python3 because Python2 will eventually stop maintenance. Maybe most of the tutorials on the market currently use Python2, but don’t worry, because Anaconda can manage two Python versions of the environment at the same time.

Install according to the prompts. After completion, you may be surprised to find that there are many more applications on your computer. Don’t worry, we will look at them one by one:

  • Anaconda Navigtor: A graphical user interface for managing toolkits and environments. Many subsequent management commands can also be implemented manually in Navigator.

  • Jupyter notebook: A web-based interactive computing environment that can edit documents that are easy for people to read and used to display the process of data analysis.

  • qtconsole: A terminal-like 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 execution, and have many built-in Useful features and functions.

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

After the installation is completed, we also need to upgrade all tool packages to avoid possible errors. Open the terminal of your computer and enter in the command line:

conda upgrade --all

When the terminal asks whether to install the following upgrade version, enter y.
In some cases, you may encounter an error message that the conda command cannot be found. This is likely to be a problem with the environment path setting. You need to add the conda environment variable: export PATH=xxx/anaconda/bin:$PATH, Replace xxx with the installation path of anaconda.
Now that the installation is complete, let’s take a look at how to use Anaconda to manage tool packages and environments.

3. How to manage Python package?

Install a package:

conda install package_name

Here package_name is the name of the package that needs to be installed. You can also install multiple packages at the same time, such as installing numpy, scipy and pandas at the same time, then execute the following command:

conda install numpy scipy pandas

You can also specify the version to be installed, such as installing 1.1 version of numpy:

conda install numpy=1.10

Remove a package:

conda remove package_name

Upgrade package version:

conda update package_name

View all packages:

conda list

If you can’t remember the specific name of the package, you can also perform a fuzzy query:

conda search search_term

4. How Manage Python environment?

The default environment is root, you can also create a new environment:

conda create -n env_name list of packages

where -n represents name, env_name is the name of the environment that needs to be created, and list of packages lists the tool packages that need to be installed in the new environment.

For example, when I installed the Python3 version of Anaconda, the default root environment is naturally Python3, but I also need to create a Python 2 environment to run the old version of Python code. It is best to install pandas package, so we run the following command to create it:

conda create -n py2 python=2.7 pandas

If you are careful, you will definitely find that not only is the py2 environment installed pandas and a series of packages such as numpy are also installed. This is the convenience of using conda. It will automatically install the corresponding dependency packages for you without requiring you to install them manually one by one.

Enter the environment named env_name:

source activate env_name

Exit Current environment:

source deactivate

Also note that in Windows systems, use activate env_name and deactivate to enter and exit an environment.

Delete the environment named env_name:

conda env remove -n env_name

Display all environments:

conda env list

When sharing code, you also need to share the running environment with everyone. Execute the following command to save the package information in the current environment into a YAML file named environment.

conda env export > environment.yaml

Similarly, when executing other people's code, you also need to configure the corresponding environment. At this time, you can use the YAML file shared by the other party to create an identical running environment.

conda env create -f environment.yaml

At this point, you have entered the door of Anaconda, and you can wander in the ocean of Python.

Happy studying!

Note: The code examples in this article are referenced from the Anaconda chapter of the Udacity data analysis course.

I believe you have mastered the method after reading the case in this article. For more exciting information, please pay attention to other related articles on the php Chinese website!

Recommended reading:

Operation excel to read and write data

##How to perform automated unit testing with Python Unittest

The above is the detailed content of Python environment configuration analysis. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

PHP and Python: Different Paradigms Explained PHP and Python: Different Paradigms Explained Apr 18, 2025 am 12:26 AM

PHP is mainly procedural programming, but also supports object-oriented programming (OOP); Python supports a variety of paradigms, including OOP, functional and procedural programming. PHP is suitable for web development, and Python is suitable for a variety of applications such as data analysis and machine learning.

Choosing Between PHP and Python: A Guide Choosing Between PHP and Python: A Guide Apr 18, 2025 am 12:24 AM

PHP is suitable for web development and rapid prototyping, and Python is suitable for data science and machine learning. 1.PHP is used for dynamic web development, with simple syntax and suitable for rapid development. 2. Python has concise syntax, is suitable for multiple fields, and has a strong library ecosystem.

PHP and Python: A Deep Dive into Their History PHP and Python: A Deep Dive into Their History Apr 18, 2025 am 12:25 AM

PHP originated in 1994 and was developed by RasmusLerdorf. It was originally used to track website visitors and gradually evolved into a server-side scripting language and was widely used in web development. Python was developed by Guidovan Rossum in the late 1980s and was first released in 1991. It emphasizes code readability and simplicity, and is suitable for scientific computing, data analysis and other fields.

Python vs. JavaScript: The Learning Curve and Ease of Use Python vs. JavaScript: The Learning Curve and Ease of Use Apr 16, 2025 am 12:12 AM

Python is more suitable for beginners, with a smooth learning curve and concise syntax; JavaScript is suitable for front-end development, with a steep learning curve and flexible syntax. 1. Python syntax is intuitive and suitable for data science and back-end development. 2. JavaScript is flexible and widely used in front-end and server-side programming.

How to run sublime code python How to run sublime code python Apr 16, 2025 am 08:48 AM

To run Python code in Sublime Text, you need to install the Python plug-in first, then create a .py file and write the code, and finally press Ctrl B to run the code, and the output will be displayed in the console.

Can vs code run in Windows 8 Can vs code run in Windows 8 Apr 15, 2025 pm 07:24 PM

VS Code can run on Windows 8, but the experience may not be great. First make sure the system has been updated to the latest patch, then download the VS Code installation package that matches the system architecture and install it as prompted. After installation, be aware that some extensions may be incompatible with Windows 8 and need to look for alternative extensions or use newer Windows systems in a virtual machine. Install the necessary extensions to check whether they work properly. Although VS Code is feasible on Windows 8, it is recommended to upgrade to a newer Windows system for a better development experience and security.

Where to write code in vscode Where to write code in vscode Apr 15, 2025 pm 09:54 PM

Writing code in Visual Studio Code (VSCode) is simple and easy to use. Just install VSCode, create a project, select a language, create a file, write code, save and run it. The advantages of VSCode include cross-platform, free and open source, powerful features, rich extensions, and lightweight and fast.

Can visual studio code be used in python Can visual studio code be used in python Apr 15, 2025 pm 08:18 PM

VS Code can be used to write Python and provides many features that make it an ideal tool for developing Python applications. It allows users to: install Python extensions to get functions such as code completion, syntax highlighting, and debugging. Use the debugger to track code step by step, find and fix errors. Integrate Git for version control. Use code formatting tools to maintain code consistency. Use the Linting tool to spot potential problems ahead of time.

See all articles