Repository: conda/conda

Issue:
conda list error if package installed with --editable
I have package installed via `pip install -U --editable .`

### Current Behavior
AssertionError: ('lib/python3.6/site-packages/ocli-sarpy.egg-link', ['ocli.sarpy.egg-info', 'ocli_sarpy.egg-info'])

### Steps to Reproduce
```
pip install -U --editable .
conda list
```


## Expected Behavior
should not raise exception, should output installed packages

## Environment Information
<details><summary><code>`conda info`</code></summary><p>
```
     active environment : ocli
    active env location : /home/vlz/miniconda3/envs/ocli
            shell level : 1
       user config file : /home/vlz/.condarc
 populated config files : /home/vlz/.condarc
          conda version : 4.7.5
    conda-build version : not installed
         python version : 3.6.7.final.0
       virtual packages :
       base environment : /home/vlz/miniconda3  (writable)
           channel URLs : https://conda.anaconda.org/conda-forge/linux-64
                          https://conda.anaconda.org/conda-forge/noarch
                          https://repo.anaconda.com/pkgs/main/linux-64
                          https://repo.anaconda.com/pkgs/main/noarch
                          https://repo.anaconda.com/pkgs/r/linux-64
                          https://repo.anaconda.com/pkgs/r/noarch
          package cache : /home/vlz/miniconda3/pkgs
                          /home/vlz/.conda/pkgs
       envs directories : /home/vlz/miniconda3/envs
                          /home/vlz/.conda/envs
               platform : linux-64
             user-agent : conda/4.7.5 requests/2.22.0 CPython/3.6.7 Linux/4.4.0-18362-Microsoft ubuntu/18.04.2 glibc/2.27
                UID:GID : 1000:1000
             netrc file : None
           offline mode : False
```
</p></details>


<details open><summary><code>`conda config --show-sources`</code></summary><p>

```
==> /home/vlz/.condarc <==
auto_update_conda: False
auto_activate_base: False
channels:
  - conda-forge
  - defaults
```

</p></details>


<details><summary><code>`conda list --show-channel-urls`</code></summary><p>

```
 AssertionError: ('lib/python3.6/site-packages/ocli-sarpy.egg-link', ['ocli.sarpy.egg-info', 'ocli_sarpy.egg-info'])
```
</p></details>



