pyenv

Post tags: | pyenv | python |

In the case of Ruby git,rbenv and bundler are the keys to project management. Looking for the Python keys. Looking at git, pyenv, virtualenv.

github.com/yyuu/pyenv

Simple Python Version Management: pyenv

pyenv lets you easily switch between multiple versions of Python. It’s simple, unobtrusive, and follows the UNIX tradition of single-purpose tools that do one thing well.

This project was forked from rbenv and ruby-build, and modified for Python.

github.com/pyenv Simple Python version management

        git clone https://github.com/pyenv/pyenv.git ~/.pyenv
        
        cd ~/.pyenv
        git pull
        

github.com/pyenv/ pyenv Command Reference

        pyenv install --list
        pyenv install 3.8.0
        
        cd ~craig/dev/scourby-king-james
        pyenv local 3.8.0
        
        pip install beautifulsoup4
        
        pip install --upgrade pip
        
        

dabapps.com/blog article Pip and Virtualenv for Python beginners

Jamie Matthews - A non-magical introduction to Pip and Virtualenv for Python beginners

One of the hurdles that new Python developers have to get over is understanding the Python packaging ecosystem. This blog post is based on material covered in our Python for Programmers training course, which attempts to explain pip and virtualenv for new Python users.

How does virtualenv help?

virtualenv solves this problem by creating a completely isolated virtual environment for each of your programs. An environment is simply a directory that contains a complete copy of everything needed to run a Python program, including a copy of the python binary itself, a copy of the entire Python standard library, a copy of the pip installer, and (crucially) a copy of the site-packages directory mentioned above. When you install a package from PyPI using the copy of pip that’s created by the virtualenv tool, it will install the package into the site-packages directory inside the virtualenv directory. You can then use it in your program just as before.

How can I install virtualenv?

In fact, virtualenv comes with a copy of pip which gets copied into every new environment you create, so virtualenv is really all you need. You can even install it as a separate standalone package (rather than from PyPI). This might be easier for Windows users. See virtualenv.org for instructions.

spin.atomicobject.com article Python Environment Management for Rubyists – a Guide by Mitchell Johnson

github.com/yyuu/pyenv

github.com/yyuu/pyenv-installer

github.com/yyuu/pyenv-virtualenv

dabapps.com/what-we-do article

Python For Programmers - a one-day workshop

Python’s simplicity and elegance is at the heart of our software strategy, and we love sharing our knowledge with the wider programming community.

dabapps.com/who-we-are

DabApps is an established member of the digital community in Brighton.

Our core business is designing and building custom applications to help businesses succeed and grow. As well as building an impressive client base we have formed a number effective partnerships with other digital agencies providing the technical resource they lack in house. In addition to this, with a number of specialist programming skills to our name, we also offer a technical consultancy service.

We have a strong team of designers and developers led by co-founders Chris Palk (MD), Caroline Pickering (Creative Director) and Jamie Matthews (Technical Director).

pyenv / virtualenv try 1

Show python versions on system

        python --version
        Python 2.7.9
        
        which python
        /usr/bin/python
        
        python3 --version
        Python 3.4.2
        
        which python3
        /usr/bin/python3
        

run pyenv-installer

        curl -L https://raw.githubusercontent.com/yyuu/pyenv-installer/master/bin/pyenv-installer | bash
         ...
        Cloning into '/home/craig/.pyenv'...
         ...
        WARNING: seems you still have not added 'pyenv' to the load path.
        
         Load pyenv automatically by adding
         the following to ~/.zshrc:
        
        export PATH="/home/craig/.pyenv/bin:$PATH"
        eval "$(pyenv init -)"
        eval "$(pyenv virtualenv-init -)"
         ...
        

Install local pythons

        pyenv install --list
         ...
          2.7.12
         ...
          3.5.2
         ...
        
        pyenv install 2.7.12
        
        pyenv install 3.5.2
        
          Downloading Python-3.5.2.tar.xz...
          -> https://www.python.org/ftp/python/3.5.2/Python-3.5.2.tar.xz
          Installing Python-3.5.2...
          WARNING: The Python bz2 extension was not compiled. Missing the bzip2 lib?
          Installed Python-3.5.2 to /home/craig/.pyenv/versions/3.5.2
        
        

Python’s bz2 module not compiled by default

stackoverflow.com/questions Python’s bz2 module not compiled by default

        option 2. build and install bzip2
        
        In the README file of bzip2 package, it is explained that under certain platforms, namely those which employ Linux-ELF binaries, you have to build an additional shared object file like shown below:
        
        wget http://bzip.org/1.0.6/bzip2-1.0.6.tar.gz
        tar xpzf bzip2-1.0.6.tar.gz
        cd bzip2-1.0.6
        make
        make -f Makefile-libbz2_so
        make install PREFIX=/path/to/local # /usr/local by default
        
        The critical bit here is the following command:
        
        make -f Makefile-libbz2_so
        
        I've done this and after that tried to build Python again, like shown below:
        
        cd Python-2.7.3
        ./configure --prefix=/path/to/local 
        make install
        

Build bzip2 from source

bzip.org

Here is the 1.0.6 source tarball , which includes full documentation. md5: 00b516f4704d4a7cb50a1d97e6e8e15b

        make
         ...
        make distclean # tests are successful.
         ...
        make -f Makefile-libbz2_so
         ...
        sudo checkinstall
         ...
         Done. The new package has been installed and saved to
        
         /home/craig/dev/bzip2/bzip2-1.0.6/bzip2_1.0.6-1_amd64.deb
        
         You can remove it from your system anytime using: 
        
              dpkg -r bzip2
        

Install pythons again

        cd /home/craig/.pyenv/versions
        rm -rf 2.7.12 3.5.2
        
        pyenv install 2.7.12
        Downloading Python-2.7.12.tar.xz...
        -> https://www.python.org/ftp/python/2.7.12/Python-2.7.12.tar.xz
        Installing Python-2.7.12...
        Installed Python-2.7.12 to /home/craig/.pyenv/versions/2.7.12
        
        pyenv install 3.5.2
        Downloading Python-3.5.2.tar.xz...
        -> https://www.python.org/ftp/python/3.5.2/Python-3.5.2.tar.xz
        Installing Python-3.5.2...
        Installed Python-3.5.2 to /home/craig/.pyenv/versions/3.5.2
        

Success this time

Create a virtualenv

Note virtualenv and venv

There is a venv module available for CPython 3.3 and newer. It provides an executable module venv which is the successor of virtualenv and distributed by default.

pyenv-virtualenv uses python -m venv if it is available and the virtualenv command is not available.

craig not sure how to install virtualenv on CPython before 3.3

3/library/venv.html New in version 3.3. venv — Creation of virtual environments

and build a pyenv with 3.5.2 and venv

        pyenv versions
          2.7.12
          3.5.2
        
        pyenv virtualenv 3.5.2 py1
        
        ls ~/.pyenv/versions/py1
        
        pyenv versions
          2.7.12
          3.5.2
          3.5.2/envs/py1
          py1
        
        pyenv virtualenvs
        
        mkdir --parents ~/dev/python/py1
        cd ~/dev/python/py1
        pyenv local py1
        
        py1  pyenv version
        py1 (set by /home/craig/dev/python/py1/.python-version)
        
        git init .
        git add .
        git commit -m 'Starting. using pyvenv py1'