It's been over a year since I wrote this article. Recently, using Pipenv has become the easiest way to build an environment. For those who can start Python from now on, it is recommended to specify the Python version with "pipenv + pyenv" and prepare a development platform that divides the virtual environment by directory.
There are various ways to build a Python environment, and you don't know when it's the first time to build an environment. However, the default python is 2.7, and if you put various packages in it with pip, it will be messed up, and you want something that can be divided into environments.
In the meantime, after touching Python for about half a year, building the environment and repeatedly destroying it, I came up with the method of "Is it the simplest?"
However, since it does not use pyenv, version control is not possible. Only python2.7, which is installed as standard, or python3.6, which will be installed from now on, will be selected. After using it for about half a year, I haven't encountered any packages that do not support python3.6, so I think there is no problem other than using it for special purposes.
It's pretty good if you have Homebrew on your Mac.
pip is a Python package management system that allows you to install packages and more. virtualenv is a package that allows you to create an independent environment for Python and can be installed with pip.
$ brew install python3
Contains python3.6.1. (As of June 30, 2017)
$ python -V
Python 2.7.13
$ python3 -V
Python 3.6.1
$ python3.6 -V
Python 3.6.1
It turned out to be something like this.
$ brew install pip
Enter with.
$ pip -V
pip 9.0.1 from /usr/local/lib/python2.7/site-packages (python 2.7)
$ pip install virtualenv
...
$ virtualenv --version
15.1.0
This is the end of the installation itself. From here, we will start building a virtual environment.
When you create a virtual environment, one directory is created, so move to the directory where you want to create a virtual environment in advance.
$ mkdir sandbox
$ cd sandbox
$ virtualenv environment name -p Python interpreter
You can build a virtual environment by specifying the Python version.
$ virtualenv testenv -p python3
...
$ ls
testenv
A directory with the specified name (testenv) has been created.
To enter the virtual environment
$ source environment name / bin / activate
Type in.
$ source testenv/bin/activate #Enter the virtual environment
(testenv) $ pip freeze #No packages installed
(testenv) $ python -V #Python version 3.6.To 1
Python 3.6.1
(testenv) $ deactivate #Exit the virtual environment
$
(Environment name) $
Is displayed, you have successfully entered the virtual environment.
If you try $ pip freeze
, you can see that virtualenv is not included.
You can see that the environment is python3.6.1 with $ python -V
.
I was able to simply build a virtual environment without using pyenv in Python.
Recommended Posts