[PYTHON] Building a virtual environment using homebrew + pyenv-virtualenv

How to create a virtual environment when using homebrew + pyenv-virtualenv. Since it uses homebrew, it is for MacOS.

There are already many similar materials, but I have created my own memos.

Installation and pyenv settings

If you want to install pyenv-virtualenv and its wrapper, you can easily install it by using brew as follows.

% brew install pyenv-virtualenv
% brew install pyenv-virtualenvwrapper

If you are using homebrew-file, do as follows.

% brew file brew install pyenv-virtualenv
% brew file brew install pyenv-virtualenvwrapper

The following cautions will be displayed during installation, so set them later.

To enable shims and autocompletion add to your profile:
if which pyenv > /dev/null; then eval "$(pyenv init -)"; fi

To use Homebrew's directories rather than ~/.pyenv add to your profile:
export PYENV_ROOT=/usr/local/var/pyenv

Set the environment.

% vi .bash_profile

I will add this content.

if which pyenv > /dev/null; then eval "$(pyenv init -)"; fi

Enable the .bash_profile setting.

% source .bash_profile 

Introduce Python using pyenv

Install python using pyenv. Here, I installed Python 3.3.6 as an example.

% pyenv install 3.3.6
Downloading Python-3.3.6.tgz...
-> https://yyuu.github.io/pythons/0a58ad1f1def4ecc90b18b0c410a3a0e1a48cf7692c75d1f83d0af080e5d2034
Installing Python-3.3.6...
(The following is omitted)

% 

If PYENV_ROOT is not set, it will be installed under ~ / .pyenv / shims /.

Creating a virtual environment

Since I installed python3.3.6 earlier, I will use this to create a virtual environment with the name "sandbox336".

% pyenv virtualenv 3.3.6 sandbox336

Tips

List of things that can be installed with pyenv

Check what can be installed with pyenv as follows.

% pyenv install -l

How to install django

If pip uses ~ / .. pyenv / shims / pip, install it with the pip command.

% which pip 
→ pip~/.pyenv/shims/Looking at pip
% pip install django

How to delete the environment

You can uninstall it as you installed it with pyenv.

% pyenv uninstall sandbox336
% pyenv uninstall 3.3.6

Reference material

http://qiita.com/maosanhioro/items/47a52f96fefba7126f9b

Recommended Posts

Building a virtual environment using homebrew + pyenv-virtualenv
Building a Python virtual environment
Building a Python virtual environment
Building a virtual environment with Python 3
[Mac] Building a virtual environment for Python
[Python] Web development preparation (building a virtual environment)
Building a Python environment for pyenv, pyenv-virtualenv, Anaconda (Miniconda)
Build a Django development environment using pyenv-virtualenv on Mac
Building a training environment for penetration testing using Naumachia
Build a Python virtual environment using venv (Django + MySQL ①)
Building and enabling a python virtual environment, etc. (venv)
Memo for building a machine learning environment using Python
Building a Python environment on a Mac and using Jupyter lab
[Python] Building a virtual python environment for the pyramid tutorial (summary)
Building a pyhon environment without using Anaconda (with easy startup)
Building a virtual environment with pyenv-virtualenv/Python (installation, environment settings, packages) Mac environment
Until building a Python development environment using pyenv on Ubuntu 20.04
Building a kubernetes environment with ansible 2
Building a Python environment on Mac
Build a go environment using Docker
Building a Python environment on Ubuntu
Create a virtual environment with Python!
Building a kubernetes environment with ansible 1
Try using virtualenv, which can build a virtual environment for Python
From installing Ansible to building a Python environment in Vagrant's virtual environment
Install Django in a pipenv virtual environment
Building a Python3 environment with Amazon Linux2
Building a LaTeX environment on Chrome OS
Let's create a virtual environment for Python
[Python] Create a virtual environment with Anaconda
pyenv-Building a pypy environment using virtualenv (MacOSX)
Building a Python 3.6 environment with Windows + PowerShell
[Python] Create a Batch environment using AWS-CDK
Creating a python virtual environment on Windows
Create a virtual environment with Python_Mac version
Building scikit-learn in Windows 10 environment using Pycharm
Building a conda environment for ROS users
Build a python virtual environment with pyenv
Creating a virtual environment in an Anaconda environment
I started Node.js in a virtual environment
Building a Python development environment for AI development
Add a Python virtual environment to VSCode
Building a virtual environment for Mayavi dedicated to Python 3.6, Anaconda, Spyder users
How to share a virtual environment [About requirements.txt]
How to create a Python virtual environment (venv)
Ubuntu18.04.05 Creating a python virtual environment in LTS
Building a python environment with virtualenv and direnv
Building a Python environment with WLS2 + Anaconda + PyCharm
Create a virtual environment with conda in Python
Beginner virtual environment
Try using conda virtual environment with Jupyter Notebook
[Memo] Build a virtual environment with Pyenv + anaconda
Build a simple Python virtual environment without pyenv
Build a virtual environment with pyenv and venv
Think about building a Python 3 environment in a Mac environment
[Venv] Create a python virtual environment on Ubuntu
Work in a virtual environment with Python virtualenv.
What to do if you are told "Import Error: cannot import name'HTTPSHandler'" when building a virtual environment using virtualenv
Flow of creating a virtual environment with Anaconda
Building a Python environment on a Sakura VPS server
Create a Python virtual development environment on Windows