0

I've spotted some similar questions/answers, but not what I'm having. Thanks for your help!

System : ubuntu 20.04 fresh install, python 3.8.5 system installed and pyenv running just fine. Tox,though, creates the venv but keeps running the system interpreter.

pyenv running great :

aj@jaja:/tmp$ python --version
Python 3.8.5
aj@jaja:/tmp$ pyenv versions
* system (set by /home/aj/.pyenv/version)
  3.6.13
  pypy3.6-7.0.0
aj@jaja:/tmp$ pyenv local 3.6.13
aj@jaja:/tmp$ python --version
Python 3.6.13

my tox.ini :

[tox]
envlist = 3.6.13, 3.8.5
skipsdist = True

[testenv]
deps =
    pytest

commands =
    python --version
    python -c 'import sys; print(sys.executable)'
    pytest

tox seems to create the venv just fine:

aj@jaja:/tmp/foo$ tox -l
3.6.13
3.8.5

but it's always running the system interpreter instead of the venv one:

3.6.13 installed: attrs==20.3.0,iniconfig==1.1.1,packaging==20.9,pluggy==0.13.1,py==1.10.0,pyparsing==2.4.7,pytest==6.2.2,toml==0.10.2
3.6.13 run-test-pre: PYTHONHASHSEED='3215808768'
3.6.13 run-test: commands[0] | python --version
**Python 3.8.5**
3.6.13 run-test: commands[1] | python -c 'import sys; print(sys.executable)'
**/tmp/foo/.tox/3.6.13/bin/python**
3.6.13 run-test: commands[2] | pytest
======================================================================= test session starts =======================================================================
platform linux -- Python 3.8.5, pytest-6.2.2, py-1.10.0, pluggy-0.13.1
cachedir: .tox/3.6.13/.pytest_cache
rootdir: /tmp/foo
collected 1 item  

                                                                                                                                            

test_calc.py .

the pyenv of interest shows that, but I don't know how correct it using tox directly:

aj@jaja:/tmp/foo$ cat .tox/3.6.13/pyvenv.cfg 
home = /usr
implementation = CPython
version_info = 3.8.5.final.0
virtualenv = 20.4.3
include-system-site-packages = false
base-prefix = /usr
base-exec-prefix = /usr
base-executable = /usr/bin/python3.8
  • Update: thanks to both of you for indication and information :) my mistake was that I assumed tox would install the required env, if it were downloaded before. in my case, the 3.6 was downloaded but not active. => I added a layer on top to have both expected available : aj@jaja:~/foo_env$ pyenv local 3.6.13 3.8.5 aj@jaja:~/foo_env$ cd foo/ aj@jaja:~/foo_env$ rm -rf .tox aj@jaja:~/foo_env$ tox aj@jaja:~/foo_env/foo$ tox – jefsomething Mar 17 '21 at 19:08

2 Answers2

4

your environments aren't named how tox expects them to be named

The convention is py## where ## is the version without a dot (or ### in the case of 3.10+)

So in your case you want:

envlist = py36,py38

this will cause tox to automatically find and use python3.6 and python3.8 on your PATH -- if you need it to pick a specific interpreter you can use the envpython setting in the individual [testenv]


disclaimer: I'm one of the tox core maintainers

anthony sottile
  • 61,815
  • 15
  • 148
  • 207
  • 1
    The full spec for the env name is actuallyhttps://virtualenv.pypa.io/en/latest/user_guide.html#python-discovery anything that matches that spec will be respected. If this does not happen make sure to always post the output or tox -vv so we can see where and what's going wrong. Also as @klausf pointed out make sure you enable all envs with pyenv so they are discoverable as the linked documentation describes., – Yeti Mar 16 '21 at 23:55
  • The link: https://virtualenv.pypa.io/en/latest/user_guide.html#python-discovery – Yeti Mar 16 '21 at 23:55
  • tox is great, with pyenv and pytest it's a decade jump toward happy coding :) – jefsomething Mar 17 '21 at 19:18
1

I never encountered pyenv issues with tox: Just be sure you enable all versions, that tox shall use.

E.g.

pyenv shell system 3.6.13
tox

I also think, that tox handles only two version numbers, so try to change in your tox.ini file to 3.6 and 3.8

Edit: In fact as it was pointed out in @Anthony Sottile's answer: (I didn't even notice when reading your question. you had to use py36 and py38 instead of 3.6 and 3.8 as I suggested in my initial answer

You can use pyenv to force the exact versions of 3.6 or 3.8

In general it doesn't really make that much sense to test 3.6.a and 3.6.b normally the newer sub versions should be fully compatible to the previous ones except of course for erroneous behavior, that has been fixed

Just for info: (I know you don't try to do that)

Please note, that you cannot activate for example 3.6.1 and 3.6.2 within one pyenv 'session' (shell) in a meaningful way.

Type following commands to see what I mean:

pyenv which python
pyenv which python3
pyenv which python3.6
pyenv which python3.6.13  # this one will not be found
KlausF
  • 152
  • 8