Discussion:
Looks like there is a problem with how conda is reading pip installs for older versions of pip. Could you provide a more complete traceback for the issue?
```bash
(ocli) ➜  sarpy pip --version
pip 19.1.1 from /home/vlz/miniconda3/envs/ocli/lib/python3.6/site-packages/pip (python 3.6)
```
```
pip install --upgrade-strategy=only-if-needed --editable  .
```
```sh
(ocli) ➜  sarpy conda list

# >>>>>>>>>>>>>>>>>>>>>> ERROR REPORT <<<<<<<<<<<<<<<<<<<<<<

    Traceback (most recent call last):
      File "/home/vlz/miniconda3/lib/python3.6/site-packages/conda/exceptions.py", line 1043, in __call__
        return func(*args, **kwargs)
      File "/home/vlz/miniconda3/lib/python3.6/site-packages/conda/cli/main.py", line 84, in _main
        exit_code = do_call(args, p)
      File "/home/vlz/miniconda3/lib/python3.6/site-packages/conda/cli/conda_argparse.py", line 82, in do_call
        exit_code = getattr(module, func_name)(args, parser)
      File "/home/vlz/miniconda3/lib/python3.6/site-packages/conda/cli/main_list.py", line 142, in execute
        show_channel_urls=context.show_channel_urls)
      File "/home/vlz/miniconda3/lib/python3.6/site-packages/conda/cli/main_list.py", line 80, in print_packages
        show_channel_urls=show_channel_urls)
      File "/home/vlz/miniconda3/lib/python3.6/site-packages/conda/cli/main_list.py", line 45, in list_packages
        installed = sorted(PrefixData(prefix, pip_interop_enabled=True).iter_records(),
      File "/home/vlz/miniconda3/lib/python3.6/site-packages/conda/core/prefix_data.py", line 130, in iter_records
        return itervalues(self._prefix_records)
      File "/home/vlz/miniconda3/lib/python3.6/site-packages/conda/core/prefix_data.py", line 159, in _prefix_records
        return self.__prefix_records or self.load() or self.__prefix_records
      File "/home/vlz/miniconda3/lib/python3.6/site-packages/conda/common/io.py", line 88, in decorated
        return f(*args, **kwds)
      File "/home/vlz/miniconda3/lib/python3.6/site-packages/conda/core/prefix_data.py", line 72, in load
        self._load_site_packages()
      File "/home/vlz/miniconda3/lib/python3.6/site-packages/conda/core/prefix_data.py", line 274, in _load_site_packages
        python_record = read_python_record(self.prefix_path, af, python_pkg_record.version)
      File "/home/vlz/miniconda3/lib/python3.6/site-packages/conda/gateways/disk/read.py", line 249, in read_python_record
        pydist = PythonDistribution.init(prefix_path, anchor_file, python_version)
      File "/home/vlz/miniconda3/lib/python3.6/site-packages/conda/common/pkg_formats/python.py", line 76, in init
        return PythonEggLinkDistribution(prefix_path, anchor_file, python_version)
      File "/home/vlz/miniconda3/lib/python3.6/site-packages/conda/common/pkg_formats/python.py", line 416, in __init__
        anchor_full_path = get_dist_file_from_egg_link(anchor_file, prefix_path)
      File "/home/vlz/miniconda3/lib/python3.6/site-packages/conda/common/pkg_formats/python.py", line 916, in get_dist_file_from_egg_link
        assert len(egg_info_fnames) == 1, (egg_link_file, egg_info_fnames)
    AssertionError: ('lib/python3.6/site-packages/ocli-sarpy.egg-link', ['ocli.sarpy.egg-info', 'ocli_sarpy.egg-info'])

`$ /home/vlz/miniconda3/bin/conda list`

  environment variables:
                 CIO_TEST=<not set>
        CONDA_DEFAULT_ENV=ocli
                CONDA_EXE=/home/vlz/miniconda3/bin/conda
             CONDA_PREFIX=/home/vlz/miniconda3/envs/ocli
    CONDA_PROMPT_MODIFIER=(ocli)
         CONDA_PYTHON_EXE=/home/vlz/miniconda3/bin/python
               CONDA_ROOT=/home/vlz/miniconda3
              CONDA_SHLVL=1
                     PATH=/home/vlz/miniconda3/bin:/home/vlz/miniconda3/envs/ocli/bin:/home/vlz/
                          miniconda3/condabin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:
                          /sbin:/bin:/usr/games:/usr/local/games:/c/Program Files/Far
                          Manager/ConEmu/Scripts:/c/Program Files/Far Manager:/c/Program
                          Files/Far Manager/ConEmu:/c/Program Files (x86)/Common
                          Files/Oracle/Java/javapath:/c/ProgramData/DockerDesktop/version-
                          bin:/c/Program Files/Docker/Docker/Resources/bin:/c/Program
                          Files/NVIDIA GPU Computing Toolkit/CUDA/v10.0/bin:/c/Program
                          Files/NVIDIA GPU Computing Toolkit/CUDA/v10.0/libnvvp:/c/ProgramData/O
                          racle/Java/javapath:/c/Program Files/Intel/iCLS Client:/c/WINDOWS/syst
                          em32:/c/WINDOWS:/c/WINDOWS/System32/Wbem:/c/WINDOWS/System32/WindowsPo
                          werShell/v1.0:/c/VLZ/work/Ampps/php:/c/Program Files (x86)/Windows
                          Live/Shared:/c/Program Files/R/R-3.2.5/bin:/c/Program Files
                          (x86)/Zillya Antivirus:/c/WINDOWS/System32/OpenSSH:/c/ProgramData/choc
                          olatey/bin:/c/Program Files/IBM/Cloud/bin:/c/Program Files
                          (x86)/NVIDIA Corporation/PhysX/Common:/c/Program Files/Git/cmd:/c/Stra
                          wberry/c/bin:/c/Strawberry/perl/site/bin:/c/Strawberry/perl/bin:/c/WIN
                          DOWS/system32:/c/WINDOWS:/c/WINDOWS/System32/Wbem:/c/WINDOWS/System32/
                          WindowsPowerShell/v1.0:/c/WINDOWS/System32/OpenSSH:/c/ProgramData/nvm:
                          /c/Program Files/nodejs:/c/Program Files/dotnet:/c/Go/bin:/c/Program
                          Files (x86)/Yarn/bin:/c/Program Files/Microsoft VS Code/bin:/c/VLZ/Pyt
                          hon36/Scripts:/c/VLZ/Python36:/c/VLZ/Python36/Library/bin:/c/Program F
                          iles/Java/jdk1.8.0_40/bin:/c/WINDOWS/system32:/c/Users/VLZ/AppData/Roa
                          ming:/c/Users/VLZ/AppData/Local/hyper/app-2.0.0/resources/bin:/c/Progr
                          am Files/snap/bin:/c/Users/VLZ/AppData/Local/Microsoft/WindowsApps:/c/
                          Users/VLZ/go/bin:/c/Users/VLZ/AppData/Local/Yarn/bin
       REQUESTS_CA_BUNDLE=<not set>
            SSL_CERT_FILE=<not set>

     active environment : ocli
    active env location : /home/vlz/miniconda3/envs/ocli
            shell level : 1
       user config file : /home/vlz/.condarc
 populated config files : /home/vlz/.condarc
          conda version : 4.7.5
    conda-build version : not installed
         python version : 3.6.7.final.0
       virtual packages :
       base environment : /home/vlz/miniconda3  (writable)
           channel URLs : https://conda.anaconda.org/conda-forge/linux-64
                          https://conda.anaconda.org/conda-forge/noarch
                          https://repo.anaconda.com/pkgs/main/linux-64
                          https://repo.anaconda.com/pkgs/main/noarch
                          https://repo.anaconda.com/pkgs/r/linux-64
                          https://repo.anaconda.com/pkgs/r/noarch
          package cache : /home/vlz/miniconda3/pkgs
                          /home/vlz/.conda/pkgs
       envs directories : /home/vlz/miniconda3/envs
                          /home/vlz/.conda/envs
               platform : linux-64
             user-agent : conda/4.7.5 requests/2.22.0 CPython/3.6.7 Linux/4.4.0-18362-Microsoft ubuntu/18.04.2 glibc/2.27
                UID:GID : 1000:1000
             netrc file : None
           offline mode : False
```

