Search code examples
pythontox

Tox installing external libraries in tox env not from requirements.txt


I use windows. My tox.ini:

[tox]
envlist =
    docs
min_version = 4
skipsdist = True
allowlist_externals = cd
passenv =
    HOMEPATH
    PROGRAMDATA
basepython = python3.8

[testenv:docs]
changedir = docs
deps =
    -r subfolder/package_name/requirements.txt
commands =
    bash -c "cd ../subfolder/package_name/ && pip install ."

Within a tox environment, I install some additional packages. I do it as above in tox's commands.

However, tox is installing a library in WSL's python instance path:

/home/usr/.local/lib/python3.8/site-packages

Not in tox's environment place for libraries:

.tox/env/lib/site-packages

I trigger tox inside the python virtual environment. If I run it in Docker everything works fine.

I use Windows. Besides WSL I have two python versions installed on my Windows: 3.8 and the main one 3.10. However, the virtual env that I'm using for tox is with 3.8. But I tested it with 3.10 and I receive the same result. In the system variables' path they are in such order and on the top of the list:

C:\Users\UserName\AppData\Local\Programs\Python\Python310\Scripts
C:\Users\UserName\AppData\Local\Programs\Python\Python310
C:\Users\UserName\AppData\Local\Programs\Python\Python38\Scripts
C:\Users\UserName\AppData\Local\Programs\Python\Python38\

As I found in the tox documentation:

Name or path to a Python interpreter which will be used for creating the virtual environment, first one found wins. This determines in practice the Python for what we’ll create a virtual isolated environment.

So: I'm trying to understand and fix the way how tox picks up the path to the python instance. As a result it should install libraries inside tox environment in libs folder.


Solution

  • Found a solution. Silly mistake: Use python instead of bash to install libraries.

    commands =
        python -m pip install [path_to_library]
    

    As simple.