Virtual Environment Version Control Summary Python

Overview

Python is not compatible with 2 series and 3 series respectively. There are two versions on the market because of this relationship.

Because there was a slide that introduced the method of virtual environment management in an easy-to-understand manner I borrowed the contents of that slide and added the contents of the virtualenv that I mainly use. If you want to know more, please refer to the references.

pyenv-virtualenv can be set for each directory, and unlike vitalenv, it does not need to be activated at the time of use, so it is the most recommended.

Virtual environment introduction

virtualenv -A tool that allows you to switch between libraries used in the same version of Python. ・ Can be installed with pip ・ Can be used on Windows vertualenv.png <Citation: [Machine Learning Nagoya_7th Study Group_Python Environment Construction Method.key](https://speakerd.s3.amazonaws.com/presentations/0d969d6526dd4b5fa0549f4e3481745f/%E6%A9%9F%E6%A2%B0 % E5% AD% A6% E7% BF% 92% E5% 90% 8D% E5% 8F% A4% E5% B1% 8B_% E7% AC% AC7% E5% 9B% 9E% E5% 8B% 89% E5 % BC% B7% E4% BC% 9A_Python% E7% 92% B0% E5% A2% 83% E6% A7% 8B% E7% AF% 89% E6% 96% B9% E6% B3% 95_20161015.pdf)> pyenv -Tools for managing various Python versions ・ You can switch between Python 2 and 3 -Python to be used in shell and directory can be specified -You cannot switch libraries with the same version of Python. ・ Cannot be used on Windows pyenv.png <Citation: [Machine Learning Nagoya_7th Study Group_Python Environment Construction Method.key](https://speakerd.s3.amazonaws.com/presentations/0d969d6526dd4b5fa0549f4e3481745f/%E6%A9%9F%E6%A2%B0 % E5% AD% A6% E7% BF% 92% E5% 90% 8D% E5% 8F% A4% E5% B1% 8B_% E7% AC% AC7% E5% 9B% 9E% E5% 8B% 89% E5 % BC% B7% E4% BC% 9A_Python% E7% 92% B0% E5% A2% 83% E6% A7% 8B% E7% AF% 89% E6% 96% B9% E6% B3% 95_20161015.pdf)> pyenv-virtualenv -A tool that allows you to switch libraries with the same version of Python with pyenv. ・ The author is the same as pyenv ・ Cannot be used on Windows pyenv-virtualenv.png <Citation: [Machine Learning Nagoya_7th Study Group_Python Environment Construction Method.key](https://speakerd.s3.amazonaws.com/presentations/0d969d6526dd4b5fa0549f4e3481745f/%E6%A9%9F%E6%A2%B0 % E5% AD% A6% E7% BF% 92% E5% 90% 8D% E5% 8F% A4% E5% B1% 8B_% E7% AC% AC7% E5% 9B% 9E% E5% 8B% 89% E5 % BC% B7% E4% BC% 9A_Python% E7% 92% B0% E5% A2% 83% E6% A7% 8B% E7% AF% 89% E6% 96% B9% E6% B3% 95_20161015.pdf)>

Installation / use

I've also introduced how to install Linux and Windows. Since the amount of sentences will be large, I will omit it only for Mac.

virtualenv

Installation

Installation


$ pip install virtualenv

Create virtual environment


$ virtualenv -p [Python version] [Virtual environment name]

#Example
$ virtualenv -p 3.5 python3.5

use

use


$ source [Virtual environment name]/bin/activate

#Example
source python3.5/bin/activate

If successful, the terminal display will be displayed.

(python3.5)$


 Should have changed.



#### **`End`**
```shell

$ deactivate

If you want to delete the environment, you can delete the created directory.

pyenv-virtualenv

Installation

Installation


$ brew install pyenv-virtualenv

Environment variable settings(For bash, the default is bash)


$ echo 'export PYENV_ROOT="/usr/local/var/pyenv"' >> ~/.bash_profile
$ echo 'if which pyenv > /dev/null; then eval "$(pyenv init -)"; fi' >> ~/.bash_profile
$ echo 'if which pyenv-virtualenv-init > /dev/null; then eval "$(pyenv virtualenv-init -)"; fi' >> ~/.bash_profile
$ source ~/.bash_profile

If you use a shell other than bash, please change the **. Bash_profile ** part.

Environment variable settings(For zsh)


$ echo 'export PYENV_ROOT="/usr/local/var/pyenv"' >> ~/.zshrc
$ echo 'if which pyenv > /dev/null; then eval "$(pyenv init -)"; fi' >> ~/.zshrc
$ echo 'if which pyenv-virtualenv-init > /dev/null; then eval "$(pyenv virtualenv-init -)"; fi' >> ~/.zshrc
$ source ~/.zshrc

Python installation


pyenv install [Python version]

Create virtual environment


$ pyenv virtualenv [Python version] [Virtual environment name]

#Example
$ pyenv virtualenv 2.7.11 Py2Base
$ pyenv virtualenv Py2Base py2-test 

If you create a new virtual environment from the virtual environment, it seems that the library etc. will be inherited.

use

Change Python used as standard


$ pyenv global [Virtual environment name]

Change Python in the current shell


$  pyenv shell [Virtual environment name]

Change Python in the current directory


$ pyenv local [Virtual environment name]

Delete virtual environment


$ pyenv unisntall [Virtual environment name]

References

[Machine learning Nagoya_7th study session_Python environment construction method.key](https://speakerd.s3.amazonaws.com/presentations/0d969d6526dd4b5fa0549f4e3481745f/%E6%A9%9F%E6%A2%B0%E5% AD% A6% E7% BF% 92% E5% 90% 8D% E5% 8F% A4% E5% B1% 8B_% E7% AC% AC7% E5% 9B% 9E% E5% 8B% 89% E5% BC% B7% E4% BC% 9A_Python% E7% 92% B0% E5% A2% 83% E6% A7% 8B% E7% AF% 89% E6% 96% B9% E6% B3% 95_20161015.pdf)

Recommended Posts

Virtual Environment Version Control Summary Python
About the virtual environment of python version 3.7
python virtual environment Pipenv
virtual environment in python
Virtual environment with Python 3.6
Building a Python virtual environment
venv: Python virtual environment management
python standard virtual environment venv
Building a Python virtual environment
Python Summary
Build python virtual environment with virtualenv
[Personal memo] Python virtual environment command memo
Create a virtual environment with Python!
Python summary
Building a virtual environment with Python 3
[Python] Building a virtual python environment for the pyramid tutorial (summary)
Python virtual environment and packages on Ubuntu
Let's create a virtual environment for Python
[Python] Create a virtual environment with Anaconda
[Mac] Building a virtual environment for Python
Creating a python virtual environment on Windows
Create a virtual environment with Python_Mac version
Build a python virtual environment with pyenv
Add a Python virtual environment to VSCode
Python environment construction
python environment settings
Python tutorial summary
python windows environment
Environment construction (python)
Beginner virtual environment
Build a version control environment for Python, Ruby, Perl, Node.js on UNIX
python environment construction
Python --Environment construction
Python virtual environment construction (2017 version) pyenv and pyenv-virtualenv and virtualenv and virtualenv wrapper and pyvenv and venv
Install Python Control
Python environment construction
python related summary
PYTHON2.7 64bit version
python environment construction
Python basics summary
How to create a Python virtual environment (venv)
Ubuntu18.04.05 Creating a python virtual environment in LTS
Python environment construction (Anaconda + VSCode) @ Windows10 [January 2020 version]
Python (Windows 10) Virtual Environment / Package with VS Code
Create a virtual environment with conda in Python
Manage Python multiple version environment with Pythonz, virtualenv
Installation of Python3 and Flask [Environment construction summary]
[Python] Web development preparation (building a virtual environment)
Build a simple Python virtual environment without pyenv
[Venv] Create a python virtual environment on Ubuntu
[Node-RED] Execute Python on Anaconda virtual environment from Node-RED [Anaconda] [Python]
Work in a virtual environment with Python virtualenv.
Use jupyter-lab installed in python virtual environment (venv)
[Django3] Environment construction and various settings summary [Python3]
Kernel / Python version summary for each Debian release
From Python environment construction to virtual environment construction with anaconda
Create a Python virtual development environment on Windows
Virtual environment construction with Docker + Flask (Python) + Jupyter notebook
Summary about Python scraping
[Python] Get environment variables
My python environment memo