IMHO conda searches eggs in ` AssertionError: ('lib/python3.6/site-packages/ocli-sarpy.egg-link', ['ocli.sarpy.egg-info', 'ocli_sarpy.egg-info'])
`
but pip  made them locally, 
```
(ocli) ➜  sarpy pwd
/c/VLZ/oDesk/taras/src/IBM/sarpy
(ocli) ➜  sarpy ll
total 4.0K
drwxr-xr-x 1 vlz vlz  512 Jul 15 15:20 ocli
drwxrwxrwx 1 vlz vlz  512 Jul  5 17:03 ocli.sarpy.egg-info
drwxrwxrwx 1 vlz vlz  512 Jul 18 12:37 ocli_sarpy.egg-info
-rwxr--r-- 1 vlz vlz  468 Jul  5 14:35 sarpy.iml
-rwxr--r-- 1 vlz vlz 1.4K Jul 16 01:55 setup.py
-rwxr--r-- 1 vlz vlz  383 Jul  6 00:46 test.sh
```
important note - I'm using Windows-10 and conda runs in WSL
```shell
(ocli) ➜  sarpy ll /home/vlz/miniconda3/envs/ocli/lib/python3.6/site-packages/ocli-sarpy.egg-link
-rw-rw-rw- 1 vlz vlz 34 Jul 18 12:37 /home/vlz/miniconda3/envs/ocli/lib/python3.6/site-packages/ocli-sarpy.egg-link
(ocli) ➜  sarpy cat /home/vlz/miniconda3/envs/ocli/lib/python3.6/site-packages/ocli-sarpy.egg-link
/c/VLZ/oDesk/taras/src/IBM/sarpy
.%
```

