pyenv installs multiple pythons, but recognizes only some
Asked Answered
H

2

6

I am trying to get pyenv up and running (Mac OS X), so I can use tox/detox to test code vs. multiple python environments. I was able to install multiple python3 versions, and then I used pyenv global on all the versions. After doing that, pyenv versions returns this list:

  system
* 3.2.6 (set by /Users/Workspace/.pyenv/version)
  3.3.6
  3.4.6
  3.5.3
  3.6.1

However, only 3.4 and 3.5 are recognized (along with 2.7.8, which I believe is 'system'):

Geoffreys-MBP:pydnmr-tox Workspace$ python --version
Python 2.7.8
Geoffreys-MBP:pydnmr-tox Workspace$ python3.2 --version
-bash: python3.2: command not found
Geoffreys-MBP:pydnmr-tox Workspace$ python3.3 --version
-bash: python3.3: command not found
Geoffreys-MBP:pydnmr-tox Workspace$ python3.4 --version
Python 3.4.3
Geoffreys-MBP:pydnmr-tox Workspace$ python3.5 --version
Python 3.5.2
Geoffreys-MBP:pydnmr-tox Workspace$ python3.6 --version
-bash: python3.6: command not found

Any ideas what is causing this behavior? tox/detox similarly cannot find any Python version besides 3.4/3.5.

Edit: it seems that pyenv has installed all the environments, but python3.x commands weren't finding them. python3.4 and python3.5 were working because they found previous top-level installations. Results for pyenv which python3.x.y vs. python3.x [--version] shown below.

$ pyenv which python3.2
/Users/Workspace/.pyenv/versions/3.2.6/bin/python3.2
$ python3.2 --version
-bash: python3.2: command not found
$ python3.2
-bash: python3.2: command not found
pyenv which python3.3
/Users/Workspace/.pyenv/versions/3.3.6/bin/python3.3
$ python3.3 --version
-bash: python3.3: command not found
$ pyenv which python3.4
/usr/local/bin/python3.4  # old install
$ python3.4 --version
Python 3.4.3              # not 3.4.6 installed by pyenv
$ pyenv which python3.4.6
pyenv: python3.4.6: command not found
$ python3.4.6 --version
-bash: python3.4.6: command not found
$ pyenv which python3.5
/Users/Workspace/.pyenv/versions/3.5.3/bin/python3.5
$ python3.5 --version
Python 3.5.2  #Linked to my old 3.5.2 install instead of pyenv 3.5.3 install
$ pyenv which python3.6
/Users/Workspace/.pyenv/versions/3.6.1/bin/python3.6
$ python3.6 --version
-bash: python3.6: command not found

However, installing tox-pyenv as suggested in the answers below allowed tox to find and use all of these environments!

Heredia answered 6/4, 2017 at 3:4 Comment(3)
What does pyenv version (without the s at the end) return?Armelda
Oliver: it returns a list of system plus 3.x.x versions, in the order listed in the global/local command, with (set by /Users/Workspace/Desktop/pydnmr-tox/.python-version)Heredia
I also noticed inconsistencies like this, but did not have the chance to pin them down yet, that is why tox-pyenv is a good alternative.Armelda
A
5

pyenv interpreter discovery is not integrated with tox core (yet). So everything that work is just because tox happens to find some with the unaware discovery methods it already applies.

There are two ways to make this work consistently:

  1. Tell pyenv about all your interpreters in the context where you call tox. e.g. in the project where you want to run tox pyenv local system 3.2.6 3.3.6 3.4.6 3.5.3 3.6.1 Then tox should find all of them. If you want this to be the default wherever you are you cant set pyenv global exactly like that. The first in the list is the interpreter that is invoked, when just calling python, but all others should also be active and therefore discoverable for tox.

  2. If this doesn't do it for you for whatever reason or you like it to be a bit more automatic: there is a plugin - tox-pyenv that takes care of the discovery

Armelda answered 6/4, 2017 at 8:40 Comment(1)
Neither pyenv global or pyenv local worked, but installing tox-pyenv did. I read that tox-pyenv tells tox to use pyenv which for path discovery. I tried doing this and discovered odd behavior. I'll add it at the end of my question.Heredia
P
0

You can set all the versions you need by using pyenv global. For example:

pyenv global 3.6.0 3.5.3 3.4.6 2.7.10

I use this approach for my libraries and tox runs without any issue :)

Purity answered 6/4, 2017 at 8:44 Comment(3)
That's what I actually meant by "used pyenv global on all the versions". Thanks, though.Heredia
have you launched the command the same way as my example (with all the versions simultaneously)? If you run pyenv global what is the output? (you should see all the versions, otherwise if you get only one it means that the answer to my first question is nope)Purity
Yes, I did. The output of pyenv global is a list of all the versions. I have more elaboration in other comments, plus an addendum to my original question. The mystery is that pyenv seems to have successfully installed the versions, but using python3.x for 3.2 thru 3.6 would either not find a python, or find an old top-level install. But: installing tox-pyenv magically solves the issue!Heredia

© 2022 - 2024 — McMap. All rights reserved.