Install Python environment with Anaconda

There are several ways to install Python and its packages, but here's how to install them using Anaconda.

I often see discussions around me about the pros and cons of building an environment with Anaconda and using the Python community standard method. You can choose the one that suits your purpose, but it can be difficult for beginners to determine which one suits their purpose.

Below is a summary of my personal views on the value that Anaconda (Continuum Analytics) offers as a distributor.

Meanwhile, wheel, a tool that provides the official binary distribution for the Python community, has also been enhanced.

I hope it will give you an opportunity to think about something that suits your purpose.

Install Anaconda

You can download Anaconda from the following sites.

You need to select the Python version when installing. There are 2.7 and 3.x versions of Python.

In conclusion, unless you have a specific reason, you can choose the latest version of the new version, 3.x (currently 3.7).

Python is incompatible with 2.x and 3.x, 2.x is in maintenance mode, and the Python community has PEP 373. -0373 /) will be supported until 2020.

Environments that have been using 2.x for some time still have a support period, but no new features will be provided to 2.x in the future. Therefore, if you are new to Python or are developing new ones, you should not hesitate to use the latest version of 3.x.

Installers are available for each OS for Windows, OS X, and Linux. Select and install the installer for the platform you are using.

How to install on Windows

You can download the installer for Windows from the following.

Only a graphical installer is available for Windows. Here, download the 64-bit version and proceed with the installation work.

Run * Anaconda3-5.3.0-Windows-x86_64.exe * to launch the installer.

Install with administrator privileges. If you are not particular about it, you can install it by default as it is. If you install with the default settings, it will be installed in the following location.

C:\Anaconda3

Start a command prompt and run python to see the Python interpreter installed in Anaconda launch as shown below.

C:\Users\user>python
Python 3.7.0 (default, Jun 28 2018, 08:04:48) [MSC v.1912 64bit (AMD64)] :: Anaconda, Inc. on win32
Type "help", "copyright", "credits" or "license" for more information.
>>>

Let's try importing numpy. You can see that the numpy in the Anaconda environment has been imported.

>>> import numpy
>>> numpy.__file__
'C:\\Anaconda3\\lib\\site-packages\\numpy\\__init__.py'

How to install on OS X

You can download the installer for OS X from:

Both graphical and command line installers are available for the OS. Here, download the graphical version and proceed with the installation work.

Run * Anaconda3-5.3.0-MacOSX-x86_64.pkg * to launch the installer.

If you are not particular about it, you can install it by default as it is. If you install it for your personal environment, it will be installed in the following location.

$ ls ~/anaconda/
Navigator.app	bin		conda-meta	envs		etc		include		lib		pkgs		python.app	share		ssl

Run python and check that the Python interpreter installed by Anaconda starts as follows.

$ python
Python 3.7.0 (default, Jun 28 2018, 07:39:16) 
[Clang 4.0.1 (tags/RELEASE_401/final)] :: Anaconda, Inc. on darwin
Type "help", "copyright", "credits" or "license" for more information.

Let's try importing numpy. You can see that the numpy in the Anaconda environment has been imported.

>>> import numpy
>>> numpy.__file__
'/anaconda3/lib/python3.7/site-packages/numpy/__init__.py'

By default, the Anaconda installer sets the environment variable * PATH *. If you are concerned about conflicts between commands installed on your system and commands with the same name installed by Anaconda, you may want to disable this setting and set * PATH * only when using Anaconda.

$ vi ~/.bash_profile
# added by Anaconda3 5.3.0 installer
...
export PATH="/anaconda3/bin:$PATH"

How to install on Linux

You can download the installer for Linux from the following.

Only the command line installer is available for Linux. Here, download the 64-bit version and proceed with the installation work.

$ bash Anaconda3-5.3.0-Linux-x86_64.sh
...
Do you wish the installer to prepend the Anaconda3 install location
to PATH in your /home/vagrant/.bashrc ? [yes|no]
[no] >>>

You will be asked to confirm the license agreement and the installation location interactively, but if you are not particular about it, you can just install it by default. Finally, you will be asked if you want to include the Anaconda-installed executable in the environment variable * PATH * to preferentially use it. The default is * no *.

