[PYTHON] I tried using pyenv, which I hated without eating, and it was too convenient to sit down.

** [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. ** **


I hate it without eating it. Zettai.

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 is what

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.

You said you only need vitrualenv

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.

It's a hassle to work on every time! !! !!

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.

pyenv-virtualenv solves everything! !! !!

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

I tried using pyenv, which I hated without eating, and it was too convenient to sit down.
I tried using Google Translate from Python and it was just too easy
I tried to score the syntax that was too humorous and humorous using the COTOHA API.
The tree.plot_tree of scikit-learn was very easy and convenient, so I tried to summarize how to use it easily.
I read "Quantum Computer Accelerates Artificial Intelligence" and tried to outline it in Python without using mathematical formulas.
When I tried to install PIL and matplotlib in a virtualenv environment, I was addicted to it.
I tried to get Web information using "Requests" and "lxml"
I tried to predict the up and down of the closing price of Gurunavi's stock price using TensorFlow (progress)
When I tried to run Python, it was skipped to the Microsoft Store
I tried to convert datetime <-> string with tzinfo using strftime () and strptime ()
I tried to extract and illustrate the stage of the story using COTOHA
I tried to create a sample to access Salesforce using Python and Bottle
I tried image recognition of "Moon and Soft-shelled Turtle" with Pytorch (using torchvision.datasets.ImageFolder which corresponds to from_from_directry of keras)
I tried using Azure Speech to Text.
I tried using Twitter api and Line api
I installed DSX Desktop and tried it
I tried using PyEZ and JSNAPy. Part 2: I tried using PyEZ
I tried to classify text using TensorFlow
I tried to predict Covid-19 using Darts
I tried to notify the update of "Hamelin" using "Beautiful Soup" and "IFTTT"
I tried to use Java with Termux using Termux Arch but it didn't work
[Python] Deep Learning: I tried to implement deep learning (DBN, SDA) without using a library.
Python programming: I tried to get (crawling) news articles using Selenium and BeautifulSoup4.
Three things I was addicted to when using Python and MySQL with Docker
I made an image classification model and tried to move it on mobile
Docker x visualization didn't work and I was addicted to it, so I summarized it!
I tried to use Twitter Scraper on AWS Lambda and it didn't work.
I set up TensowFlow and was addicted to it, so make a note