0

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.

QbS
  • 425
  • 1
  • 4
  • 17

2 Answers2

1

You should install additional Python packages via the deps directive, see the example in our documentation:

https://tox.wiki/en/latest/config.html#tox-ini

P.S.: I am one of the tox maintainers

Jürgen Gmach
  • 5,366
  • 3
  • 20
  • 37
  • Thanks I know, I do it for some of the packages. But I need to install those from the prepared repository and it worked some time ago, but something changed (probably) on my machine and I'm trying to figure out what exactly. It looks like tox attached this path to it: /home/usr/.local/lib/python3.8/site-packages But I tried to reinstall tox and it didn't help. – QbS Jan 18 '23 at 10:39
  • Or is it possible to install from a repository located in subfolders to tox.ini installation by pip setup.py by adding it to deps somehow? I haven't found a clear description of how the installation is done in deps. And I can't add those libraries to the requirements.txt file from where I install some other dependencies. – QbS Jan 18 '23 at 11:16
  • I found that tox creates .tox-info.json for running tox environment with an executable path to the wrong instance of python. This is strange because in tox documentation commands should first resolve to an executable from within the virtual environment not my local python instance. – QbS Jan 18 '23 at 12:48
  • 1
    You can have a look over at https://stackoverflow.com/questions/24411276 for more inspirations on how to achieve what you plan to do. There might have been changes between tox 3 and version 4 though. On which version are you? About interpreter discovery.. I cannot say much without seeing your tox.ini, your command, your computer setup... so, maybe try `deps` first as suggested. – Jürgen Gmach Jan 18 '23 at 14:10
  • Thanks, I checked it and learn something new. However, in my case I need libraries to be placed in one folder (to be precise tox folder with libraries for the precise environment). Because then I apply some actions to them. I investigated a bit and apparently, tox is forcing WSL python's path in my case. I updated my question. If you'd be able to give it a look, maybe you'll have an idea of what to fix / what to investigate further. I'd appreciate it! – QbS Jan 19 '23 at 09:25
0

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

commands =
    python -m pip install [path_to_library]

As simple.

QbS
  • 425
  • 1
  • 4
  • 17