--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.
`pyenv`
anyenv
By using, it will end immediately.
(For `pyenv`
alone, write PATH to Shell profile.)
$ anyenv install pyenv
shell
Refresh the environment.
$ exec $SHELL -l
pyenv -v
sopyenv
If the version of is displayed, it is installed.
$ pyenv -v
pyenv 1.1.3-5-g7dae197
pyenv
Is a plug-in ofpyenv-virtualenv
To 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
.
pyenv
Usingpython
Install.
Basically, I use `Python3```, so I will build the
`Python3environment. We will also use
Anaconda``` 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.
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.
python
If 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)
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.
conda
Check 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 versions
You 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)
`pyenv deactivate``` to deactivate
`pyenv activate```pyenv local (VERSION NAME)` `` with
pyenv local --unset```Enjoy!
Recommended Posts