2

I'm having problems with ~/.local/share/miniconda3/envs/nndl/bin/tput - it produces output different to my system version, breaking some ANSI colouring.

I'm trying to track down the package which provides this offensive version.

I've tried (source):

pip list | tail -n +3 | cut -d" " -f1 | xargs pip show -f | grep tput

But the binary is not shown.

How do I find which python package includes a binary?

Tom Hale
  • 40,825
  • 36
  • 187
  • 242
  • Unfortunately, I don't know a general solution to the problem. But in your special case it should be the ncurses package: https://packages.ubuntu.com/search?searchon=contents&keywords=tput&mode=exactfilename&suite=disco&arch=any – cel Apr 26 '19 at 09:34
  • Thanks @cel, but I use Arch Linux packages and am looking for the python package with the binary that miniconda is putting earlier in my PATH. – Tom Hale Apr 26 '19 at 09:48
  • I am very sure that it will be provided by conda's ncurses package. You can check `conda list |grep ncurses` and see whether it is installed. – cel Apr 26 '19 at 10:19
  • @cel How can I tell if you are right? pip doesn't seem to tell me. – Tom Hale Apr 26 '19 at 13:39
  • Do you *have* `ncurses` in the env? If yes then it's Occam's razor. – tripleee Apr 27 '19 at 06:36
  • @tripleee `pip list | grep -q ncurses` is false (with the broken colours environment activated). – Tom Hale Apr 27 '19 at 06:41
  • If you examine the `tput` file, is it a binary, or Python code? In the latter case the `import` should reveal which package it's from. – tripleee Apr 27 '19 at 06:43
  • @tripleee `file` says: `ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, for GNU/Linux 2.6.18, not stripped` – Tom Hale Apr 27 '19 at 08:09
  • 1
    Can you run `strings` on it? – tripleee Apr 27 '19 at 08:16
  • @tripleee It seems to be a regular RedHat binary: https://pastebin.com/TxtZyGz7 – Tom Hale Apr 27 '19 at 09:11

4 Answers4

2

Conda-based options

Option 1: Resolve any environment file

The conda package command includes functionality for resolving the package of origin given a file. This is provided by the -w,--which command.

Documentation (abridged)

$ conda package -h
usage: conda package [-h] [-n ENVIRONMENT | -p PATH] [-w PATH [PATH ...]] [-r] [-u] [--pkg-name PKG_NAME] [--pkg-version PKG_VERSION] [--pkg-build PKG_BUILD]

Low-level conda package utility. (EXPERIMENTAL)

Options:

optional arguments:
  -h, --help            Show this help message and exit.
  -w PATH [PATH ...], --which PATH [PATH ...]
                        Given some PATH print which conda package the file came from.
...

There's a tput in my base's bin/ so running on that, I get:

$ conda package --which tput
tput    conda-forge/osx-arm64::ncurses-6.3-h07bb92c_1

That is, ncurses looks like the culprit.

Option 2: Executables Only

There is a neat Conda Incubator package called conda-suggest that I've found useful. This uses a database of executable files from Conda Forge packages to identify what Conda Forge packages provide them.

This again works out nicely with OP's example:

## install it to base
$ conda install -n base conda-forge::conda-suggest

$ conda suggest message 'tput'
Command 'tput' not found in the environment, but can be installed with # # any of:

    $ conda install -c conda-forge ncurses

So, ncurses is the only package on Conda Forge that installs this executable.

Unfortunately, the database is not regularly updated and only covers Conda Forge. On the upside, one doesn't need the package installed, and it accepts regex.

merv
  • 67,214
  • 13
  • 180
  • 245
1

To find which package some file belongs to in a mixed conda/pip environment

  1. search which package installed by pip contains filename:
pip list | tail -n +3 | cut -d" " -f1 | xargs pip show -f | grep filename_to_find
  1. but if it was installed via conda you have to do this instead:
grep filename_to_find  ~/anaconda3/envs/ENVNAME/conda-meta/*
  • replace filename_to_find with the filename you need
  • replace ~/anaconda3 with the path where your conda resides
  • replace ENVNAME with the conda env name you want

(the first recipe is from OP)

stason
  • 5,409
  • 4
  • 34
  • 48
0

One ugly solution is:

  1. Rename the file
  2. Re-install all installed packages one-by-one until the file reappears
Tom Hale
  • 40,825
  • 36
  • 187
  • 242
-2
which python

It should give you the right path

Albe
  • 109
  • 4