Repository: conda/conda

Issue:
conda-env 4.2.9 still says to install 'binstar'
# Is this a big deal?

First, this seems like something minor that I could get in and submit a PR to fix.  This isn't going to kill anyone, it's just a minor annoyance that could be cleaned up.

I'm sorry if this is already a ticket.  I tried searching but _whow_ you guys have a lot of tickets!  This is a simple fix that I'll try to come back and submit a PR for if I get the chance.  If I file the ticket, I'll be able to find it again for my PR.
# Steps to Reproduce
1. Do a clean miniconda install
2. `conda update --all` to get the latest of all the things
3. `conda env create tsnyder/python_training_2016_10`
   - Refers to https://anaconda.org/tsnyder/python_training_2016_10
# Expected output

Something minimal and graceful that says something like 

> Hey guy. I don't know what `tsnyder/python_training_2016_10` is but I also don't have my buddy `anaconda-client` installed.  Please run `conda install anaconda-client` and have an Anaconda Day 🐍 

would be nice.
# What I got

```
Windows PowerShell
Copyright (C) 2009 Microsoft Corporation. All rights reserved.

PS C:\Users\tsnyder> which conda
C:\Users\tsnyder\Miniconda3\Scripts\conda.EXE
PS C:\Users\tsnyder> conda list
# packages in environment at C:\Users\tsnyder\Miniconda3:
#
conda                     4.1.11                   py35_0
conda-env                 2.5.2                    py35_0
console_shortcut          0.1.1                    py35_1
menuinst                  1.4.1                    py35_0
pip                       8.1.2                    py35_0
pycosat                   0.6.1                    py35_1
pycrypto                  2.6.1                    py35_4
python                    3.5.2                         0
pyyaml                    3.11                     py35_4
requests                  2.10.0                   py35_0
ruamel_yaml               0.11.14                  py35_0
setuptools                23.0.0                   py35_0
vs2015_runtime            14.0.25123                    0
wheel                     0.29.0                   py35_0
PS C:\Users\tsnyder> conda update --all
Fetching package metadata .........
Solving package specifications: ..........

Package plan for installation in environment C:\Users\tsnyder\Miniconda3:

The following packages will be downloaded:

    package                    |            build
    ---------------------------|-----------------
    conda-env-2.6.0            |                0          498 B
    menuinst-1.4.2             |           py35_0         107 KB
    pyyaml-3.12                |           py35_0         118 KB
    requests-2.11.1            |           py35_0         665 KB
    setuptools-27.2.0          |           py35_1         761 KB
    conda-4.2.9                |           py35_0         428 KB
    ------------------------------------------------------------
                                           Total:         2.0 MB

The following packages will be UPDATED:

    conda:      4.1.11-py35_0 --> 4.2.9-py35_0
    conda-env:  2.5.2-py35_0  --> 2.6.0-0
    menuinst:   1.4.1-py35_0  --> 1.4.2-py35_0
    pyyaml:     3.11-py35_4   --> 3.12-py35_0
    requests:   2.10.0-py35_0 --> 2.11.1-py35_0
    setuptools: 23.0.0-py35_0 --> 27.2.0-py35_1

Proceed ([y]/n)?

menuinst-1.4.2 100% |###############################| Time: 0:00:00 456.48 kB/s
Fetching packages ...
conda-env-2.6. 100% |###############################| Time: 0:00:00  71.13 kB/s
pyyaml-3.12-py 100% |###############################| Time: 0:00:00 541.10 kB/s
requests-2.11. 100% |###############################| Time: 0:00:00 885.09 kB/s
setuptools-27. 100% |###############################| Time: 0:00:00 976.23 kB/s
conda-4.2.9-py 100% |###############################| Time: 0:00:00 875.95 kB/s
Extracting packages ...
[      COMPLETE      ]|##################################################| 100%
Unlinking packages ...
[      COMPLETE      ]|##################################################| 100%
Linking packages ...
[      COMPLETE      ]|##################################################| 100%
PS C:\Users\tsnyder> conda env create -h
usage: conda-env-script.py create [-h] [-f FILE] [-n ENVIRONMENT | -p PATH]
                                  [-q] [--force] [--json] [--debug]
                                  [--verbose]
                                  [remote_definition]

Create an environment based on an environment file

Options:

positional arguments:
  remote_definition     remote environment definition / IPython notebook

optional arguments:
  -h, --help            Show this help message and exit.
  -f FILE, --file FILE  environment definition file (default: environment.yml)
  -n ENVIRONMENT, --name ENVIRONMENT
                        Name of environment (in
                        C:\Users\tsnyder\Miniconda3\envs).
  -p PATH, --prefix PATH
                        Full path to environment prefix (default:
                        C:\Users\tsnyder\Miniconda3).
  -q, --quiet
  --force               force creation of environment (removing a previously
                        existing environment of the same name).
  --json                Report all output as json. Suitable for using conda
                        programmatically.
  --debug               Show debug output.
  --verbose, -v         Use once for info, twice for debug.

examples:
    conda env create
    conda env create -n name
    conda env create vader/deathstar
    conda env create -f=/path/to/environment.yml
    conda env create -f=/path/to/requirements.txt -n deathstar
    conda env create -f=/path/to/requirements.txt -p /home/user/software/deathstar
PS C:\Users\tsnyder> conda env create tsnyder/python_training_2016_10
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 : win-64
          conda version : 4.2.9
       conda is private : False
      conda-env version : 4.2.9
    conda-build version : not installed
         python version : 3.5.2.final.0
       requests version : 2.11.1
       root environment : C:\Users\tsnyder\Miniconda3  (writable)
    default environment : C:\Users\tsnyder\Miniconda3
       envs directories : C:\Users\tsnyder\Miniconda3\envs
          package cache : C:\Users\tsnyder\Miniconda3\pkgs
           channel URLs : https://repo.continuum.io/pkgs/free/win-64/
                          https://repo.continuum.io/pkgs/free/noarch/
                          https://repo.continuum.io/pkgs/pro/win-64/
                          https://repo.continuum.io/pkgs/pro/noarch/
                          https://repo.continuum.io/pkgs/msys2/win-64/
                          https://repo.continuum.io/pkgs/msys2/noarch/
            config file : None
           offline mode : False



`$ C:\Users\tsnyder\Miniconda3\Scripts\conda-env-script.py create tsnyder/python_training_2016_10`




    Traceback (most recent call last):
      File "C:\Users\tsnyder\Miniconda3\lib\site-packages\conda\exceptions.py", line 473, in conda_exception_handler
        return_value = func(*args, **kwargs)
      File "C:\Users\tsnyder\Miniconda3\lib\site-packages\conda_env\cli\main_create.py", line 81, in execute
        directory=os.getcwd())
      File "C:\Users\tsnyder\Miniconda3\lib\site-packages\conda_env\specs\__init__.py", line 23, in detect
        raise SpecNotFound(build_message(specs))
    conda_env.exceptions.SpecNotFound: Runtime error: Please install binstar
    Please install nbformat:
        conda install nbformat
    Conda Env Exception: environment.yml file not found
    There is no requirements.txt
```
# What to fix?
1. This shouldn't be an "unexpected" error.  If `conda env create` takes a positional parameter named `remote_definiton` and you don't have the remote client installed, that should be an expected error that has a cleaner message.   Something that says `'{} could not be resolved but you do not have the remote client installed.  Please install {}'.format(remote_definition, remote_client)` might be appropriate.
2. It shouldn't be suggesting to install `binstar` anymore.  I vaguely remember that the latest `binstar` says "Don't use me anymore" but the UX would be nicer if we didn't send people down that road.
# How did I run into this?

