A story of trying out pyenv, virtualenv and virtualenvwrapper

Until now, the Python environment was handled by pyenv, but I often hear it, so I tried using virtualenv. At the same time, install virtualenvwrapper.

Pre-environment

Like this

$ pyenv versions 
  system
* 3.5.2 (set by /Users/hikaru/.pyenv/version)

Installation

Install in the environment of python 3.5.2.

$ pyenv version
3.5.2 (set by /Users/hikaru/.pyenv/version)
$ pip install virtualenv virtualenvwrapper

setup

Write the following in .bashrc

export WORKON_HOME=$HOME/.virtualenvs
source $PYENV_ROOT/versions/3.5.2/bin/virtualenvwrapper.sh

Execute the following command.

$ mkdir ~/.virtualenvs
$ source ~/.bashrc

I was addicted to the location of the source virtualenvwrapper.sh. There is also a file called $ HOME / .pyenv / shims / virtualenvwrapper.sh, but this is different from the one above. Or rather, when I sourced this, the terminal was exited.

move

Building the environment

$ mkvirtualenv django
Using base prefix '/Users/hikaru/.pyenv/versions/3.5.2'
New python executable in /Users/hikaru/.virtualenvs/django/bin/python3.5
Also creating executable in /Users/hikaru/.virtualenvs/django/bin/python
Installing setuptools, pip, wheel...done.
virtualenvwrapper.user_scripts creating /Users/hikaru/.virtualenvs/django/bin/predeactivate
virtualenvwrapper.user_scripts creating /Users/hikaru/.virtualenvs/django/bin/postdeactivate
virtualenvwrapper.user_scripts creating /Users/hikaru/.virtualenvs/django/bin/preactivate
virtualenvwrapper.user_scripts creating /Users/hikaru/.virtualenvs/django/bin/postactivate
virtualenvwrapper.user_scripts creating /Users/hikaru/.virtualenvs/django/bin/get_env_details
(django) $ pip list -l --format=columns
Package    Version
---------- -------
appdirs    1.4.3  
packaging  16.8   
pip        9.0.1  
pyparsing  2.2.0  
setuptools 35.0.2 
six        1.10.0 
wheel      0.29.0 

With this feeling, an environment called django was created. Only the minimum required packages are included.

Exit the environment

(django)$ deactivate
$

You can enter each environment by displaying the environment list with the workon command and selecting the environment as an option.

$ workon 
django
$ workon django
(django) $

Delete environment

$ rmvirtualenv django
Removing django...
$ 

Environment construction by specifying Python

When I ran mkvirtualenv under python3.5.2, I got python3.5.2 environment, but I can explicitly use other python.

$ mkvirtualenv --python=/usr/bin/python2.7 django
Running virtualenv with interpreter /usr/bin/python2.7
New python executable in /Users/hikaru/.virtualenvs/django/bin/python
Installing setuptools, pip, wheel...done.
virtualenvwrapper.user_scripts creating /Users/hikaru/.virtualenvs/django/bin/predeactivate
virtualenvwrapper.user_scripts creating /Users/hikaru/.virtualenvs/django/bin/postdeactivate
virtualenvwrapper.user_scripts creating /Users/hikaru/.virtualenvs/django/bin/preactivate
virtualenvwrapper.user_scripts creating /Users/hikaru/.virtualenvs/django/bin/postactivate
virtualenvwrapper.user_scripts creating /Users/hikaru/.virtualenvs/django/bin/get_env_details
(django) $ python --version
Python 2.7.10
(django) $ 

Python 2.7.10 is working properly.

Summary

If you don't need to manage packages for each version of python, you probably don't need virtualenv. On the other hand, if there are packages that adversely affect each other or if detailed version specification is required, It seems better to turn off the environment with virtualenv.

Recommended Posts

A story of trying out pyenv, virtualenv and virtualenvwrapper
Mechanism of pyenv and virtualenv
The story of trying deep3d and losing
python development environment -use of pyenv and virtualenv-
Build a python virtual environment with virtualenv and virtualenvwrapper
Build a python virtual environment with virtualenv and virtualenvwrapper
A story of trial and error trying to create a dynamic user group in Slack
Coexistence of pyenv and autojump
Story of trying competitive programming 2
Story of trying competitive programming Part 1
The story of writing a program
A story about trying to run JavaScripthon on Windows and giving up.
A story of a deep learning beginner trying to classify guitars on CNN
A story about trying to connect to MySQL using Heroku and giving up
The story of making a sound camera with Touch Designer and ReSpeaker
The story of trying to reconnect the client
A story connecting Slack and google spreadsheets
A rough understanding of python-fire and a memo
A little scrutiny of pandas 1.0 and dask
Connect a lot of Python or and and
A story about Python pop and append
The story of blackjack A processing (python)
A story about trying to install uwsgi on an EC2 instance and failing
The story of making a box that interconnects Pepper's AL Memory and MQTT
A story of a high school graduate technician trying to predict the survival of the Titanic
Python3 TensorFlow environment construction (Mac and pyenv virtualenv)
Building a python environment with virtualenv and direnv
A memorandum of studying and implementing deep learning
A story about Go's global variables and scope
A note about the python version of python virtualenv
The story of making a lie news generator
Story of trying to use tensorboard with pytorch
Build a virtual environment with pyenv and venv
The story of trying Sourcetrail × macOS × VS Code
A story of creating 16 * 16 dots from a Digimon photo
The story of making a mel icon generator
A story about modifying Python and adding functions
[Python] A rough understanding of iterators, iterators, and generators
A discussion of the strengths and weaknesses of Python
The story of Airflow's webserver and DAG, which takes a long time to load
I can't find the clocksource tsc! ?? The story of trying to write a kernel patch
The story of trying to contribute to COVID-19 analysis with AWS free tier and failing
The real cause of the Jubatus client spitting out a timeout and dropping an error
A story about trying to introduce Linter in the middle of a Python (Flask) project
Find out who is a favorite user of Hatena Bookmark and is not already active