I made a Python3 environment on Ubuntu with direnv.

I heard that it is easy to build a Python environment using direnv, so I created a 3rd system environment on Ubuntu. It's from putting the Ubuntu 14.04 box in Vagrant.

Upload Vagrant with ubuntu box

Get a box

vagrant box add ubuntu-14.04 https://cloud-images.ubuntu.com/vagrant/trusty/current/trusty-server-cloudimg-amd64-vagrant-disk1.box
vagrant init ubuntu-14.04
vagrant up

Log in to vagrant

vagrant ssh

Install the package on Ubuntu

Package update


sudo apt-get update

Put pip and pythonz

Install pip and pythonz.

Install pip and pythonz


sudo apt-get install build-essential zlib1g-dev libbz2-dev libssl-dev libreadline-dev libncurses5-dev libsqlite3-dev libgdbm-dev libdb-dev libexpat-dev libpcap-dev liblzma-dev libpcre3-dev curl python-pip
curl -kL https://raw.github.com/saghul/pythonz/master/pythonz-install | bash
echo '[[ -s $HOME/.pythonz/etc/bashrc ]] && source $HOME/.pythonz/etc/bashrc' >> $HOME/.bashrc
exec $SHELL

Insert virtualenv

sudo pip install virtualenv
Downloading/unpacking virtualenv
  Downloading virtualenv-13.1.2-py2.py3-none-any.whl (1.7MB): 1.7MB downloaded
Installing collected packages: virtualenv
Successfully installed virtualenv
Cleaning up...

Insert direnv

curl -L -o direnv https://github.com/zimbatm/direnv/releases/download/v2.5.0/direnv.linux-amd64
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   142    0   142    0     0     22      0 --:--:--  0:00:06 --:--:--    37
  0     0    0   602    0     0     93      0 --:--:--  0:00:06 --:--:--    93
100 3579k  100 3579k    0     0   236k      0  0:00:15  0:00:15 --:--:--  865k
sudo install direnv /usr/local/bin
echo 'type direnv > /dev/null 2>&1 && eval "$(direnv hook bash)" ' >> $HOME/.bashrc
exec $SHELL
pythonz list -a
Abbreviation
     2.7.8
     2.7.9
     2.7.10
     3.0
     3.0.1
     3.1
Abbreviation

It seems that 2.7.6 series is included by default.

python -V
Python 2.7.6

Install python3 series

pythonz install 3.4.3

Downloading Python-3.4.3.tgz as /home/vagrant/.pythonz/dists/Python-3.4.3.tgz
########################################################################## 100%
Extracting Python-3.4.3.tgz into /home/vagrant/.pythonz/build/CPython-3.4.3

This could take a while. You can run the following command on another shell to track the status:
  tail -f /home/vagrant/.pythonz/log/build.log

Installing CPython-3.4.3 into /home/vagrant/.pythonz/pythons/CPython-3.4.3

Installed CPython-3.4.3 successfully.
pythonz locate 3.4.3
/home/vagrant/.pythonz/pythons/CPython-3.4.3/bin/python3
pip -V
pip 1.5.4 from /usr/lib/python2.7/dist-packages (python 2.7)

Specify the directory to use Python3

pwd
/home/vagrant

Make python3.4.3 available in the directory / home / vagrant / sand_box.

sand_Set to use python in box directory


echo 'layout python $(pythonz locate 3.4.3)' > sand_box/.envrc
direnv allow sand_box

Once through Vagrant

exit

Re-enter Vagrant

vagrant ssh

Maybe you don't need this logout procedure?

OK if Python3 package is installed

If you move to the directory sand_box here, the installation will start automatically.

cd sand_box
direnv: loading .envrc
Running virtualenv with interpreter /home/vagrant/.pythonz/pythons/CPython-3.4.3/bin/python3
Using base prefix '/home/vagrant/.pythonz/pythons/CPython-3.4.3'
New python executable in /home/vagrant/sand_box/.direnv/python-3.4.3/bin/python3
Also creating executable in /home/vagrant/sand_box/.direnv/python-3.4.3/bin/python
Installing setuptools, pip, wheel...done.
direnv: export +VIRTUAL_ENV ~PATH

Try putting a Pretty Table

pip install PrettyTable
Collecting PrettyTable
  Downloading prettytable-0.7.2.tar.bz2
Building wheels for collected packages: PrettyTable
  Running setup.py bdist_wheel for PrettyTable
  Stored in directory: /home/vagrant/.cache/pip/wheels/41/46/ec/ec86e65e50e9f4be52547a3bedd46077e7414c53d2ed0418fd
Successfully built PrettyTable
Installing collected packages: PrettyTable
Successfully installed PrettyTable-0.7.2

I entered normally. If pip isn't called correctly via 3.4.3, it won't work.

Check if Python3 system is used

python -V
Python 3.4.3

In addition to the following, create other directories

I created a directory called / var / www / sand_box and put other versions of Python in it.

sudo mkdir /var/www
sudo chown vagrant:vagrant /var/www

Before moving to the directory, it is Python2 series.

python -V
Python 2.7.6

pythonz install 3.2.4
Downloading Python-3.2.4.tgz as /home/vagrant/.pythonz/dists/Python-3.2.4.tgz
########################################################################## 100%
Extracting Python-3.2.4.tgz into /home/vagrant/.pythonz/build/CPython-3.2.4

This could take a while. You can run the following command on another shell to track the status:
  tail -f /home/vagrant/.pythonz/log/build.log

Installing CPython-3.2.4 into /home/vagrant/.pythonz/pythons/CPython-3.2.4

Installed CPython-3.2.4 successfully.
mkdir sand_box

If you go to / var / www / sand_box, the 3.2.4 series files will be installed.

cd sand_box/
direnv: loading .envrc
Running virtualenv with interpreter /home/vagrant/.pythonz/pythons/CPython-3.2.4/bin/python3
New python executable in /var/www/sand_box/.direnv/python-3.2.4/bin/python3
Also creating executable in /var/www/sand_box/.direnv/python-3.2.4/bin/python
Installing setuptools, pip, wheel...done.
direnv: export +VIRTUAL_ENV ~PATH
pip install PrettyTable
Collecting PrettyTable
Installing collected packages: PrettyTable
Successfully installed PrettyTable-0.7.2

reference

There were various reference sites, but I didn't make a note. \ (^ O ^) / http://qiita.com/jnotoya/items/ca9a0dfee6b9f084f4da

Recommended Posts

I made a Python3 environment on Ubuntu with direnv.
I made a fortune with Python.
I made a daemon with Python
[Pyenv] Building a python environment with ubuntu 16.04
I made a character counter with Python
I made a Hex map with Python
I made a roguelike game with Python
I made a simple blackjack with Python
I made a configuration file with Python
I made a neuron simulator with Python
I made a competitive programming glossary with Python
I made a weather forecast bot-like with Python.
I made a GUI application with Python + PyQt5
Build python environment with pyenv on EC2 (ubuntu)
Building a python environment with virtualenv and direnv
Build a python environment with ansible on centos6
I made a Twitter fujoshi blocker with Python ①
[Python] I made a Youtube Downloader with Tkinter.
[Venv] Create a python virtual environment on Ubuntu
Create a Python execution environment on IBM i
I made a bin picking game with Python
I made a Mattermost bot with Python (+ Flask)
I made blackjack with python!
Build python3 environment with ubuntu 16.04
Build python environment with direnv
I made a python text
I made blackjack with Python.
I tried to build a Mac Python development environment with pythonz + direnv
I made wordcloud with Python.
I made a Twitter BOT with GAE (python) (with a reference)
# 2 Build a Python environment on AWS EC2 instance (ubuntu18.04)
I made a Christmas tree lighting game with Python
I made a net news notification app with Python
I made a LINE BOT with Python and Heroku
Building a Python environment on Mac
Prepare Python development environment on Ubuntu
I made a Line-bot using Python!
Create a Python environment on Mac (2017/4)
Create a virtual environment with Python!
Building a virtual environment with Python 3
Create a python environment on centos
Build Python 3.8 + Pipenv environment on Ubuntu 18.04
Build a python3 environment on CentOS7
OpenCV3 & Python3 environment construction on Ubuntu
I made a simple typing game with tkinter in Python
How to build a new python virtual environment on Ubuntu
I made a package to filter time series with python
I made a simple book application with python + Flask ~ Introduction ~
I made a puzzle game (like) with Tkinter in Python
Until building a Python development environment using pyenv on Ubuntu 20.04
Life game with Python [I made it] (on the terminal & Tkinter)
[Ubuntu 18.04] Python environment construction with pyenv + pipenv
I made a simple circuit with Python (AND, OR, NOR, etc.)
I made a library to easily read config files with Python
Building a Python3 environment with Amazon Linux2
I made a package that can compare morphological analyzers with Python
I made a payroll program in Python!
Build Python3 and OpenCV environment on Ubuntu 18.04
Build a python environment on MacOS (Catallina)
Python virtual environment and packages on Ubuntu
Build a Python environment on your Mac with Anaconda and PyCharm