The pros and cons of changing * PATH * by default are controversial. For example, Anaconda installs the curl command, but it hides the command installed on your system.

$ which curl
/usr/bin/curl
$ export PATH=/path/to/anaconda3/bin:$PATH
$ which curl
~/anaconda3/bin/curl

If you are concerned about conflicts between other commands installed on your system and those installed by Anaconda, do not set * PATH * by default, and only temporarily when using Python (and its environment) installed by Anaconda. Make sure to set * PATH * on your device.

$ export PATH=/path/to/anaconda3/bin:$PATH

If you install with the default settings, it will be installed in the following location.

$ ls ~/anaconda3/
LICENSE.txt  conda-meta  etc  libexec  phrasebooks  qml
ssl vscode_inst.py.log  bin  doc  include  man  pkgs  resources
translations  x86_64-conda_cos6-linux-gnu  compiler_compat  envs
lib  mkspecs  plugins  share  var

After setting * PATH *, try starting Python.

$ python
Python 3.7.0 (default, Jun 28 2018, 13:15:42) 
[GCC 7.2.0] :: Anaconda, Inc. on linux
Type "help", "copyright", "credits" or "license" for more information.

Let's try importing numpy. You can see that the numpy in the Anaconda environment has been imported.

>>> import numpy
>>> numpy.__file__
'/path/to/anaconda3/lib/python3.7/site-packages/numpy/__init__.py'

What is Anaconda ...

A Python distribution that includes Python provided by Continuum Analytics and a package manager called conda. The site states that it includes R and Scala packages in addition to Python, but you can think of them as mainly Python packages.

Anaconda seems to want to provide a platform dedicated to data science. That's why it features a set of packages that are commonly used in Python for those areas.

