Building a Python environment for pyenv, pyenv-virtualenv, Anaconda (Miniconda)

Building a Python environment for pyenv, pyenv-virtualenv, Anaconda

--I want to use multiple Python versions (2 series, 3 series) --I want to create a virtual environment ――But I don't usually care much

It is a memo of how to build an environment for myself.

The main usage is

--Usually, if you hit ipython or `` `jupyter notebook```, the default version and library environment will be launched. --If you enter the project directory, the Python version and installed libraries will switch.

It is assumed that.

In Previous article, it is assumed that the installation of anyenv is in the environment.

Installing `pyenv`

anyenvBy using, it will end immediately. (For `pyenv` alone, write PATH to Shell profile.)

$ anyenv install pyenv

shellRefresh the environment.

$ exec $SHELL -l

pyenv -vsopyenvIf the version of is displayed, it is installed.

$ pyenv -v
pyenv 1.1.3-5-g7dae197

Installing `` `pyenv-virtualenv```

pyenvIs a plug-in ofpyenv-virtualenvTo install. This is as described in 3 types of workarounds for activate collision problem when pyenv and anaconda coexist.

pyenv and anaconda activate collision problem

It is a work to avoid.

Follow the installation instructions on Pyenv-virtualenv official github page.

$ git clone https://github.com/pyenv/pyenv-virtualenv.git $(pyenv root)/plugins/pyenv-virtualenv

Add the following to the Shell profile.

eval "$(pyenv virtualenv-init -)"

After adding, refresh the Shell environment.

$ exec $SHELL -l

This completes the installation of pyenv-virtualenv.

Installation of Anaconda

pyenvUsingpythonInstall. Basically, I use `Python3```, so I will build the `Python3environment. We will also useAnaconda``` to install various libraries at once.

Check the list of installable environments.

$ pyenv install -l
Available versions:
    2.1.3
    2.2.3
    ...
    anaconda3-4.3.1
    anaconda3-4.4.0
    ironpython-dev
    ...

As of July 30, 2017, anaconda3-4.4.0 seems to be the latest Anaconda3. After deciding the installation environment, install with the following command.

$ pyenv install anaconda3-4.4.0
Downloading Anaconda3-4.4.0-MacOSX-x86_64.sh...
-> https://repo.continuum.io/archive/Anaconda3-4.4.0-MacOSX-x86_64.sh
Installing Anaconda3-4.4.0-MacOSX-x86_64...
Installed Anaconda3-4.4.0-MacOSX-x86_64 to /Users/(USER NAME)/.anyenv/envs/pyenv/versions/anaconda3-4.4.0

This completes the installation of the Ana conda3-4.4.0 environment.

`` `pyenv global / local``` environment settings

Ana conda3 with pyenv-4.4.Just installing 0 will not switch versions.



```pyenv global/local```Using,```python```Toggle the version of.

 First, check the current version of ``` Python```.

