Python third-party library management Anaconda

Source: Internet
Author: User
Tags jupyter jupyter notebook

First, Anaconda Introduction:

Anaconda is an open source version of Python, primarily for scientific computing. We can simply understand that Anaconda is a python that is preloaded with a lot of third-party libraries that we use or do not use. and the Conda Install command is added to Anaconda in comparison to the familiar pip install command. When you are familiar with Anaconda, you will find that Conda install will be more convenient than Pip install. For example, we often worry about the problem of lxml package, under Windows PIP is not installed smoothly, and the Conda command can be, the following will be detailed display.

Second, Anaconda download installation:

(a) Download

Anaconda's official website download Anaconda now!. In contrast to Python, Anaconda's version is divided into Anaconda2 and Anaconda3, which you can download on your own for everyday use, with 32-bit and 64-bit downloads. (2.x and 3.x mixed with the students do not worry, we will talk about the specific version management). Considering that the Anaconda website is slow to download, it is recommended to download and configure the image (Index of/anaconda/archive/) from the Tsinghua Open source software mirror station in China.

Choose the appropriate version to download it (directly looking for the latest version of 2017 Anaconda2 or Anaconda3).

(ii) installation

1, Anaconda installation path do not appear blank;

2, two need to confirm the place, the first tick is whether to add Anaconda environment variables, which relates to the use of the CMD directly in the Conda, Jupyter, Ipython and other commands, recommended tick, if not tick the question is not big, You can then use the command-line tool provided by Anaconda, and the second is whether to set Anaconda Python 3.6 as the default Python version of the system, which is not a problem to look at.

(iii) test installation

Installation is completed, you need to open cmd test installation results, respectively, enter Python, Ipython, Conda, Jupyter notebook and other commands, you will see the corresponding results, indicating that the installation was successful.

    • Python is entered into the Python interactive command line
    • Ipython is entered into the Ipython interactive command line
    • Conda is a configuration command for Anaconda
    • Jupyter Notebook will start the web-side Ipython Notebook (note: The Jupyter notebook command starts the Jupyter service locally on the PC with the default configuration)

(iv) Modifying the package management image

After the Anaconda installation is successful, we need to modify its package management image as a domestic source. (Tsinghua Open Source Mirror)

In simple terms, it's good to run these two commands separately in CMD.

Command line--

conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/conda config --set show_channel_urls yes

After setting up the image, we continue to manage the environment.

Iv. management of different version environments under Anaconda:

The latest version of Anaconda3 has been installed, with a python version of 3.6, which requires the addition of the 2.7 version of Python to do the following. (Similarly, if someone installs the Anaconda2 need to add Python 3.x, then the action in 2.7 to 3.6 or 3.5 can be)

1. Add new environment

Command line--

conda create -n py27 python=2.7

Where Py27 is the name of the newly added environment, you can customize the changes.

2. activating/exiting the new environment

Activate and exit the environment by activate PY27 and deactivate py27 commands. (Commands for Linux and OS systems appear to be source activate and source deactivate)

Command line--

activate py27

3. Install the third-party library in the new environment

After activating the new environment, all we do is to install the third-party library in the new environment, including the PIP command. Let's try Pip installation lxml.

Command line--

conda install -n py27 lxml

"Note" The direct installation of the lxml library under Python may cause an error.

Command line--

pip install lxml

Of course, a library that can be installed normally can use the PIP command naturally.

4. View existing Environment

View existing environments with the Conda info-e command.

conda install -n py27 anaconda

5. Install scientific calculation package for new environment

Since we are now installing ANACONDA3 and then adding a new Python 2.7 environment, the Python 3.6 environment is installed with Anaconda's own scientific computing environment, but not in Python 2.7. So how to add a Anaconda scientific calculation package to the newly added environment:

Command line-

conda install -n py27 anaconda


6、Jupyter下不同环境并存

 Anaconda中可以使Python 2.x和3.x共存,Jupyter Notebook是否可以呢?

Multiple versions of the Python or R languages, known as kernel in Jupyter.

There are two ways to add multiple Python versions of kernel to Jupyter.

method One: if the desired Python version already exists (such as the PY27 environment we just added), then you can install the Ipykernel package directly for this environment. That

Command line--

conda install -n py27 ipykernel

Then activate the environment and enter

Command line--

python -m ipykernel install --user

method Two: the required version is not an existing environment and can be preinstalled ipykernel directly when the environment is created.

Command line--

conda create -n py27 python=2.7 ipykernel

PS. If you want to install a new version of the environment, directly loaded with other libraries, like here Ipykernel directly attached to the back. It also activates the environment and adds kernel.

PS. The command generates a JSON file that can be viewed and modified directly.

"Note" Some libraries, whether Conda or PIP, cannot be installed directly and can only be downloaded. WHL, this is no longer mentioned here, small white students encounter this problem, should also have the ability to solve this problem.

8. Delete the new environment

Delete the specified environment by Conda remove-n Env_name--all (if you do not add the--all parameter, but instead indicate a library name, delete the library).

For example I want to delete py35 this environment now.

I hope you are no longer because of the choice of version, install Python, manage the environment, add third-party libraries (can use Conda with Conda, cannot use the Conda with PIP), select the IDE (single file Jupyter, project organization Open Pycharm) and so on chores, focus on the code.

Python third-party library management Anaconda

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.