In general, in the world of Python, tools and libraries that analyze large amounts of data are important for processing performance, so extension modules developed in languages such as C / C ++ ([Extending and embedding the Python interpreter]([Python interpreter extension and embedding]) There are many packages that include http://docs.python.jp/3.5/extending/extending.html)). To install these packages, you need to compile and install for the OS you are using in your local environment, but Anaconda compiles in your local environment by providing a pre-compiled package (binary distribution). You can install it without any hassle.

It's not difficult for the average developer to build an environment for compiling Python C extensions. However, the task of creating such an environment can be painful for researchers and data scientists. A binary distribution called Anaconda is popular because it eliminates the complexity of building such a development environment.

What is Miniconda ...

A tool called pip is provided as a standard Python package manager, but if you are familiar with the Anaconda environment, [conda](http: //: //) You can also use conda.pydata.org) as your package manager.

Anaconda is a distribution that includes a set of packages for data science, while you can also install only Python and conda with a minimal configuration. The minimum configuration distribution is called Miniconda.

Miniconda can be downloaded and installed from:

Easy to use conda

Let's use * conda * as a package manager.

Display a list of installed packages

$ conda list
# packages in environment at /path/to/anaconda3:
#
_license                  1.1                      py36_1
alabaster                 0.7.9                    py36_0
anaconda                  4.3.0               np111py36_0
anaconda-client           1.6.0                    py36_0
anaconda-navigator        1.4.3                    py36_0
...

Search for packages

$ conda search django
Using Anaconda Cloud api site https://api.anaconda.org
Fetching package metadata .......
django                       1.6.5                    py26_0  defaults
                             1.6.5                    py27_0  defaults
                             1.6.5                    py33_0  defaults
                             1.6.5                    py34_0  defaults
...

Install the package

$ conda install django
Using Anaconda Cloud api site https://api.anaconda.org
Fetching package metadata .......
Solving package specifications: ..........

Package plan for installation in environment /path/to/anaconda3:

The following NEW packages will be INSTALLED:

    django: 1.10.5-py36_0

Proceed ([y]/n)? y

Upgrade package

$ conda update lxml
Using Anaconda Cloud api site https://api.anaconda.org
Fetching package metadata .......
Solving package specifications: ..........

Package plan for installation in environment /path/to/anaconda3:

The following packages will be UPDATED:

    lxml: 3.7.1-py36_0 --> 3.7.2-py36_0

Proceed ([y]/n)? y

Remove the package

$ conda remove django
Fetching package metadata .......
Using Anaconda Cloud api site https://api.anaconda.org
Solving package specifications: ..........

Package plan for package removal in environment /path/to/anaconda3:

The following packages will be REMOVED:

    django: 1.10.5-py36_0

Proceed ([y]/n)? y

Build different versions of Python environment

Thanks to @python_ufo and @y__sama for their comments. Thank you very much.

As a function of conda, in addition to being able to build a virtual environment for Python, it seems that it can handle switching between multiple versions of Python. If you don't use Anaconda, use virtualenv to build a virtual environment, and pyenv to switch between multiple versions of Python. I think that com / yyuu / pyenv) is often used. It seems that it can be used as an alternative to these with the function of conda.

I am building a virtual environment called * py27 * that uses Python 2.7.

$ conda create -n py27 python=2.7 anaconda

You can check the environment you are currently using as follows.

$ conda info -e
# conda environments:
#
py27                     /path/to/anaconda3/envs/py27
root                  *  /path/to/anaconda3

To switch to the * py27 * environment on Linux or OS X, use the shell's built-in command * source * and run: Windows does not have a * source * command, so execute the * activate * command directly.

$ source activate py27  # $ activate py27 (on windows)
(py27) $ 

Make sure that the environment is switched with the conda command.

(py27) $ conda info -e
# conda environments:
#
py27                  *  /path/to/anaconda3/envs/py27
root                     /path/to/anaconda3

(py27) $ python
Python 2.7.13 |Anaconda 4.3.0 (64-bit)| (default, Dec 20 2016, 23:09:15) 
[GCC 4.4.7 20120313 (Red Hat 4.4.7-1)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
Anaconda is brought to you by Continuum Analytics.
Please check out: http://continuum.io/thanks and https://anaconda.org
>>> 

To exit the * py27 * environment, execute as follows.

(py27) $ source deactivate  # $ deactivate (on windows)

$ python
Python 3.6.0 |Anaconda custom (64-bit)| (default, Dec 23 2016, 12:22:00) 
[GCC 4.4.7 20120313 (Red Hat 4.4.7-1)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> 

conda documentation

For details on how to use conda, refer to the official document Using conda.

Easy to use anaconda-client

A repository is provided to manage the package called Anaconda Cloud. It seems that you can also upload arbitrary packages to the personal area of this repository and manage packages for personal use. It's free for public project plans and $ 7 / month for private plans.

Anaconda-client (https://github.com/Anaconda-Platform/anaconda-client) is provided as a command line interface for interacting with Anaconda Cloud. You can work with Anaconda Cloud using the command * anaconda * by installing anaconda-client (if you installed the Anaconda distribution, you also have anaconda-client installed).

Search and install packages not provided by conda from Anaconda Cloud

Here, the package LittleHTTPServer is used as an example.

Searching for packages not provided by conda will not show anything.

$ conda search littlehttpserver
Using Anaconda Cloud api site https://api.anaconda.org
Fetching package metadata .......

Try searching the repository on Anaconda Cloud using anaconda-client. It seems that you can specify either * conda * or * pypi * package type with * -t (--package-type) * option. Here, specify * conda *.

$ anaconda search -t conda littlehttpserver
Using Anaconda API: https://api.anaconda.org
Run 'anaconda show <USER/PACKAGE>' to get more details:
Packages:
     Name                      |  Version | Package Types   | Platforms      
     ------------------------- |   ------ | --------------- | ---------------
     auto/littlehttpserver     |    0.1.4 | conda           | linux-64       
                                          : http://bitbucket.org/t2y/littlehttpserver
     t2y/LittleHTTPServer      |    0.5.0 | pypi, conda     | linux-64       
                                          : Little bit extended SimpleHTTPServer
Found 2 packages

I found two packages of littlehttpserver that someone has published. Select 0.5.0, which is the latest version at the moment. Here, select the package published by the user * t2y *.

Execute the installation command with the * -c (--channel) * option specified as follows.

$ conda install -c https://conda.anaconda.org/t2y littlehttpserver
Fetching package metadata ...........
Solving package specifications: .

Package plan for installation in environment /path/to/anaconda3:

The following NEW packages will be INSTALLED:

    littlehttpserver: 0.5.0-py36_0 t2y

Proceed ([y]/n)? y

You can see that littlehttpserver keras is installed from the package list.

$ conda list | grep littlehttpserver
littlehttpserver          0.5.0                    py36_0    t2y

$ littlehttpserver --help
usage: littlehttpserver [-h] [-d DOCUMENT_DIR] [-i INDEX_DIRECTORY]
                        [-p PORT_NUMBER] [-v] [--protocol PROTOCOL]
                        [--servertype {process,thread}] [--version]

optional arguments:
  -h, --help            show this help message and exit
  -d DOCUMENT_DIR, --dir DOCUMENT_DIR
                        set some document directories
  -i INDEX_DIRECTORY, --indexdir INDEX_DIRECTORY
                        set arbitrary top directory
  -p PORT_NUMBER, --port PORT_NUMBER
                        set server port number
  -v, --verbose         set verbose mode
  --protocol PROTOCOL   set protocol
  --servertype {process,thread}
                        set server type
  --version             show program version

documentation for anaconda-client

For details on how to use anaconda-client, refer to the official document Anaconda Cloud.

Recommended Posts

Install Python environment with Anaconda
Install scrapy in python anaconda environment
install tensorflow in anaconda + python3.5 environment
Change Python 64bit environment to 32bit environment with Anaconda
[Python] Create a virtual environment with Anaconda
Use Python 3.8 with Anaconda
Install Voluptuous with Python 2.5
Build Python environment with Anaconda on Mac
Python environment with docker-compose
Install python with pyenv
Virtual environment with Python 3.6
Building an Anaconda environment for Python with pyenv
Building a Python environment with WLS2 + Anaconda + PyCharm
Install OpenCV 4.0 and Python 3.7 on Windows 10 with Anaconda
Use Python in Anaconda environment with VS Code
From Python environment construction to virtual environment construction with anaconda
Python + Anaconda + Pycharm environment construction
Install Keras (used with Anaconda)
Manage python environment with virtualenv
Install external libraries with Python
Build python3 environment with ubuntu 16.04
Anaconda3 python environment construction procedure
Prepare python3 environment with Docker
Build python environment with direnv
install python
Python development environment with Windows + Anaconda3 + Visual Studio Code
How to install python using anaconda
Get started with Python! ~ ① Environment construction ~
Install Python 2.7.9 and Python 3.4.x with pip.
Anaconda python environment construction on Windows 10
Build python virtual environment with virtualenv
Setup modern Python environment with Homebrew
I can't install python3 with pyenv-vertualenv
Install Python from source with Ansible
Install python2.7 on windows 32bit environment
Build Mysql + Python environment with docker
Create a virtual environment with Python!
Install Python 3.7 Anaconda on MAC, but Python 2
I can't install mysql-connector-python with anaconda
Python environment construction (pyenv, anaconda, tensorflow)
Building a virtual environment with Python 3
Install the Python plugin with Netbeans 8.0.2
Unable to install Python with pyenv
Python3 environment construction with pyenv-virtualenv (CentOS 7.3)
Install Python development environment on Windows 10
pytorch @ python3.8 environment construction with pipenv
Prepare Python development environment with Atom
Install python with mac vs code
How to install Anaconda with pyenv
Python3.6 environment construction (using Win environment Anaconda)
[Python Windows] pip install with Python version
Install CaboCha in Ubuntu environment and call it with Python.
[Pyenv] Building a python environment with ubuntu 16.04
[Ubuntu 18.04] Python environment construction with pyenv + pipenv
FizzBuzz with Python3
Competitive programming with python Local environment settings
Python 3.3 in Anaconda
Scraping with Python
Python (anaconda) development environment construction procedure (SpringToolsSuites) _2020.4
Building a Python3 environment with Amazon Linux2
Build Jupyter Lab (Python) environment with Docker