Repository: conda/conda

Issue:
inconsistent environment warning breaks --json
<!--
Anaconda Community Code of Conduct: https://www.anaconda.com/community-code-of-conduct/
-->

## Current Behavior

The ["environment is inconsistent"](https://github.com/conda/conda/blob/e9a50561880696e57ba80472dce332e08e58ee0b/conda/core/solve.py#L486-L489) warning goes to STDOUT and breaks `--json --dry-run` output.

Observed with an environment which works perfectly fine and also `conda install` (without `--dry-run`) succeeds without issues.

### Steps to Reproduce

```bash
conda create -y -n test python
conda activate test

# remove a non-essential package
conda uninstall -y --force readline

conda install --json --dry-run requests | json_verify
```
Output:
```
lexical error: invalid char in json text.
                                        The environment is inconsisten
                     (right here) ------^
JSON is invalid
```

## Expected Behavior

Valid JSON.

## Environment Information
<details open><summary><code>`conda info`</code></summary><p>
<!-- between the ticks below, paste the output of 'conda info' -->

```
     active environment : test
    active env location : /home/thomas/miniconda3/envs/test
            shell level : 2
       user config file : /home/thomas/.condarc
 populated config files : /home/thomas/.condarc
          conda version : 4.7.12
    conda-build version : 3.18.11
         python version : 3.7.1.final.0
       virtual packages : __cuda=10.2
       base environment : /home/thomas/miniconda3  (writable)
           channel URLs : https://repo.anaconda.com/pkgs/main/linux-64
                          https://repo.anaconda.com/pkgs/main/noarch
          package cache : /home/thomas/miniconda3/pkgs
                          /home/thomas/.conda/pkgs
       envs directories : /home/thomas/miniconda3/envs
                          /home/thomas/.conda/envs
               platform : linux-64
             user-agent : conda/4.7.12 requests/2.22.0 CPython/3.7.1 Linux/5.5.4-arch1-1 arch/rolling glibc/2.31
                UID:GID : 1000:100
             netrc file : /home/thomas/.netrc
           offline mode : False
```
</p></details>


<details open><summary><code>`conda config --show-sources`</code></summary><p>
<!-- between the ticks below, paste the output of 'conda config --show-sources' -->

```
==> /home/thomas/.condarc <==
auto_update_conda: False
ssl_verify: True
default_channels:
  - https://repo.anaconda.com/pkgs/main
anaconda_upload: False
```
</p></details>


<details><summary><code>`conda list --show-channel-urls`</code></summary><p>
<!-- between the ticks below, paste the output of 'conda list --show-channel-urls' -->

```
# packages in environment at /home/thomas/miniconda3/envs/test:
#
# Name                    Version                   Build  Channel
_libgcc_mutex             0.1                        main    defaults
ca-certificates           2020.1.1                      0    defaults
certifi                   2019.11.28               py38_0    defaults
ld_impl_linux-64          2.33.1               h53a641e_7    defaults
libedit                   3.1.20181209         hc058e9b_0    defaults
libffi                    3.2.1                hd88cf55_4    defaults
libgcc-ng                 9.1.0                hdf63c60_0    defaults
libstdcxx-ng              9.1.0                hdf63c60_0    defaults
ncurses                   6.2                  he6710b0_0    defaults
openssl                   1.1.1d               h7b6447c_4    defaults
pip                       20.0.2                   py38_1    defaults
python                    3.8.1                h0371630_1    defaults
setuptools                45.2.0                   py38_0    defaults
sqlite                    3.31.1               h7b6447c_0    defaults
tk                        8.6.8                hbc83047_0    defaults
wheel                     0.34.2                   py38_0    defaults
xz                        5.2.4                h14c3975_4    defaults
zlib                      1.2.11               h7b6447c_3    defaults
```
</p></details>



Discussion:

Resolving patch:
diff --git a/conda/core/solve.py b/conda/core/solve.py
--- a/conda/core/solve.py
+++ b/conda/core/solve.py
@@ -485,8 +485,8 @@ def _find_inconsistent_packages(self, ssc):
         if inconsistent_precs:
             print(dedent("""
             The environment is inconsistent, please check the package plan carefully
-            The following packages are causing the inconsistency:"""))
-            print(dashlist(inconsistent_precs))
+            The following packages are causing the inconsistency:"""), file=sys.stderr)
+            print(dashlist(inconsistent_precs), file=sys.stderr)
             for prec in inconsistent_precs:
                 # pop and save matching spec in specs_map
                 spec = ssc.specs_map.pop(prec.name, None)


Test patch:
diff --git a/tests/test_create.py b/tests/test_create.py
--- a/tests/test_create.py
+++ b/tests/test_create.py
@@ -2138,8 +2138,10 @@ def test_conda_recovery_of_pip_inconsistent_env(self):
             rc = p.returncode
             assert int(rc) == 0
 
-            stdout, stderr, _ = run_command(Commands.INSTALL, prefix, 'imagesize')
-            assert not stderr
+            stdout, stderr, _ = run_command(Commands.INSTALL, prefix, 'imagesize', '--json')
+            assert json.loads(stdout)['success']
+            assert "The environment is inconsistent" in stderr
+
             stdout, stderr, _ = run_command(Commands.LIST, prefix, '--json')
             pkgs = json.loads(stdout)
             for entry in pkgs: