When using pyenv and it’s
pyenv-virtualenv -plugin, the activated virtualenv does not include
the /bin
-directory of the base python version in the PATH.
Background
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.
pyenv-virtualenv
pyenv-virtualenv is a pyenv plugin that provides features to manage virtualenvs and conda environments for Python on UNIX-like systems.
Python environment at the time
- pyenv installed as defined in the Basic github checkout
- pyenv-virtualenv installed as defined here
-
python version 3.6.4 installed
$ pyenv install 3.6.4 $ pyenv versions system 3.6.4
-
virtualenv for Ansible created
$ pyenv virtualenv 3.6.4 ansible $ pyenv virtualenvs 3.6.4/envs/ansible (created from /home/askolsam/.pyenv/versions/3.6.4) ansible (created from /home/askolsam/.pyenv/versions/3.6.4)
-
Ansible 2.5.6 installed
$ pyenv activate ansible $ pip install ansible==2.5.6
Problem
I was trying to update an local ansible module from python 2 to 3, but command 2to3
just returned
‘command not found’:
$ pyenv activate ansible
$ python --version
Python 3.6.4
$ pyenv which 2to3
pyenv: 2to3: command not found
The '2to3' command exists in these Python versions:
3.6.4
$ pyenv deactivate
$ pyenv global 3.6.4
$ python --version
Python 3.6.4
$ pyenv which 2to3
/home/askolsam/.pyenv/versions/3.6.4/bin/2to3
Solution
Someone else had this same issue too.
The solution is not to use pyenv activate
but pyenv global
or pyenv local
:
$ pyenv global ansible 3.6.4
$ pyenv version
ansible (set by /home/askolsam/.pyenv/version)
3.6.4 (set by /home/askolsam/.pyenv/version)