updating conda to `conda version : 4.7.8` doesn't helps
I also have this problem on Mac with conda 4.7.7.
I had this on 4.7.8, seems to be gone with 4.7.10.
I have this issue with conda 4.7.10 on Linux.  In my case, the packages are my own local ones, installed via `python setup.py develop`.  This places an egg-link in the `site-packages` directory which points to my working directory. 
Also not fixed by updating (4.7.5 -> 4.7.10). But AFAICT my situation was the same as https://github.com/conda/conda/issues/8948#issuecomment-512743235: multiple left-over `*.egg-info` directories in the target of the `egg-link`. Debugging steps if someone wants to dig in and verify. This is w/ conda 4.7.10

- make a backup copy to be restored, so conda doesn't complain about hashes later
```
cp $CONDA_BASE/lib/python3.7/site-packages/conda/common/pkg_formats/python.py $CONDA_BASE/lib/python3.7/site-packages/conda/common/pkg_formats/python.py.bk
```
- set a breakpoint 
```
diff $CONDA_BASE/lib/python3.7/site-packages/conda/common/pkg_formats/python.py $CONDA_BASE/lib/python3.7/site-packages/conda/common/pkg_formats/python.py.bk
914,915c914
<
<     import pdb; pdb.set_trace()
---
>
```
- run `conda list`
- print the relevant variables
```
conda list
> /Users/inorton/mc3/lib/python3.7/site-packages/conda/common/pkg_formats/python.py(916)get_dist_file_from_egg_link()
-> if egg_info_fnames:
(Pdb) list
911  	        egg_info_fnames = fnmatch_filter(listdir(egg_link_contents), '*.egg-info')
912  	    else:
913  	        egg_info_fnames = ()
914
915  	    import pdb; pdb.set_trace()
916  ->	    if egg_info_fnames:
917  	        assert len(egg_info_fnames) == 1, (egg_link_file, egg_info_fnames)
918  	        egg_info_full_path = join(egg_link_contents, egg_info_fnames[0])
919
920  	        if isdir(egg_info_full_path):
921  	            egg_info_full_path = join(egg_info_full_path, "PKG-INFO")
(Pdb) p egg_info_fnames
['tiledb.egg-info', 'tiledb_py.egg-info']
(Pdb) p egg_link_contents
'/Users/inorton/work/git/TileDB-Py'
(Pdb)
```
- contents of that directory (`ls`) included
```
...
tiledb.egg-info
tiledb_py.egg-info
...
```

(due to some `setup.py` mods I had been testing on a branch and forgot to clean the directory)

- removing `tiledb_py.egg-info` resolved the issue reported above.

So ... not really a conda problem, as in both my case and https://github.com/conda/conda/issues/8948#issuecomment-512743235 we were both violating the `egg-link`/`egg-info` protocol by having multiple `egg-info`s in one directory.

Conda could print a more helpful error if the assertion is violated, but that's probably about it...

(don't forget to restore the .bk file above, and/or remove the pdb line)

Resolving patch:
diff --git a/conda/common/pkg_formats/python.py b/conda/common/pkg_formats/python.py
--- a/conda/common/pkg_formats/python.py
+++ b/conda/common/pkg_formats/python.py
@@ -17,6 +17,7 @@
 import sys
 import warnings
 
+from ... import CondaError
 from ..compat import PY2, StringIO, itervalues, odict, open, string_types
 from ..path import (
     get_python_site_packages_short_path, pyc_path, win_path_ok, get_major_minor_version,
@@ -913,7 +914,14 @@ def get_dist_file_from_egg_link(egg_link_file, prefix_path):
         egg_info_fnames = ()
 
     if egg_info_fnames:
-        assert len(egg_info_fnames) == 1, (egg_link_file, egg_info_fnames)
+        if len(egg_info_fnames) != 1:
+            raise CondaError(
+                    "Expected exactly one `egg-info` directory in '{}', via egg-link '{}'."
+                    " Instead found: {}.  These are often left over from "
+                    "legacy operations that did not clean up correctly.  Please "
+                    "remove all but one of these.".format(egg_link_contents,
+                    egg_link_file, egg_info_fnames))
+
         egg_info_full_path = join(egg_link_contents, egg_info_fnames[0])
 
         if isdir(egg_info_full_path):


Test patch: