Overview
In a shared development environment, if you put pyenv for each user, the capacity will be great, so A story to put one in common so that it can be reused by general users.
pyenv
grouppyenv
grouppyenv
groupThe method that docker also adopts.
You can use docker, but since it's a big deal, I'll use vagrant.
$ vagrant -v
Vagrant 2.2.3
Vagrantfile
Vagrant.configure("2") do |config|
config.vm.box = "centos/7"
end
$ vagrant up
$ vagrant ssh
Last login: Wed Feb 5 03:53:55 2020 from 10.0.2.2
[vagrant@localhost ~]$
[vagrant@localhost ~]$ sudo su -
Last login:Wed February 5 03:50:50 UTC 2020 on pts/1
[root@localhost ~]#
pyenv.sh
if [ -e /opt/pyenv ]; then
export PYENV_ROOT=/opt/pyenv
export PATH="${PYENV_ROOT}/bin:$PATH"
eval "$(pyenv init -)"
fi
Install to / opt / pyenv
.
$ yum install -y \
@development zlib-devel bzip2 bzip2-devel readline-devel sqlite \
sqlite-devel openssl-devel xz xz-devel libffi-devel findutils
$ curl https://pyenv.run | PYENV_ROOT=/opt/pyenv bash
$ groupadd pyenv \
&& chown -R :pyenv /opt/pyenv/ \
&& chmod g+r -R /opt/pyenv/
$ cp /vagrant/pyenv.sh /etc/profile.d/
Re-enter the vm
[vagrant@localhost ~]$ pyenv -v
pyenv 1.2.16
[vagrant@localhost ~]$ pyenv versions
* system (set by /opt/pyenv/version)
Since pyenv install
can only be done by root,
[root@localhost ~]# pyenv install 3.8.1
(..snip..)
[root@localhost ~]# pyenv install 3.7.6
(..snip..)
It has entered.
[root@localhost ~]# pyenv versions
* system (set by /opt/pyenv/version)
3.7.6
3.8.1
Also confirmed by general users.
I don't have write permission, so I get pyenv: cannot rehash: / opt / pyenv / shims isn't writable
, but don't worry.
[root@localhost ~]# su - vagrant
Last login: Wed Feb 5 04:01:04 UTC 2020 from 10.0.2.2 on pts/0
pyenv: cannot rehash: /opt/pyenv/shims isn't writable
[vagrant@localhost ~]$ pyenv versions
* system (set by /opt/pyenv/version)
3.7.6
3.8.1
This is the preparation.
Run in vm.
Don't forget to belong to the pyenv
group.
[root@localhost ~]# useradd foo -G pyenv
[root@localhost ~]# id foo
uid=1001(foo) gid=1002(foo) groups=1002(foo),1001(pyenv)
To add an existing user to group:
[root@localhost ~]# useradd bar
[root@localhost ~]# gpasswd -a bar pyenv
[root@localhost ~]# id bar
uid=1002(bar) gid=1003(bar) groups=1003(bar),1001(pyenv)
Since pyenv global
cannot be used, pyenv local
is used for each user.
[root@localhost ~]# su - bar
Last login: Wed Feb 5 03:55:34 UTC 2020 on pts/2
pyenv: cannot rehash: /opt/pyenv/shims isn't writable
[bar@localhost ~]$ pyenv local 3.7.6
[bar@localhost ~]$ python -V
Python 3.7.6
[bar@localhost ~]$ python -m venv .venv
[bar@localhost ~]$ . .venv/bin/activate
(.venv) [bar@localhost ~]$ python -V
Python 3.7.6
(.venv) [bar@localhost ~]$ which python
~/.venv/bin/python
(.venv) [bar@localhost ~]$ pip install numpy==1.18.1
(.venv) [bar@localhost ~]$ python -c 'import numpy; print(numpy.__version__)'
1.18.1
[root@localhost ~]# su - foo
Last login: Wed Feb 5 03:54:47 UTC 2020 on pts/1
pyenv: cannot rehash: /opt/pyenv/shims isn't writable
[foo@localhost ~]$ pyenv local 3.8.1
[foo@localhost ~]$ python -V
Python 3.8.1
Don't forget to add the --user
option to pip install
if you don't use virtualenv.
[foo@localhost ~]$ python -m pip install --user numpy==1.15
[foo@localhost ~]$ python -c 'import numpy; print(numpy.__version__)'
1.15.0
end.
It is unknown what will happen if you use it because it is not operating properly. At Your Own Risk.
Let's use docker.
Recommended Posts