Python Forum
Thread Rating:
  • 1 Vote(s) - 5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Part-1]Linux Python 3 environment
#2
Over have looked at using default Python 3 installation that linux Distros has.
Now look Simple Python Version Management: pyenv

Using a new versions of Python is simple with pyenv.
pyenv install 3.6.1 to install newest version.
It's fully automated for both install and virtual environment pyenv virtualenv 3.6.1 env_36
Everything runs as your user,so you don't have to worry about messing up the Python used by linux Distros itself.
Look at a run:
Output:
mint@mint ~ $ pyenv install 3.6.1 Downloading Python-3.6.1.tar.xz... -> https://www.python.org/ftp/python/3.6.1/Python-3.6.1.tar.xz Installing Python-3.6.1... Installed Python-3.6.1 to /home/mint/.pyenv/versions/3.6.1 # Make it default version mint@mint ~ $ pyenv global 3.6.1 mint@mint ~ $ python Python 3.6.1 (default, May 25 2017, 14:44:39) [GCC 5.4.0 20160609] on linux Type "help", "copyright", "credits" or "license" for more information. >>>

Setting up pyenv:
Install headers needed to build CPython:
sudo apt-get install -y build-essential libbz2-dev libssl-dev libreadline-dev libsqlite3-dev tk-dev
Optional scientific package headers(Numpy, Matplotlib, SciPy, etc.)
sudo apt-get install -y libpng-dev libfreetype6-dev

Run the installer script (installs pyenv and some very useful pyenv plugins).
git clone https://github.com/pyenv/pyenv-virtualenv.git $(pyenv root)/plugins/pyenv-virtualenv

Add these 3 lines last in ~/.bashrc
Output:
export PATH="~/.pyenv/bin:$PATH" eval "$(pyenv init -)" eval "$(pyenv virtualenv-init -)"
Example how to add lines:
mint@mint ~ $ nano ~/.bashrc
# paste in lines last 
# Ctrl-O <enter>(save) Ctrl-X
Restart shell.

Setting up environment:
Looked at example run first with pyenv install 3.6.1,
and making it global pyenv global 3.6.1
Here a sample of --list available versions:
Output:
mint@mint ~ $ pyenv install --list Available versions: 3.6.1 3.7-dev anaconda3-4.3.1 miniconda3-4.3.11 ironpython-2.7.7 jython-2.7.1b3 pypy3.5-5.7.1-beta-src pypy3.5-5.7.1-beta pypy3-portable-5.7.0
So as a example want to test out miniconda pyenv install miniconda3-4.3.11

Setting up virtual environment with pyenv 
Output:
mint@mint ~ $ pyenv virtualenv 3.6.1  env_36 # Activate environment mint@mint ~ $ pyenv activate env_36 (env_36) mint@mint ~ $ pip -V pip 9.0.1 from /home/mint/.pyenv/versions/3.6.1/envs/env_36/lib/python3.6/site-packages (python 3.6)
Install into environment:
Output:
(env_36) mint@mint ~ $ pip install requests Collecting requests Installing collected packages: requests Successfully installed requests-2.14.2 # Test that it work (env_36) mint@mint ~ $ python Python 3.6.1 (default, May 25 2017, 14:44:39) [GCC 5.4.0 20160609] on linux Type "help", "copyright", "credits" or "license" for more information. >>> import requests >>> r = requests.get('http://www.python.org') >>> r <Response [200]> >>> r.headers['date'] 'Thu, 25 May 2017 16:59:22 GMT'
Reply


Messages In This Thread
[Part-1]Linux Python 3 environment - by snippsat - May-21-2017, 10:41 PM
RE: [Part-1]Linux Python 3 environment - by snippsat - May-25-2017, 05:14 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  [Part-2]Python environment Windows snippsat 4 25,080 May-24-2017, 10:44 AM
Last Post: metulburr

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020