** [Addition] This article was written in 2014, and its content is currently of no value other than its historical significance. If you want to start Python from now on, if you don't use venv in Python3, you will be beaten by scary people, so let's do so. ** **
http://qiita.com/who_you_me/items/1d37d964c1459b9625fa#1-2
When I wrote an article about the Python development environment in the past, I said "pyenv? I don't have a need to switch Python versions (゜ ⊿ ゜) Iran", but this was a big mistake. We apologize for the correction.
pyenv lets you easily switch between multiple versions of Python.
https://github.com/yyuu/pyenv
A tool that allows you to easily switch between Python versions. In short, it is the same as rbenv, you can install multiple versions of Python and specify the version to use for each directory.
Yes, I did say so. In my way of dealing with Python, I wanted to use the 2nd system and the 3rd system properly, and I thought that it was a virtualenv. Reference: http://qiita.com/who_you_me/items/543a901a827e93401db1
However, while virtualenv (+ virtualenvwrapper) is certainly a revolutionary useful tool, it has one very embarrassing problem.
This. Moreover, in my case, for some reason, I couldn't enter work on
in one shot, and I typed wokorn
or wokron
, and I had to retype it several times.
There is talk of setting an alias, but since the virtual environment you want to use is the same for each directory, you want to automatically work on
when you jump to a certain directory.
It may be possible to do my best with .bashrc, but it seems to be quite troublesome.
There was a super useful plugin in pyenv.
https://github.com/yyuu/pyenv-virtualenv
When installed, the pyenv virtualenv
command is added to pyenv.
With this, the virtual environment created by virtualenv is added to the Python version that can be specified by pyenv.
$ pyenv virtualenv 3.4.2 django
$ pyenv versions
* system
2.7.8
3.4.2
django
What happens if you set this virtual environment to pyenv local
?
Yes, you can automatically enter the virtual environment created by virtualenv just by moving to the specified directory! !!
$ mkdir mydjangoproject
$ cd mydjangoproject
$ pyenv local django
$ pip install django
$ pip freeze
Django==1.7.1
$ cd ..
$ pyenv local
system
$ pip freeze
argparse==1.2.1
six==1.8.0
stevedore==1.0.0
virtualenv==1.11.6
virtualenv-clone==0.2.5
virtualenvwrapper==4.3
#Another environment! !!
$ cd mydjangoproject
$ pip freeze
Django==1.7.1
#Just cd into the django environment! !!
Of course, if you want to start another django project, just create a directory (if the Python version is the same) and do pyenv local django
.
Now you don't have to hit work on
. I'm embarrassed to hate myself without eating.
Recommended Posts