1

I need to pipe some conda commands:

$ conda list --export | head -n 3
# This file may be used to create an environment using:
# $ conda create --name <env> --file <this file>
# platform: linux-64

This works fine. However piping the explicit list fails:

$ conda list --explicit | head -n 3
# This file may be used to create an environment using:
# $ conda create --name <env> --file <this file>
# platform: linux-64
An unexpected error has occurred.
Please consider posting the following information to the
conda GitHub issue tracker at:

    https://github.com/conda/conda/issues



Current conda install:

               platform : linux-64
          conda version : 4.2.12
       conda is private : False
      conda-env version : 4.2.12
    conda-build version : not installed
         python version : 2.7.12.final.0
       requests version : 2.11.1
       root environment : /home/me/miniconda3  (writable)
    default environment : /home/me/miniconda3
       envs directories : /home/me/miniconda3/envs
          package cache : /home/me/miniconda3/pkgs
           channel URLs : https://repo.continuum.io/pkgs/free/linux-64
                          https://repo.continuum.io/pkgs/free/noarch
                          https://repo.continuum.io/pkgs/pro/linux-64
                          https://repo.continuum.io/pkgs/pro/noarch
            config file : None
           offline mode : False



`$ /home/me/miniconda3/bin/conda list --explicit`

The traceback is (sorry, it wont allow me to put it inside code tags...):

Traceback (most recent call last):    
File "/home/me/miniconda3/lib/python2.7/site-packages/conda/exceptions.py", line 479, in conda_exception_handler
return_value = func(*args, **kwargs)

File "/home/me/miniconda3/lib/python2.7/site-packages/conda/cli/main.py", line 145, in _main
  exit_code = args.func(args, p)

File "/home/me/miniconda3/lib/python2.7/site-packages/conda/cli/main_list.py", line 213, in execute
  print_explicit(prefix, args.md5)

File "/home/me/miniconda3/lib/python2.7/site-packages/conda/cli/main_list.py", line 190, in print_explicit
  print(url + ('#%s' % md5 if add_md5 and md5 else ''))

IOError: [Errno 32] Broken pipe

That's probably a bug right? Without piping it works fine.

darthbith
  • 18,484
  • 9
  • 60
  • 76
kaligne
  • 3,098
  • 9
  • 34
  • 60
  • I can't reproduce this on my Ubuntu 16.04 system with Python 3. What OS are you using? – darthbith Nov 11 '16 at 18:51
  • I tried this on mac osx. Ill try with a linux – kaligne Nov 11 '16 at 19:53
  • But your `conda info` shows `linux-64`? FWIW, I can't reproduce this on OS X either, but again, its Miniconda 3 – darthbith Nov 11 '16 at 21:21
  • Sorry I got it wrong.. You are right I executed the command on Linux. Then I used those information to install the conda packages on mac that's how I got confused. – kaligne Nov 14 '16 at 10:14

1 Answers1

3

The broken pipe is occurring because head is closing the output stream once it gets the 3 lines that it has been instructed to show. You'll notice that you get those three lines in your output. The next time that conda tries to print, it cannot because head has closed the pipe. That is what is causing this exception. This is not a problem with conda. Have a look here for further information regarding broken pipe exceptions in python: IOError: [Errno 32] Broken pipe: Python

Now for a potential work around:

$ conda list --explicit > /tmp/conda-explicit-output && head -n 15 /tmp/conda-explicit-output && rm /tmp/conda-explicit-output

Yeah it's pretty ugly, but it will probably get the job done.

Community
  • 1
  • 1
Eric Dill
  • 2,166
  • 2
  • 17
  • 15
  • I guess you solved it! So it's not a piping issue generally speaking. If I do `$ conda list --explicit | wc -l` I get `297`. So now: `$ conda list --explicit | head -n 297` returns the correct results. Actually I used `head` for testing purposes, I don't need it per se. So I don't need the "ugly" piece of code ;) THanks! – kaligne Nov 14 '16 at 10:18