```shell-session
$ python -V
Python 2.7.10

$ python3 -V
pyenv: python3: command not found

The 'python3' command exists in these Python versions:
    anaconda3-4.4.0

Only `` `Python 2.7.10```, which was installed from the beginning, is available.

Check the list of currently available Python.

$ pyenv versions
* system (set by /Users/(USER NAME)/.anyenv/envs/pyenv/version)
  anaconda3-4.4.0

system (set by /Users/(USER NAME)/.anyenv/envs/pyenv/version)When,



#### **`anaconda3-4.4.You can see that 0 is installed.`**

However, anaconda3-4.4.0 is not ready for use. (``` *` `` represents the environment you are currently using.)

Let's set the previously installed anaconda3-4.4.0 as the default.

$ pyenv global anaconda3-4.4.0

The anaconda3-4.4.0 environment is now applied by default in any directory.

pythonIf you want to use both 2nd and 3rd series, set as follows.

$ pyenv global system anaconda3-4.4.0

Now you can use both series 2 and 3 with the `` `pythoncommand and the python3``` command.

$ pyenv version
* system (set by /Users/(USER NAME)/.anyenv/envs/pyenv/version)
* anaconda3-4.4.0 (set by /Users/(USER NAME)/.anyenv/envs/pyenv/version)

$ python -V
Python 2.7.10

$ python3 -V
Python 3.6.1 :: Anaconda 4.4.0 (x86_64)

If you want to switch the version only under a specific directory, use the `` `pyenv local``` command.

$ cd target_dir
$ pyenv local (VERSION NAME)

$ python -V
Python (VERSION)

How to create / use a virtual environment

Next, let's create a virtual environment assuming actual development.

First, create a virtual environment using the conda command that accompanies Anaconda3.

Here, let's create an environment of Python3.5.2.

$ conda create -n py3.5.2 python=3.5.2 anaconda

With this command

--Virtual environment name: py3.5.2 --Python version: 3.5.2 --Installed libraries: Anaconda

You can create an environment called. condaCheck the virtual environment created by the command.

$ conda info -e
# conda environments:
#
py3.5.2                  /Users/(USER NAME)/.anyenv/envs/pyenv/versions/anaconda3-4.4.0/envs/py3.5.2
root                  *  /Users/(USER NAME)/.anyenv/envs/pyenv/versions/anaconda3-4.4.0

pyenv versionsYou can also check with the command.

$ pyenv versions
* system (set by /Users/(USER NAME)/.anyenv/envs/pyenv/version)
* anaconda3-4.4.0 (set by /Users/(USER NAME)/.anyenv/envs/pyenv/version)
  anaconda3-4.4.0/envs/py3.5.2

Let's adapt the created anaconda3-4.4.0 /envs/py3.5.2 environment.

Before adaptation:

$ python -V
Python 2.7.10
$ python3 -V
Python 3.6.1 :: Anaconda 4.4.0 (x86_64)

After adaptation:

$ pyenv activate anaconda3-4.4.0/envs/py3.5.2
$ python -V
Python 3.5.2 :: Anaconda 4.3.1 (x86_64)
$ python -V
Python 3.5.2 :: Anaconda 4.3.1 (x86_64)

Release:

$ pyenv deactivate
$ python -V
Python 2.7.10
$ python3 -V
Python 3.6.1 :: Anaconda 4.4.0 (x86_64)

Also, if you want to switch the environment only under a specific directory, use `` `pyenv local```.

Before adaptation:

$ python -V
Python 2.7.10
$ python3 -V
Python 3.6.1 :: Anaconda 4.4.0 (x86_64)

After adaptation:

$ pyenv local anaconda3-4.4.0/envs/py3.5.2
$ python -V
Python 3.5.2 :: Anaconda 4.3.1 (x86_64)
$ python -V
Python 3.5.2 :: Anaconda 4.3.1 (x86_64)

Release:

$ pyenv local --unset
$ python -V
Python 2.7.10
$ python3 -V
Python 3.6.1 :: Anaconda 4.4.0 (x86_64)

Summary

  1. Version control with `` `pyenv global / local```
  2. Create a virtual environment with ``` conda create -n (NAME) (PYTHON VERSION) (LIBRARY)` ``
  3. Adaptation of virtual environment
  4. Adapt the virtual environment to the whole with `` `pyenv activate```
  5. Adapt the virtual environment under a specific directory with `` `pyenv local (VERSION NAME) ```
  6. Canceling the virtual environment
  7. Use `pyenv deactivate``` to deactivate `pyenv activate```
  8. Release pyenv local (VERSION NAME)` `` with pyenv local --unset```

Enjoy!

Recommended Posts

Building a Python environment for pyenv, pyenv-virtualenv, Anaconda (Miniconda)
Building an Anaconda environment for Python with pyenv
[Python] Django environment construction (pyenv + pyenv-virtualenv + Anaconda) for macOS
[Pyenv] Building a python environment with ubuntu 16.04
[Mac] Building a virtual environment for Python
Building a Python development environment for AI development
How about Anaconda for building a machine learning environment in Python?
Building a Python environment with WLS2 + Anaconda + PyCharm
Building a virtual environment for Mayavi dedicated to Python 3.6, Anaconda, Spyder users
Building a Python virtual environment
Building a Python virtual environment
Write about building a Python environment for writing Qiita Qiita
Building a Docker working environment for R and Python
Build a python environment for each directory with pyenv-virtualenv
Procedure for building a CDK environment on Windows (Python)
Building a Python environment for programming beginners (Mac OS)
Memo for building a machine learning environment using Python
Notes from installing Homebrew to building an Anaconda environment for Python with pyenv
Building a Python environment on Mac
Building a Python environment on Ubuntu
Python environment construction (pyenv, anaconda, tensorflow)
Building a virtual environment with Python 3
Building a python environment for artificial intelligence (Chainer / TensorFlow / CSLAIER)
Building a development environment for Android apps-creating Android apps in Python
Building a Hy environment for Lisper who hasn't touched Python
[Python] Building a virtual python environment for the pyramid tutorial (summary)
Until building a Python development environment using pyenv on Ubuntu 20.04
[Python] Building an environment with Anaconda [Mac]
Building a Python3 environment with Amazon Linux2
Building a Docker working environment for R and Python 2: Japanese support
Building a Windows 7 environment for getting started with machine learning with Python
Building a virtual environment using homebrew + pyenv-virtualenv
Let's create a virtual environment for Python
[Python] Create a virtual environment with Anaconda
From building a Python environment for inexperienced people to Hello world
Building a Python 3.6 environment with Windows + PowerShell
pyenv + anaconda + python3
Building a conda environment for ROS users
Build a python virtual environment with pyenv
Selenium + WebDriver (Chrome) + Python | Building environment for scraping
Building a python environment with virtualenv and direnv
Building an environment for executing Python scripts (for mac)
[Memo] Build a virtual environment with Pyenv + anaconda
[Python] Web development preparation (building a virtual environment)
Build a simple Python virtual environment without pyenv
A memo when creating a python environment with miniconda
Think about building a Python 3 environment in a Mac environment
Commands for creating a python3 environment with virtualenv
Procedure for creating a Python quarantine environment (venv environment)
A memo for creating a python environment by a beginner
Building a Python environment on a Sakura VPS server
Install python (pyenv, pyenv-virtualenv)
Create a Python environment
Python environment for projects
How to set up a Python environment using pyenv
Recommendation of building a portable Python environment with conda
Create a virtual environment with Anaconda installed via Pyenv
Building a training environment for penetration testing using Naumachia
Use Python installed with pyenv for PL / Python execution environment
Create a comfortable Python 3 (Anaconda) development environment on windows
Building an environment for natural language processing with Python