Build a simple Python virtual environment without pyenv

Postscript (2018/12/05)

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.

Preface

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.

environment

Execution environment

It's pretty good if you have Homebrew on your Mac.

What to put in now

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.

procedure

Install Python 3.6.1

$ 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.

pip installation

$ brew install pip

Enter with.

$ pip -V
pip 9.0.1 from /usr/local/lib/python2.7/site-packages (python 2.7)

Install virtualenv

$ 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.

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.

Summary

I was able to simply build a virtual environment without using pyenv in Python.

Recommended Posts

Build a simple Python virtual environment without pyenv
Build a python virtual environment with pyenv
[Memo] Build a virtual environment with Pyenv + anaconda
Build a virtual environment with pyenv and venv
Building a Python virtual environment
Build a Python environment offline
Building a Python virtual environment
Build a Python virtual environment that anyone can understand September 2016 (pyenv + virutalenv)
Build a python virtual environment with virtualenv and virtualenvwrapper
Build a Python virtual environment using venv (Django + MySQL ①)
Build a Python environment on your Mac using pyenv
Build a python virtual environment with virtualenv and virtualenvwrapper
Build a Python development environment using pyenv on MacOS
Build python virtual environment with virtualenv
Create a virtual environment with Python!
Building a virtual environment with Python 3
Build a python3 environment on CentOS7
Build a python environment with pyenv (OS X El Capitan 10.11.3)
Build a Python environment with WSL + Pyenv + Jupyter + VS Code
[Pyenv] Building a python environment with ubuntu 16.04
Build a python environment on MacOS (Catallina)
Let's create a virtual environment for Python
I want to build a Python environment
[Mac] Building a virtual environment for Python
Creating a python virtual environment on Windows
Build a Python + OpenCV environment on Cloud9
Build a modern Python environment with Neovim
Add a Python virtual environment to VSCode
Try using virtualenv, which can build a virtual environment for Python
How to manage Python minor version (build virtual environment) on Windows (without Pyenv or WSL)
After buying a new Mac, use pyenv + poetry to build a Python environment.
Ubuntu18.04.05 Creating a python virtual environment in LTS
Build python environment with pyenv on EC2 (ubuntu)
Build a python environment with ansible on centos6
Build a Python environment on Mac (Mountain Lion)
Create a virtual environment with conda in Python
[Python] Build a Django development environment with Docker
python virtual environment Pipenv
Build a Python development environment on your Mac
[Python] Web development preparation (building a virtual environment)
virtual environment in python
[Venv] Create a python virtual environment on Ubuntu
Work in a virtual environment with Python virtualenv.
Build a Python environment with OSX El capitan
Create a Python environment
Quickly build a Python Django environment with IntelliJ
Virtual environment with Python 3.6
Create a Python virtual development environment on Windows
Build a Python machine learning environment with a container
Build a Python development environment on Raspberry Pi
Build a python execution environment with VS Code
pyenv, virtualenv Use docker to manage the environment without using
Build a simple Python virtual environment without pyenv
Build a GVim-based Python development environment on Windows 10 (3) GVim8.0 & Python3.6
Building a Python environment for pyenv, pyenv-virtualenv, Anaconda (Miniconda)
How to set up a Python environment using pyenv
# 2 Build a Python environment on AWS EC2 instance (ubuntu18.04)
Create a virtual environment with Anaconda installed via Pyenv
Build a machine learning Python environment on Mac OS
Build a GVim-based Python development environment on Windows 10 (1) Installation
How to build a Django (python) environment on docker
Build a Python development environment on Mac OS X