Repository: conda/conda

Issue:
Trivial pip subsection breaks conda env create
I observe that an empty-but-present pip subsection under dependencies breaks `conda env create`.  I expect this command to run as if the `- pip:` subsection was not present.

```
$ cat environment.yml 
dependencies:
- pip:

$ conda env create -n recreate --file=environment.yml
Fetching package metadata ...........
Solving package specifications: 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.3.13
       conda is private : False
      conda-env version : 4.3.13
    conda-build version : 2.1.5
         python version : 3.5.2.final.0
       requests version : 2.13.0
       root environment : /opt/ts/services/miniconda.ext_public_miniconda/dist  (read only)
    default environment : /opt/ts/services/miniconda.ext_public_miniconda/dist
       envs directories : /nas/dft/ire/rhys/envs
                          /opt/ts/services/miniconda.ext_public_miniconda/dist/envs
                          /home/rhys/.conda/envs
          package cache : /opt/ts/services/miniconda.ext_public_miniconda/dist/pkgs
                          /home/rhys/.conda/pkgs
           channel URLs : http://python3.app.twosigma.com/conda/twosigma.com/ts/linux-64
                          http://python3.app.twosigma.com/conda/twosigma.com/ts/noarch
                          http://python3.app.twosigma.com/conda/twosigma.com/ext/linux-64
                          http://python3.app.twosigma.com/conda/twosigma.com/ext/noarch
                          http://python3.app.twosigma.com/conda/repo.continuum.io/pkgs/free/linux-64
                          http://python3.app.twosigma.com/conda/repo.continuum.io/pkgs/free/noarch
                          http://python3.app.twosigma.com/conda/repo.continuum.io/pkgs/pro/linux-64
                          http://python3.app.twosigma.com/conda/repo.continuum.io/pkgs/pro/noarch
            config file : /home/rhys/.condarc
           offline mode : False
             user-agent : conda/4.3.13 requests/2.13.0 CPython/3.5.2 Linux/4.1.35-pv-ts2 debian/7.10 glibc/2.13
                UID:GID : 11082:5000

`$ /opt/ts/services/miniconda.ext_public_miniconda/dist/bin/conda-env create -n recreate --file=environment.yml`

    Traceback (most recent call last):
      File "/opt/ts/services/miniconda.ext_public_miniconda/dist/lib/python3.5/site-packages/conda/exceptions.py", line 591, in conda_exception_handler
        return_value = func(*args, **kwargs)
      File "/opt/ts/services/miniconda.ext_public_miniconda/dist/lib/python3.5/site-packages/conda_env/cli/main_create.py", line 108, in execute
        installer.install(prefix, pkg_specs, args, env)
      File "/opt/ts/services/miniconda.ext_public_miniconda/dist/lib/python3.5/site-packages/conda_env/installers/pip.py", line 8, in install
        pip_cmd = pip_args(prefix) + ['install', ] + specs
    TypeError: unsupported operand type(s) for +: 'NoneType' and 'list'
```


