[Python] Anaconda, pyenv, virtualenv, .bash_profile

2018/01/03 update

My Mac broke and I was building a Python environment from the beginning There is no virtualenv in pyenv! !! I was scolded by terminal Added to install pyenv-virtualenv when pyenv install. Since virtualenv cannot be deleted, it is modified to pyenv uninstall virtualenv_name.

Introduction

I'm using pyenv-virtualenv in Anaconda's environment When I check with python -V, the Python version is fixed Is (virtualenv_name) displayed all the time on the terminal line and you can't deactivate it? Yes, I am.

So, I finally got to change the Python environment by referring to the articles of Qiita gentlemen and ladies. This is an article compiled for MEMO.

Articles that I used as a reference Markdown notation cheat sheet Note from installing Homebrew to building an Anaconda environment for Python with pyenv Building a python environment for each directory with pyenv-virtualenv virtualenv basic command usage memo Building an environment with pyenv and virtualenv Python environment construction for those who aim to become data scientists 2016 Install the Python environment with Anaconda [Definitive Edition] Building an environment for learning "machine learning" using Python on Mac

Install pyenv with homebrew

First, install pyenv with Brew. Open terminal

pyenv and pyenv-Install virtualenv


$brew install pyenv
$brew install pyenv-virtualenv

If you don't have Brew, install Brew first. Please refer to the many articles that were taken care of by Qiita.

Edit .bash_profile

Once pyenv is installed, play with .bash_profile. Open Terminal

.bash_Describe the following in profile


$echo 'export PYENV_ROOT="${HOME}/.pyenv"' >> ~/.bash_profile
$echo 'export PATH="${PYENV_ROOT}/bin:$PATH"' >> ~/.bash_profile
$echo 'eval "$(pyenv init -)"' >> ~/.bash_profile

Don't forget the "{}", as python --version will look weird later even though Anaconda is set up in pyenv.

with cat.bash_Check the contents of profile


$cat ~/.bash_profile

After rewriting .bash_profile, close and reopen terminal, source ~ / .bash_profile.

Install python with pyenv

Now, let's install Python with pyenv. First, display a list of Python versions that can be installed with pyenv.

Python_version_list display


$pyenv install -l

Install any of the listed Python versions. Of course, looking at this article is Anaconda, isn't it? Please install and verify both 2nd and 3rd series.

Install Anaconda with pyenv


$pyenv install [python_version]
$pyenv install [another_python_version]

Check the version of python installed in pyenv.

Python installed in pyenv_version confirmation


$pyenv versions

It's OK if multiple python_versions set in system are displayed, Also, the activated python_version is prefixed with *.

Global python and local python settings in pyenv

Here is a review, but in pyenv global (reflected in any directory) You can set python_version of local (only the current directory at the time of setting is reflected).

global python_version setting


$pyenv global [python_version]

Let's see if the global python_version is set successfully.

python set to global_version confirmation


$pyenv global

Did you see the python_version you set earlier?

Next, try setting the local python_version.

local python_version setting


$pyenv local [python_version]

Check if local python_version is set in the current directory.

python set to local_version confirmation


$pyenv local

I think you can see the python_version set to local Remove the python_version set to local once.

local set python_Release version


$pyenv local --unset

Update the python version displayed in the pyenv install list


$brew update
$brew upgrade pyenv

virtualenv Now let's get into the virtualenv settings. You can build and use a virtual environment with your favorite python_version.

Virtual environment python_Set version and name


$pyenv virtualenv [python_version] [virtualenv_name]

Let's check if the virtual environment virtualenv_name has been added to pyenv.

virtualenv in pyenv_Check if name has been added


$pyenv versions

After confirming that it has been added, let's activate the virtual environment virtualenv_name.

Virtual environment virtualenv_activate name


$pyenv activate [virtualenv_name]

Did you see (virtualenv_name) at the beginning of the terminal line? You can activate it in any directory.

Now, let's cancel the virtual environment virtualenv_name.

Virtual environment virtualenv_deactivate name


$pyenv deactivate

Did the (virtualenv_name) displayed at the beginning of the terminal line disappear?

Delete the virtual environment virtualenv_name that was built last.

Virtual environment virtualenv_delete name


$pyenv uninstall [virtualenv_name]

MEMO is over !!

After setting the virtualenv of anaconda3-4.0.0 to local yesterday When I python -V, 3.6.0 is displayed, it should be 3.5.1 ... I'm a super beginner enough to use Markdown notation for the first time With the accumulation of Qiita's Knowledge, it is now possible to play with python somewhat decently. We would like to express our utmost gratitude to everyone who shared many good articles and Qiita.

Recommended Posts

[Python] Anaconda, pyenv, virtualenv, .bash_profile
pyenv + virtualenv + Anaconda
pyenv + anaconda + python3
Python environment construction (pyenv, anaconda, tensorflow)
Python environment construction on Mac (pyenv, virtualenv, anaconda, ipython notebook)
Python 3.3 in Anaconda
python in virtualenv
Python3 TensorFlow environment construction (Mac and pyenv virtualenv)
Building an Anaconda environment for Python with pyenv
python development environment -use of pyenv and virtualenv-
Pyenv + virtualenv on Mac
Install python (pyenv, pyenv-virtualenv)
Use Python 3.8 with Anaconda
Install python with pyenv
[Python] What is virtualenv
Building a Python environment for pyenv, pyenv-virtualenv, Anaconda (Miniconda)
[Python] Django environment construction (pyenv + pyenv-virtualenv + Anaconda) for macOS
Python + Anaconda + Pycharm environment construction
python (pyenv + pyenv-virtualenv) + CentOS7 installation
Mechanism of pyenv and virtualenv
Python 2 series and 3 series (Anaconda edition)
Use Anaconda in pyenv environment
[CentOS7] Install anaconda using pyenv
Create a Python (pyenv / virtualenv) development environment on Mac (Homebrew)
Install Python environment with Anaconda
Manage python environment with virtualenv
Use MySQL from Anaconda (python)
Anaconda3 python environment construction procedure
Change python version using pyenv
Version upgrade of python Anaconda
Reinstall python with pyenv with -fPIC
python with pyenv and venv
[Python] virtualenv creation procedure memo
Specify python version with virtualenv
[Python] How to use virtualenv
Change the active version in Pyenv from anaconda to plain Python
How to install python using anaconda
Python memo Anaconda x Jupyter Notebook
Anaconda python environment construction on Windows 10
Anaconda and Python version correspondence table
Introducing Python using pyenv on Ubuntu 20.04
Install Python on Windows + pip + virtualenv
Install scrapy in python anaconda environment
[Note] Setting .bash_profile after installing pyenv
Set python compile options with pyenv
Install Python 3.7 Anaconda on MAC, but Python 2
pyenv-change the python version of virtualenv
Python memo Anaconda installation (Mac only)
Use rospy with virtualenv in Python3
install tensorflow in anaconda + python3.5 environment
Python environment construction (pyenv + poetry + pipx)
Notes on installing Python using PyEnv
Unable to install Python with pyenv
Use Python in pyenv with NeoVim
Install Python on CentOS using Pyenv
Python import directory order (on anaconda)
When using MeCab with virtualenv python
Install Python on CentOS using pyenv
How to install Anaconda with pyenv
Python3.6 environment construction (using Win environment Anaconda)
Use pydoc with Virtualenv / pyenv / venv