Anaconda's Novice use Daquan

Source: Internet
Author: User
This time to everyone to bring Anaconda novice use Daquan, novice use anaconda attention to what matters, the following is the actual case, together to see.

Order

Python is easy to use, but not easy, but it's a headache for package management and Python versions, especially when you're using Windows. In order to solve these problems, there are a lot of distributions of Python, such as Winpython, Anaconda, and so on, these distributions will python and many common packages packaged, convenient pythoners direct use, in addition, there are virtualenv, Pyenv and other tools to manage virtual environments.

Individuals tried a lot of similar distributions and eventually chose Anaconda because of their powerful and convenient package management and environmental management capabilities. This paper mainly introduces the next anaconda, the understanding of Anaconda, and briefly summarizes the related operation.

Anaconda Overview

Anaconda is a Python release for scientific computing that supports Linux, MAC, Windows, and provides package management and environmental management capabilities that can easily resolve multiple versions of Python coexistence, switching, and various third-party package installation issues. Anaconda uses the tool/command Conda to manage the package and environment, and it already contains Python and related companion tools.

This first explains the differences between the concepts of Conda and Anaconda. Conda can be understood as a tool and an executable command whose core function is package management and environmental management. Package management is similar to the use of PIP, and environmental management allows users to easily install different versions of Python and switch quickly. Anaconda is a packaged collection that is preloaded with Conda, a version of Python, numerous packages, scientific computing tools, and so on, so it is also known as a distribution version of Python. In fact, there are Miniconda, as the name implies, it contains only the most basic content--python and Conda, as well as related to the necessary dependencies, for the space-demanding users, Miniconda is an option.

Before entering the following, explain Conda's design philosophy--conda almost all the tools, third-party packages are treated as a package, even including Python and Conda itself! As a result, Conda has broken the constraints of package management and environmental management, making it easy to install versions of Python, various packages and easily switch between them.

Installation of Anaconda

Anaconda's download page is available on the website and is supported by Linux, MAC, and Windows.

At the time of installation, there are two different versions of Anaconda, which correspond to Python 2.7 and Python 3.5, and two versions in fact are the same except for the difference between the two. As we'll see later, it's not essential to install which version, because with environmental management, we can easily switch the Python version at runtime. (Since my usual Python is 2.7 and 3.4, I tend to install the Python 2.7 corresponding Anaconda directly)

After downloading, follow the instructions to install it directly. Here's a reminder: try to install as Anaconda default behavior-no root privileges, only personal installs, and the installation directory is set in the Personal home directory (Windows doesn't matter). The advantage is that different users on the same machine can completely install and configure their own anaconda without affecting each other.

For Mac, Linux system, Anaconda is installed, in fact, in the home directory is more than a folder (~/anaconda), Windows will write to the registry. At installation time, the installer will add the bin directory to path (Linux/mac write ~/.bashrc,windows to the system variable path), and these operations can also be done on their own. Take Linux/mac as an example, the operation to set path after the installation is complete is

# Add the Anaconda Bin directory to the path, depending on the version, or it may be ~/anaconda3/bin
echo ' Export path= ' ~/anaconda2/bin: $PATH ' >> ~/.BASHRC
# Update BASHRC for immediate effect
SOURCE ~/.BASHRC

After you have configured path, you can pass which conda or conda --version command to check whether it is correct. If the version of Python 2.7 is installed, running python --version or python-v can get Python 2.7.12:: Anaconda 4.1.1 (64-bit), and the default environment for the release is Python 2.7.

Environmental management of Conda

Conda's environmental management capabilities allow us to install several different versions of Python at the same time and switch freely. For the installation process described above, if we are using a Python 2.7 corresponding to the installation package, then Python 2.7 is the default environment (the default name is root, note that this root is not the super-administrator meaning).

Suppose we need to install Python 3.4, at this point we need to do the following:

# Create an environment named Python34, specify that the Python version is 3.4 (no tube is 3.4.x,conda will automatically find the latest version in 3.4.x for us)
Conda Create--name python34 python=3.4

# At this point, enter again
Python--version
# can get ' Python 3.4.5:: Anaconda 4.1.1 (64-bit) ', i.e. the system has switched to 3.4 environment