Discussion:
Same here, that's because `pip_args` [returns `None`](https://github.com/conda/conda/blob/master/conda_env/pip_util.py#L38) when pip is not installed; While it's actually used find the [pip command and chains it with arguments](https://github.com/conda/conda/blob/master/conda_env/installers/pip.py#L40). 

These seem to be used in [main_create](https://github.com/conda/conda/blob/master/conda_env/cli/main_update.py#L107) and [main_update](https://github.com/conda/conda/blob/master/conda_env/cli/main_update.py#L107) without proper checking (or requirement) for the installer to be available.
Can you verify that this is still a bug as of conda 4.3.30?  4.3.13 is very old at this point.
> Can you verify that this is still a bug as of conda 4.3.30? 4.3.13 is very old at this point.

Sorry , I tested on the latest without saying it; 

```
$ conda env create -n whatever -f foo.yml
Using Anaconda API: https://api.anaconda.org
Fetching package metadata .............
Solving package specifications: .
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 : osx-64
          conda version : 4.3.30
       conda is private : False
      conda-env version : 4.3.30
    conda-build version : 2.1.17
         python version : 3.6.3.final.0
       requests version : 2.18.4
       root environment : /Users/bussonniermatthias/anaconda  (writable)
    default environment : /Users/bussonniermatthias/anaconda
       envs directories : /Users/bussonniermatthias/anaconda/envs
                          /Users/bussonniermatthias/.conda/envs
          package cache : /Users/bussonniermatthias/anaconda/pkgs
                          /Users/bussonniermatthias/.conda/pkgs
           channel URLs : https://conda.anaconda.org/conda-forge/osx-64
                          https://conda.anaconda.org/conda-forge/noarch
                          https://repo.continuum.io/pkgs/main/osx-64
                          https://repo.continuum.io/pkgs/main/noarch
                          https://repo.continuum.io/pkgs/free/osx-64
                          https://repo.continuum.io/pkgs/free/noarch
                          https://repo.continuum.io/pkgs/r/osx-64
                          https://repo.continuum.io/pkgs/r/noarch
                          https://repo.continuum.io/pkgs/pro/osx-64
                          https://repo.continuum.io/pkgs/pro/noarch
            config file : /Users/bussonniermatthias/.condarc
             netrc file : /Users/bussonniermatthias/.netrc
           offline mode : False
             user-agent : conda/4.3.30 requests/2.18.4 CPython/3.6.3 Darwin/16.7.0 OSX/10.12.6
                UID:GID : 501:20

`$ /Users/bussonniermatthias/anaconda/bin/conda-env create -n whatever -f foo.yml`

    Traceback (most recent call last):
      File "/Users/bussonniermatthias/anaconda/lib/python3.6/site-packages/conda/exceptions.py", line 640, in conda_exception_handler
        return_value = func(*args, **kwargs)
      File "/Users/bussonniermatthias/anaconda/lib/python3.6/site-packages/conda_env/cli/main_create.py", line 108, in execute
        installer.install(prefix, pkg_specs, args, env)
      File "/Users/bussonniermatthias/anaconda/lib/python3.6/site-packages/conda_env/installers/pip.py", line 8, in install
        pip_cmd = pip_args(prefix) + ['install', ] + specs
    TypeError: unsupported operand type(s) for +: 'NoneType' and 'list'

$ cat foo.yml
name: whatever
channels:
  - conda-forge
dependencies:
- python=3.6
- ipython
#- pip # uncomment and it works
- pip:
  - toml
```

The example I give for env.yml is the the trivial one (just to make sure install still works), but the reason is the same; the place I linked to in my previous comment don't check for None (hence the crash), and arguably `pip_args` should maybe also be type stable. 

Same thing happen with updating an env. 

Also, please consider making pip a default package. The number of users that 
```
$ conda create env
$ source activate env
(env) $ pip install <whatever> 
```

And don't understand why whatever is not working is large. Even I, who know what' going on get confused sometime; At least inject a fake `pip` executabe that just return a status of -1 and print "please conda install pip". 





Resolving patch:
diff --git a/conda_env/cli/main_create.py b/conda_env/cli/main_create.py
--- a/conda_env/cli/main_create.py
+++ b/conda_env/cli/main_create.py
@@ -110,7 +110,7 @@ def execute(args, parser):
             sys.stderr.write(textwrap.dedent("""
                 Unable to install package for {0}.
 
-                Please double check and ensure you dependencies file has
+                Please double check and ensure your dependencies file has
                 the correct spelling.  You might also try installing the
                 conda-env-{0} package to see if provides the required
                 installer.
diff --git a/conda_env/env.py b/conda_env/env.py
--- a/conda_env/env.py
+++ b/conda_env/env.py
@@ -9,6 +9,7 @@
 from conda.cli import common  # TODO: this should never have to import form conda.cli
 from conda.common.serialize import yaml_load
 from conda.core.linked_data import linked
+from conda.models.match_spec import MatchSpec
 from conda_env.yaml import dump
 from . import compat, exceptions, yaml
 from .pip_util import add_pip_installed
@@ -102,6 +103,12 @@ def parse(self):
             else:
                 self['conda'].append(common.arg2spec(line))
 
+        if 'pip' in self:
+            if not self['pip']:
+                del self['pip']
+            if not any(MatchSpec(s).name == 'pip' for s in self['conda']):
+                self['conda'].append('pip')
+
     # TODO only append when it's not already present
     def add(self, package_name):
         self.raw.append(package_name)


Test patch:
diff --git a/tests/conda_env/test_env.py b/tests/conda_env/test_env.py
--- a/tests/conda_env/test_env.py
+++ b/tests/conda_env/test_env.py
@@ -90,7 +90,7 @@ def test_other_tips_of_dependencies_are_supported(self):
             dependencies=['nltk', {'pip': ['foo', 'bar']}]
         )
         expected = OrderedDict([
-            ('conda', ['nltk']),
+            ('conda', ['nltk', 'pip']),
             ('pip', ['foo', 'bar'])
         ])
         self.assertEqual(e.dependencies, expected)