Environment configuration analysis for Python

Source: Internet
Author: User
Tags virtual environment jupyter notebook
This time to bring you python environment configuration analysis, Python environment configuration analysis of the considerations of what, the following is the actual case, take a look.

Are you going to learn Python to do data analysis, do you get into all sorts of trouble at the beginning?

What's the Python2 or the Python3?
Why is it always wrong to install Python?
How to install the tool kit?

Why do I need to install a bunch of other unknown tools before installing this tool?
I believe most of the beginners in Python have had a headache for the environment, but you are not alone, and everyone is so upset. In order to avoid detours when getting started, and to keep the enthusiasm of the upswing from being too hard, it is recommended to use Anaconda to manage your installation environment and the various toolkits.

This article describes 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

First, why Choose Anaconda?

1.1 What is Anaconda?

Anaconda is a Python release that focuses on data analysis and contains more than 190 science packages, including Conda, Python, and their dependencies. As a curious baby you are not found a term conda, then you will certainly ask Conda what is it?

1.2 What is Conda?

Conda is a management system for open source packages (packages) and virtual environments (environment).

    • Packages Management: You can use Conda to install, update, uninstall toolkits, and it is more focused on data science-related toolkits. Packages such as Numpy, Scipy, Pandas, Scikit-learn, which are commonly used in data analysis, are pre-integrated when Anaconda is installed. Also worth mentioning is that Conda not only manages Python's toolkit, it can also install non-Python packages. For example, in the new version of Anaconda can be installed in the R Language integrated development environment Rstudio.

    • Virtual Environment Management: In Conda, you can establish multiple virtual environments to isolate different versions of the toolkit required by different projects to prevent conflicts on the version. For those of you who are entangled in the Python version, we can also build Python2 and Python3 environments to run different versions of Python code separately.

Knowing what it is, we also need to ask why. So why choose to use Anaconda?

What are the advantages of 1.3 Anaconda?

Anaconda advantages summed up on eight words: Save time worry, analysis of the weapon.

    • Save time and hassle: Anaconda simplifies your workflow by managing the toolkit, development environment, and Python version. It is not only easy to install, update, uninstall the toolkit, but also to install the appropriate dependencies automatically, while you can use different virtual environments to isolate the different requirements of the project.

    • Anaconda: The Python tool for enterprise-class big data analytics, which is how you advertise yourself in the official website. It contains more than 720 open source packages related to data science, and is involved in data visualization, machine learning, deep learning and many more. Not only can do data analysis, can even be used in the field of big data and artificial intelligence.

After solving the question of what and why, let's look at how to do it.

Second, how to install anaconda?

You can download the Anaconda installer from here and view the installation instructions. Whether it's Windows, Linux or MAC's OSX system, you can find the corresponding installation software. If your computer is 64 bits, choose the 64-bit version as much as possible. As for the Python version is 2.7 or 3.x, it is recommended that you use Python3, because Python2 will eventually stop maintenance. While most of the tutorials available today are Python2, there's no need to worry because you can manage two Python versions of the environment in Anaconda.

Follow the prompts to install, you will probably be surprised to find that the computer has a lot of applications, do not worry, we see in one item:

    • Anaconda Navigtor: A graphical user interface for managing toolkits and environments, and many of the subsequent management commands can be implemented manually in Navigator.

    • Jupyter Notebook: A Web-based, interactive computing environment that allows you to edit documents that are easy to read and to demonstrate the process of data analysis.

    • Qtconsole: An executable IPython graphical interface program, compared to the Python Shell interface, Qtconsole can directly display code-generated graphics, implement multi-line code input execution, as well as built in many useful functions and functions.

    • Spyder: An integrated development environment that uses Python language, cross-platform, and scientific operations.

After the installation is complete, we also need to upgrade all the toolkits to avoid possible errors. Open the terminal of your computer and enter it at the command line:

conda upgrade --all

Enter Y when the terminal asks whether to install the following upgrade version.
In some cases, you might encounter an error that could not find the Conda command, which is most likely an issue with the environment path setting, and you need to add the CONDA environment variable: Export path=xxx/anaconda/bin: $PATH, where xxx is replaced with anaconda installation path.
Now that the installation is complete, let's look at how to manage the toolkit and environment with Anaconda.

Third, 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, and execute the following command:

Conda Install NumPy scipy Pandas

You can also specify the version of the installation, such as installing the 1.1 version of NumPy:

conda install numpy=1.10

Removing a package:

conda remove package_name

Upgrade Package Version:

conda update package_name

See All packages:

conda list

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

conda search search_term

Iv. How to manage the python environment?

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

conda create -n env_name list of packages

Where-n stands for Name,env_name is the name of the environment that needs to be created, and list of packages lists the toolkits that need to be installed in the new environment.

For example, when I install 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, preferably with the pandas package installed, so we run the following command To create:

conda create -n py2 python=2.7 pandas

Careful you will find, PY2 environment not only installed pandas, but also installed a series of packages NumPy, which is the convenience of using Conda, it will automatically install the corresponding dependent package for you, and do not need you to manually install.

Enter an environment named Env_name:

source activate env_name

Exit the current environment:

source deactivate

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

To remove an environment named Env_name:

conda env remove -n env_name

Show All environments:

conda env list

When sharing the code, but also need to share the environment to everyone, execute the following command can be in the current environment of the package information into the YAML file named environment.

conda env export > environment.yaml

Similarly, when you execute someone else's code, you also need to configure the appropriate environment. You can use the YAML file you share to create a touch-like environment.

conda env create -f environment.yaml

At this point, you have entered the gate of the Anaconda, you can roam in the sea of Python in the future.

Wish you a happy study!

Note: The code examples in this article refer to the Anaconda section of the Udacity data Analysis course.

Believe that you have read the case of this article you have mastered the method, more exciting please pay attention to the PHP Chinese network other related articles!

Recommended reading:

Python operations Excel read and write data

How to automate unit testing in Python UnitTest

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.