Repository: conda/conda

Issue:
KeyError: 'python' when installing Python package.
## Current Behavior



### Steps to Reproduce

Our script does the following;

```
	wget --no-verbose --continue https://repo.continuum.io/miniconda/Miniconda3-latest-Linux-x86_64.sh
	chmod a+x Miniconda3-latest-Linux-x86_64.sh
	# -p to specify the install location
	# -b to enable batch mode (no prompts)
	# -f to not return an error if the location specified by -p already exists
	(
		export HOME=$CONDA_DIR
		./Miniconda3-latest-Linux-x86_64.sh -p $CONDA_DIR -b -f || exit 1
	)
	conda config --system --set always_yes yes
	conda config --system --set changeps1 no
	conda config --system --add envs_dirs $CONDA_DIR/envs
	conda config --system --add pkgs_dirs $CONDA_DIR/pkgs
	conda update -q conda
	conda config --system --add channels timvideos
	conda info
	echo "python ==${PYTHON_VERSION}" > $CONDA_DIR/conda-meta/pinned # Make sure it stays at given version
	conda install -y python=3.7
```


## Expected Behavior

conda installs Python 3.7

## Environment Information
<details open><summary><code>`conda info`</code></summary><p>
<!-- between the ticks below, paste the output of 'conda info' -->

```
     active environment : None
       user config file : /home/travis/.condarc
 populated config files : /home/travis/build/mithro/litex-buildenv/build/conda/.condarc
          conda version : 4.7.5
    conda-build version : not installed
         python version : 3.7.3.final.0
       virtual packages : 
       base environment : /home/travis/build/mithro/litex-buildenv/build/conda  (writable)
           channel URLs : https://conda.anaconda.org/timvideos/linux-64
                          https://conda.anaconda.org/timvideos/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/travis/build/mithro/litex-buildenv/build/conda/pkgs
       envs directories : /home/travis/build/mithro/litex-buildenv/build/conda/envs
                          /home/travis/build/mithro/litex-buildenv/build/conda/.conda/envs
               platform : linux-64
             user-agent : conda/4.7.5 requests/2.21.0 CPython/3.7.3 Linux/4.4.0-101-generic ubuntu/14.04.5 glibc/2.19
                UID:GID : 2000:2000
             netrc file : None
           offline mode : False
              Platform: arty
                Target: net (default: net)
                   CPU: lm32 (default: lm32)
Installing python3.7
Collecting package metadata (current_repodata.json): done
Solving environment: failed
# >>>>>>>>>>>>>>>>>>>>>> ERROR REPORT <<<<<<<<<<<<<<<<<<<<<<
    Traceback (most recent call last):
      File "/home/travis/build/mithro/litex-buildenv/build/conda/lib/python3.7/site-packages/conda/exceptions.py", line 1043, in __call__
        return func(*args, **kwargs)
      File "/home/travis/build/mithro/litex-buildenv/build/conda/lib/python3.7/site-packages/conda/cli/main.py", line 84, in _main
        exit_code = do_call(args, p)
      File "/home/travis/build/mithro/litex-buildenv/build/conda/lib/python3.7/site-packages/conda/cli/conda_argparse.py", line 82, in do_call
        exit_code = getattr(module, func_name)(args, parser)
      File "/home/travis/build/mithro/litex-buildenv/build/conda/lib/python3.7/site-packages/conda/cli/main_install.py", line 20, in execute
        install(args, parser, 'install')
      File "/home/travis/build/mithro/litex-buildenv/build/conda/lib/python3.7/site-packages/conda/cli/install.py", line 280, in install
        force_reinstall=context.force_reinstall or context.force,
      File "/home/travis/build/mithro/litex-buildenv/build/conda/lib/python3.7/site-packages/conda/core/solve.py", line 112, in solve_for_transaction
        force_remove, force_reinstall)
      File "/home/travis/build/mithro/litex-buildenv/build/conda/lib/python3.7/site-packages/conda/core/solve.py", line 150, in solve_for_diff
        force_remove)
      File "/home/travis/build/mithro/litex-buildenv/build/conda/lib/python3.7/site-packages/conda/core/solve.py", line 245, in solve_final_state
        ssc = self._add_specs(ssc)
      File "/home/travis/build/mithro/litex-buildenv/build/conda/lib/python3.7/site-packages/conda/core/solve.py", line 515, in _add_specs
        elif explicit_pool[s.name] & self._get_package_pool(ssc, [s])[s.name]:
    KeyError: 'python'
`$ /home/travis/build/mithro/litex-buildenv/build/conda/bin/conda install -y python=3.7`
  environment variables:
                 CIO_TEST=<not set>
               CONDA_ROOT=/home/travis/build/mithro/litex-buildenv/build/conda
                 GEM_PATH=/home/travis/.rvm/gems/ruby-2.4.1:/home/travis/.rvm/gems/ruby-2.4.1@gl
                          obal
                   GOPATH=/home/travis/gopath
                  MANPATH=/home/travis/.nvm/versions/node/v8.9.1/share/man:/home/travis/.kiex/el
                          ixirs/elixir-1.4.5/man:/home/travis/.rvm/rubies/ruby-2.4.1/share/man:/
                          usr/local/man:/usr/local/cmake-3.9.2/man:/usr/local/clang-5.0.0/share/
                          man:/usr/local/share/man:/usr/share/man:/home/travis/.rvm/man
                     PATH=/home/travis/build/mithro/litex-buildenv/build/conda/bin:/home/travis/
                          bin:/home/travis/.local/bin:/opt/pyenv/shims:/home/travis/.phpenv/shim
                          s:/home/travis/perl5/perlbrew/bin:/home/travis/.nvm/versions/node/v8.9
                          .1/bin:/home/travis/.kiex/elixirs/elixir-1.4.5/bin:/home/travis/.kiex/
                          bin:/home/travis/.rvm/gems/ruby-2.4.1/bin:/home/travis/.rvm/gems/ruby-
                          2.4.1@global/bin:/home/travis/.rvm/rubies/ruby-2.4.1/bin:/home/travis/
                          gopath/bin:/home/travis/.gimme/versions/go1.7.4.linux.amd64/bin:/usr/l
                          ocal/phantomjs/bin:/usr/local/phantomjs:/usr/local/neo4j-3.2.7/bin:/us
                          r/local/maven-3.5.2/bin:/usr/local/cmake-3.9.2/bin:/usr/local/clang-5.
                          0.0/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/
                          home/travis/.rvm/bin:/home/travis/.phpenv/bin:/opt/pyenv/bin:/home/tra
                          vis/.yarn/bin:/sbin
           PYTHONHASHSEED=0
            PYTHON_CFLAGS=-g -fstack-protector --param=ssp-buffer-size=4 -Wformat
                          -Werror=format-security
    PYTHON_CONFIGURE_OPTS=--enable-unicode=ucs4 --with-wide-unicode --enable-shared --enable-
                          ipv6 --enable-loadable-sqlite-extensions --with-computed-gotos
       REQUESTS_CA_BUNDLE=<not set>
            SSL_CERT_FILE=<not set>
         TRAVIS_APT_PROXY=<set>
             rvm_bin_path=/home/travis/.rvm/bin
                 rvm_path=/home/travis/.rvm
     active environment : None
       user config file : /home/travis/.condarc
 populated config files : /home/travis/build/mithro/litex-buildenv/build/conda/.condarc
          conda version : 4.7.5
    conda-build version : not installed
         python version : 3.7.3.final.0
       virtual packages : 
       base environment : /home/travis/build/mithro/litex-buildenv/build/conda  (writable)
           channel URLs : https://conda.anaconda.org/timvideos/linux-64
                          https://conda.anaconda.org/timvideos/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/travis/build/mithro/litex-buildenv/build/conda/pkgs
       envs directories : /home/travis/build/mithro/litex-buildenv/build/conda/envs
                          /home/travis/build/mithro/litex-buildenv/build/conda/.conda/envs
               platform : linux-64
             user-agent : conda/4.7.5 requests/2.21.0 CPython/3.7.3 Linux/4.4.0-101-generic ubuntu/14.04.5 glibc/2.19
                UID:GID : 2000:2000
             netrc file : None
           offline mode : False
An unexpected error has occurred. Conda has prepared the above report.
```
</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' -->

