Configuring the environment with Anaconda

Source: Internet
Author: User
Tags windows support
Summary of the use of Anaconda

Python is easy to use, but it's not easy to work with, and the headaches are the problem of package management and different versions of Python, especially when you're using Windows. To address these issues, there are a number of distributions of Python, such as Winpython, Anaconda, and so on, which pack Python and many commonly used package to facilitate pythoners direct use, in addition to Virtualenv, Tools such as pyenv manage virtual environments. Anaconda Overview

Anaconda is a Python release for scientific Computing, supports Linux, MAC, Windows, and provides package management and environmental management capabilities to easily address multiple versions of Python coexistence, switching, and a variety of third-party package installation issues. Anaconda uses tools/command Conda for package and environment management, and already contains Python and related tools.

Here we first explain the differences between the concepts of Conda and Anaconda. Conda can be understood as a tool and an executable command whose core functions are package management and environmental management. Package management is similar to the use of the PIP, and environmental management allows users to easily install different versions of Python and can switch quickly. Anaconda is a packaged collection of Conda, a version of Python, numerous packages, scientific computing tools, and so on, which is also known as a release of Python. In fact, there are Miniconda, as the name suggests, it contains only the most basic content--python and Conda, as well as the relevant must rely on, for the space requirements of users, Miniconda is a choice.

Before you go to the next section, explain Conda's design philosophy--conda treats almost all of the tools and Third-party packages as package, including Python and Conda itself. As a result, Conda has broken the constraints of package management and environmental management, and can easily install various versions of Python, various package, and easily switch.

Installation of Anaconda

Anaconda download page, Linux, MAC, Windows support.

When you install, you will find two different versions of Anaconda, corresponding to Python 2.7 and Python 3.5, and two versions in fact all the same except for this distinction. As we'll see later, it's not essential to install which version because we can easily switch the Python version of the runtime through environmental management. (Since my usual Python is 2.7 and 3.4, I tend to install Python 2.7 corresponding Anaconda directly)

After downloading directly follow the instructions to install it. Here's a caveat: try to install it as anaconda Default-without using root, for personal installation, 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 install and configure their own anaconda without affecting each other.

For a Mac, Linux system, Anaconda installed, in fact, in the home directory more than a folder (~/anaconda) only, Windows will write to the registry. When installed, the installer adds the bin directory to the path (Linux/mac write ~/.bashrc,windows to the system variable path), which can be done entirely on its own. Taking Linux/mac as an example, setting path after installation is done by adding 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
Add the Anaconda Bin directory to 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 your path, you can check for correctness through the which Conda or conda–version command. If a 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), which also indicates that 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 to switch freely. For the above installation process, assuming that we are using the Python 2.7 corresponding installation package, then Python 2.7 is the default environment (the default name is root, and note that this root is not meant for super administrators).

Assuming we need to install Python 3.4, we need to do the following: create an environment named Python34, and specify that Python version is 3.4 (3.4.x,conda will automatically find the latest version of 3.4.x for us)

Conda Create--name python34 python=3.4
after installation, use activate to activate an environment
Activate Python34 # for Windows
source activate Python34 # for Linux & Mac
after activation, you will find that terminal input more than the python34 word, in fact, the system is doing is to remove the default 2.7 environment from the path, and then 3.4 corresponding command to join the path at this point, enter again
Python--version
can get Python 3.4.5:: Anaconda 4.1.1 (64-bit), the system has switched to 3.4 of the 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
Create an environment named PYTHON34 that specifies that the Python version is 3.4 (3.4.x,conda will automatically find the latest version of the 3.4.x for us)
Conda Create--name python34 python=3.4
after installation, use activate to activate an environment
Activate Python34 # for Windows
source activate Python34 # for Linux & Mac
after activation, you will find that terminal input more than the python34 word, in fact, the system is doing is to remove the default 2.7 environment from the path, and then 3.4 corresponding command to join the path at this point, enter again
Python--version
can get Python 3.4.5:: Anaconda 4.1.1 (64-bit), the system has switched to 3.4 of the 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

The different Python environments that users install are placed under the directory ~/anaconda/envs and can be run Conda INFO-E view the installed environment in the command, and an asterisk or parenthesis is displayed in the currently activated environment.

Description: Some users may often use the Python 3.4 environment, so directly add the bin or scripts below the ~/ANACONDA/ENVS/PYTHON34 to the path and remove the anaconda corresponding Bin directory. This method, how to say, also can, but always feel not so elegant ...

If you follow the above mentioned so change path, you will find Conda command and can not find (of course, because Conda in ~/anaconda/bin), this time how to do it. The method has two: 1. Explicitly gives the absolute address of the Conda 2. The Conda tool (recommended) is also installed in the PYTHON34 environment.

Package Management for Conda

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

For example, if you need to install SciPy: install scipy

Conda Install SciPy
Conda from remote search scipy information and dependencies, for Python 3.4,conda to install both NumPy and MKL (compute-accelerated libraries) View the packages that have been installed

the latest version of the Conda list Conda to search for installed packages from the Site-packages folder, and does not depend on the PIP, so you can display the installation of packages in various ways scipy

Conda Install SciPy
Conda from remote search scipy information and dependencies, for Python 3.4,conda to install both NumPy and MKL (compute-accelerated libraries) View the packages that have been installed
Conda List
the latest version of Conda is to search the Site-packages folder for installed packages, not on the PIP, so you can display packages installed in various ways

Some common operations for Conda are as follows: view installed packages in the current environment

Conda List
to view installed packages for a specified environment
Conda List-n Python34
Find package Information
Conda Search NumPy
Install package
Conda install-n python34 NumPy
If the environment name is not specified with-N, it is installed in the current active environment You can also specify through a channel installation via-C Update Package
Conda update-n python34 NumPy
Delete Package
Conda remove-n python34 NumPy
view installed packages in the current environment
Conda List
to view installed packages for a specified environment
Conda List-n Python34
Find package Information
Conda Search NumPy
Install package
Conda install-n python34 NumPy
If the environment name is not specified with-N, it is installed in the current active environment You can also specify through a channel installation via-C Update Package
Conda update-n python34 NumPy
Delete Package
Conda remove-n python34 NumPy

As mentioned earlier, Conda treats Conda, Python, and so on as package, so it is entirely possible to use Conda to manage versions of Conda and Python, such as updating Conda, keeping 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 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, after running Conda create-n python34 python=3.4, Conda installs only Python 3.4-related required items such as Python, Pip, If you want the environment to install the Anaconda collection package like the default environment, you only need to: Install the Anaconda Package collection in the current environment

Conda Install Anaconda
combined with the command to create an environment, the above actions can be merged into
Conda create-n python34 python=3.4 Anaconda
also can not install all, according to the need to install their own package can be Install the Anaconda Package collection in the current environment
Conda Install Anaconda
combined with the command to create an environment, the above actions can be merged into
Conda create-n python34 python=3.4 Anaconda
also can not install all, according to the need to install their own package can be

Set up a domestic mirror

If you need to install a lot of packages, you will find that Conda downloads are often slow because anaconda.org servers are abroad. Fortunately, Tsinghua Tuna mirror source has anaconda warehouse mirroring, we add it to the Conda configuration can: Add anaconda Tuna Mirror

Conda Config--add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
The mirror address in Tuna's help is enclosed in quotes and needs to be removed To display a channel address when searching
Conda Config--set show_channel_urls Yes
Add a anaconda tuna mirror
Conda Config--add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
The mirror address in Tuna's help is enclosed in quotes and needs to be removed To display a channel address when searching
Conda Config--set show_channel_urls Yes
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.