DarkMatter in Cyberspace
  • Home
  • Categories
  • Tags
  • Archives

Manage Python Versions with Pyenv


pyenv is python equivalent of rvm of ruby. It can replace the virtualenvwrapper, and there's no need to install virtualenv before pyenv. It will install virtualenv automatically.

On ArchLinux, you just install it according its documents on the website:

$ curl -L https://raw.githubusercontent.com/yyuu/pyenv-installer/master/bin/pyenv-installer | bash

But on Mint 17, you have to install libraries beforehand:

$ sudo apt-get install make build-essential libssl-dev zlib1g-dev libbz2-dev libreadline-dev libsqlite3-dev wget curl

Then run "curl ..." to install it.

Then add "export ... eval ..." into ~/.zshrc according to its prompt at the end of the installation.

Usage

$ pyenv commands         // list all available commands
$ pyenv install -l       // list all available versions to install
$ pyenv install 2.6.6
$ pyenv rehash           // run this command after install a new version
$ pyenv versions         // list all installed versions
$ pyenv shell 2.6.6      // set python version to 2.6.6 in this session (shell)
$ pyenv local 2.6.6      // create a .python-version file under CWD, it will use 2.6.6 afterwards according to this file
$ pyenv shell system     // go back to use the system python version
$ pyevn which python     // check the python path in current environment
$ pyenv uninstall 2.6.6

No Special Package Nedded

If your python project need no special dependency packages, use pyenv local 2.6.6 is a good idea. It only create a .python-version under the folder. Very clean.

Need Install Package

If your project need some package, which you don't want to put into system environment, use

$ pyenv virtualenv 2.6.6 myproj

Now you have a INDEPENDENT python environment based on 2.6.6. You can verify this by run:

$ cd myproj
$ pyenv activate myproj
$ pyenv which python
/home/chad/.pyenv/versions/myproj/bin/python
$ pyenv deactivate

Fabric on ArchLinux

Fabric uses library paramiko, which is incompatible with Python 3.x. After fabric installed on ArchLinux with pip, when you run fab test, a "cannot import name isMappingType" error occurs. So we need install a Python 2.7, then install fabric based on it:

pyenv install 2.7.8
pyenv shell 2.7.8
pip install fabric

Now create a test fabfile.py:

def test():
    print("hello world")

And run it: fab test.

In a new shell, run fabric with pyenv shell 2.7.8; fab test.



Published

Aug 6, 2014

Last Updated

Aug 6, 2014

Category

Tech

Tags

  • pyenv 1
  • python 136
  • rvm 2
  • version 3

Contact

  • Powered by Pelican. Theme: Elegant by Talha Mansoor