5

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?

10
  • Unfortunately, I don't know a general solution to the problem. But in your special case it should be the ncurses package: packages.ubuntu.com/…
    – cel
    Commented Apr 26, 2019 at 9: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
    Commented Apr 26, 2019 at 9: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
    Commented Apr 26, 2019 at 10:19
  • @cel How can I tell if you are right? pip doesn't seem to tell me.
    – Tom Hale
    Commented Apr 26, 2019 at 13:39
  • 1
    Can you run strings on it?
    – tripleee
    Commented Apr 27, 2019 at 8:16

3 Answers 3

4

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.

2

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

Replace filename with the filename you need.

  1. search which package installed by pip contains filename:

    pip list | tail -n +3 | cut -d" " -f1 | xargs pip show -f | grep filename
    
  2. but if it was installed via conda you have to do this instead:

    If inside an active conda env:

    grep filename "$CONDA_PREFIX/conda-meta/"*
    

    If not inside an active conda env:

    grep filename ~/anaconda3/envs/ENVNAME/conda-meta/*
    
    • replace ~/anaconda3 with the path where your conda resides
    • replace ENVNAME with the conda env name you want

  • the first recipe is from the OP
2
  • Does the pip list option normally take a long time? It took more than a minute for me before I cancelled it and tried the second one, which got results in less than a second.
    – wjandrea
    Commented Mar 21 at 18:07
  • 1
    it might depend on your fs and the conda env size - on my desktop it takes 0.3secs
    – stason
    Commented Mar 21 at 22:21
0

One ugly solution is:

  1. Rename the file
  2. Re-install all installed packages one-by-one until the file reappears

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.