```

```
</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' -->

```

```
</p></details>



Discussion:
Example log output can be found at https://travis-ci.com/mithro/litex-buildenv/jobs/211878372

Resolving patch:
diff --git a/conda/core/solve.py b/conda/core/solve.py
--- a/conda/core/solve.py
+++ b/conda/core/solve.py
@@ -501,7 +501,7 @@ def _add_specs(self, ssc):
             if s.name in explicit_pool:
                 if s.name not in self.specs_to_add_names and not ssc.ignore_pinned:
                     ssc.specs_map[s.name] = MatchSpec(s, optional=False)
-                elif explicit_pool[s.name] & ssc.r._get_package_pool([s])[s.name]:
+                elif explicit_pool[s.name] & ssc.r._get_package_pool([s]).get(s.name, set()):
                     ssc.specs_map[s.name] = MatchSpec(s, optional=False)
                     pin_overrides.add(s.name)
                 else:


Test patch:
diff --git a/tests/test_create.py b/tests/test_create.py
--- a/tests/test_create.py
+++ b/tests/test_create.py
@@ -1051,6 +1051,13 @@ def test_update_with_pinned_packages(self):
             assert package_is_installed(prefix, "python=2.7")
             assert not package_is_installed(prefix, "python=2.7.12")
 
+    def test_pinned_override_with_explicit_spec(self):
+        with make_temp_env("python=3.6") as prefix:
+            run_command(Commands.CONFIG, prefix,
+                        "--add", "pinned_packages", "python=3.6.5")
+            run_command(Commands.INSTALL, prefix, "python=3.7", no_capture=True)
+            assert package_is_installed(prefix, "python=3.7")
+
     def test_remove_all(self):
         with make_temp_env("python") as prefix:
             assert exists(join(prefix, PYTHON_BINARY))