pyenv installation on Oracle Linux 6.10

In this post, I am demonstrating how to install pvenv on an Oracle Linux 6.10 and hwo to use pvenv to create a virtual envrionment with a python 3 version which is different than the version 2.6.6 coming with Oracle Linux 6.10.

In one of my prvious posts, I’ve explained different types of Python virtual environment. pyenv is one of them. You can find it on GitHub here. Basically it let you change the global Python version on a per-user basis and provide support for per-project Python versions. It intercepts Python commands using shim executables injected into your PATH, determines which Python version has been specified by your application, and passes your commands along to the correct Python installation.

Steps to install pyenv on Oracle Linux 6.10

  1. install required packages using yum

yum install git gcc zlib-devel bzip2-devel readline-devel sqlite-devel openssl-devel

2. install pyenv under $HOME using git — pyenv & individual python version can be installed under a specific user, not necessarily to be the root user. If the server uses a proxy to reach internet, configure it for git using “git config –global http.proxy <http://proxy>&#8221;. (.gitconfig file under $HOME)

root@test1:~# echo $HOME
/root
root@test1:~# git clone https://github.com/pyenv/pyenv.git $HOME/.pyenv
Initialized empty Git repository in /root/.pyenv/.git/
remote: Enumerating objects: 16, done.
remote: Counting objects: 100% (16/16), done.
remote: Compressing objects: 100% (13/13), done.
remote: Total 17608 (delta 6), reused 7 (delta 3), pack-reused 17592
Receiving objects: 100% (17608/17608), 3.43 MiB | 2.14 MiB/s, done.
Resolving deltas: 100% (11959/11959), done.

3. Edit $HOME/.bashrc to add pyenv into $PATH — adding following lines into .bashrc file

# pyenv configs
export PYENV_ROOT=”$HOME/.pyenv”
export PATH=”$PYENV_ROOT/bin:$PATH”
if command -v pyenv 1>/dev/null 2>&1; then
eval “$(pyenv init -)”
fi

Again, if there is a proxy, need to add the following two lines in .bashrc for the current user

# proxy setting for pyenv
export HTTP_PROXY=http://10.234.22.69:8080
export HTTPS_PROXY=http://10.234.22.69:8080

Now you have pyenv installed and can re-login your shell or source the .bashrc file to get it work.

With pyenv installed, you can check available versions. “*” denotes this is the default version for the current user under this directory.

root@test1:~$ pyenv versions
* system (set by /root/.pyenv/version)
3.6.10
root@test1:~$ python –version
Python 2.6.6

In the example above, the system version is 2.6.6. There is also another version 3.6.10 installed.

If you check the $PATH environmental variable, you could see pyenv adding two paths in front of other paths. So any python related commands will be interpreted by pvenv shim first.

root@test1:~$ echo $PATH
/root/.pyenv/shims:/root/.pyenv/bin:/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/sbin:/root/bin

Using “pyenv install -l” can list all available versions and you can install them using “pyenv install <version number>“. Note not all versions are compatible with your OS environment which means you might have troubles to install certain versions — especially with latest versions.

Once another version is installed, you can specify it as the default version for a project/directory with “pyenv local <version>

root@test1:~/test3610$ pyenv versions
system
* 3.6.10 (set by /root/test3610/.python-version)
root@test1:~/test3610$ pyenv global
system

root@test1:~/test3610$ which pip
~/.pyenv/shims/pip
root@test1:~/test3610$ which python
~/.pyenv/shims/python

You can use pip to install python packages just needed for this project.

Advertisement

One thought on “pyenv installation on Oracle Linux 6.10

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s