# If you want to return to the default Python 2.7 environment, run
Deactivate Python34 # for Windows
SOURCE Deactivate Python34 # for Linux & Mac

# Delete an existing environment
Conda Remove--name python34--all

# when installed, use activate to activate an environment.
Activate Python34 # for Windows
SOURCE Activate Python34 # for Linux & Mac
# after activation, you will find terminal input more than the python34 of the word, in fact, at this time the system is to do is the default 2.7 environment from the path to remove, and then 3.4 corresponding to the command to join the path

The different Python environments installed by the user are placed in the directory ~/anaconda/envs and can be run in the command to conda info -e view the installed environment, and the currently activated environment displays an asterisk or parenthesis.

Note: Some users may often use the Python 3.4 environment, so simply ~/anaconda/envs/python34 add the following bin or scripts to path, removing the bin directory corresponding to the Anaconda. This method, how to say, is also possible, but always feel not so elegant ...

If you change the path directly according to the above, you will find the Conda command and can not find it (of course, because Conda in ~/anaconda/bin), how to do? There are two methods: 1. The absolute address of the Conda is given explicitly in 2. The Conda tool (recommended) is also installed in the PYTHON34 environment.

Package Management for Conda

Conda's package management is better understood, this part of the function is similar to PIP.

For example, if you need to install SciPy:

# Install SciPy
Conda Install SciPy
# Conda will also install NumPy and MKL (op-accelerated libraries) for Python 3.4,conda from remote search scipy related information and dependent projects

# View the packages already installed
Conda List
# The latest version of Conda is to search for installed packages from the Site-packages folder, independent of Pip, so you can display packages installed in various ways

Some common operations of Conda are as follows:

# View installed packages in the current environment
Conda List

# View installed packages for a specified environment
Conda List-n Python34

# Find package Information
Conda Search NumPy

# Install the Package
Conda install-n python34 NumPy
# If you do not use-N to specify the environment name, it is installed in the current active environment
# You can also specify a channel installation via-C

# Update Package
Conda update-n python34 NumPy

# Remove Package
Conda remove-n python34 NumPy

As mentioned earlier, Conda treats Conda, Python, and so on as the package, so you can use Conda to manage versions of Conda and Python, such as

# update Conda, keep Conda up to date
Conda Update Conda

# Update Anaconda
Conda Update Anaconda

# Update Python
Conda Update python
# Assuming the current environment is Python 3.4, Conda will upgrade Python to the current latest version of the 3.4.x series

Add: If you create a new Python environment, such as 3.4, conda create -n python34 python=3.4 after running, Conda only installs Python 3.4 related required items, such as Python, Pip, etc., if you want the environment to install the Anaconda Collection package as the default environment, you only need:

# Install the Anaconda Package collection in the current environment
Conda Install Anaconda

# Combined with commands to create an environment, the above actions can be combined into
Conda create-n python34 python=3.4 Anaconda
# You can also install your own package if you need it without installing it all

Set up a domestic mirror

If you need to install a lot of packages, you will find that Conda download is often very slow, because anaconda.org server is abroad. Fortunately, the Tsinghua tuna image source has a anaconda warehouse image, we add it to the Conda configuration:

# Add a anaconda tuna mirror
Conda Config--add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
# Tuna's help in the mirror address with quotation marks, need to remove

# Set the channel address to be displayed when searching
Conda Config--set show_channel_urls Yes

After executing the above command, a ~/.condarc (LINUX/MAC) or C:\Users\USER_NAME\.condarc file is generated, which records our configuration of the Conda, and it is the same effect to manually create and edit the file directly.

Sequence

The Anaconda features cross-platform, package management, and environmental management, making it ideal for quickly deploying a python environment on a new machine. In summary, the entire installation and configuration process is as follows:

    • Download Anaconda, install

    • Configure path (BASHRC or environment variable), change tuna mirror source

    • Create the required Python environment without a version

    • Just try!

Cheat-sheet Download:

Conda Cheat Sheet

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

Python uses the UnitTest test interface to step through the detailed

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.