I'm prepping my userbase for a course that @msarahan is going to be teaching them next week.  I'll be advising them to use our Wakari Enterprise install or JupyterHub or ipython in a central environment that I have setup for the purpose of this course.  However, I do want to let people know how easy it is to get Anaconda python working on their own systems.  So, I'm putting together the instructions on how to do a clean install of miniconda + the environment they need.  Since I want to show off Anaconda Repo, I'm trying to do `conda env create` with a `remote_definition` for the first time and noticed the exception mentions installing `binstar`.



Discussion:
Awesome bug report. Which all of them were this detailed.  We also accept pull requests 😁 

We'll try to get it into a 4.3 release regardless.

@nehaljwani Since you have some history here on several of the issues I linked above, do you want to take a stab at fixing this once and for all?  It's a bug, so should target 4.3.x.
@kalefranz In all of the issues linked above, I think the reporters always started with keeping their environment files in unexpected locations like `/path/to/conda_installation/envs` or `$CONDA_PREFIX/bin` or just had them in their `Downloads` folder and expected conda to magically find it.

Asking the reporters to provide the complete path to the environment.yml file seemed easier than explaining them to use relative paths correctly (../ vs ..\\) or placing the file in the current directory (they may respawn the prompt and end up changing directory to somewhere else)

I have never been able to reproduce this stack trace on Linux or Windows when the environment.yml file is correctly pointed to, whether it is a relative path or absolute path or just kept in the current directory. The code flow triggers the `from_file()` function at https://github.com/conda/conda/blob/master/conda_env/env.py#L75-L77 and seems correct to me since there doesn't seem to be any call to `os.chdir()` in between. So I don't think `os.path.join(os.getcwd(), args.file)` is really needed here.
```
(root) C:\Users\nwani>notepad env.yml

(root) C:\Users\nwani>type env.yml
name: python_training_2016_10
dependencies:
 - python=3.4
 - jupyter
 - numpy
 - future
 - matplotlib
 - scipy
 - pillow
 - bokeh
 - scikit-learn
 - xlrd
 - h5py
 - lxml
 - openpyxl
 - xlwt
 - cython
 - numba
 - cffi
 - line_profiler
 - netcdf4
 - blaze
 - dask
 - seaborn
 - html5lib
 - beautifulsoup4
 - nltk
 - memory_profiler

(root) C:\Users\nwani>conda env create -f env.yml
Fetching package metadata ...........
Solving package specifications: .
mkl-2017.0.1-0  52% |################               | ETA:  0:00:05  10.85 MB/s
...
```
Also, (I may be wrong, but ...) this particular GH issue is trying to point out something else. I think the OP is trying to say that when `anaconda-client` is not installed, instead of the error message being:
```
(root) ubuntu@condaexpts:~$ conda env create tsnyder/python_training_2016_10
SpecNotFound: Please install binstar
Please install nbformat:
	conda install nbformat
Conda Env Exception: environment.yml file not found
There is no requirements.txt
```
It should say something like (which can be done by `raise exceptions.NoBinstar()`):
```
(root) ubuntu@condaexpts:~$ conda env create tsnyder/python_training_2016_10
The anaconda-client cli must be installed to perform this action
```
Sounds like I've basically flubbed up the whole entire issue!  Glad you corrected everything @nehaljwani  :)

Resolving patch:
diff --git a/conda_env/specs/__init__.py b/conda_env/specs/__init__.py
--- a/conda_env/specs/__init__.py
+++ b/conda_env/specs/__init__.py
@@ -24,4 +24,8 @@ def detect(**kwargs):
 
 
 def build_message(specs):
-    return "\n".join([s.msg for s in specs if s.msg is not None])
+    binstar_spec = next((spec for spec in specs if isinstance(spec, BinstarSpec)), None)
+    if binstar_spec:
+        return binstar_spec.msg
+    else:
+        return "\n".join([s.msg for s in specs if s.msg is not None])
diff --git a/conda_env/specs/binstar.py b/conda_env/specs/binstar.py
--- a/conda_env/specs/binstar.py
+++ b/conda_env/specs/binstar.py
@@ -44,7 +44,8 @@ def can_handle(self):
         # TODO: log information about trying to find the package in binstar.org
         if self.valid_name():
             if self.binstar is None:
-                self.msg = "Please install binstar"
+                self.msg = ("Anaconda Client is required to interact with anaconda.org or an "
+                            "Anaconda API. Please run `conda install anaconda-client`.")
                 return False
             return self.package is not None and self.valid_package()
         return False


Test patch: