Repository: conda/conda

Issue:
conda canary - unable to create environment yml file
I just did
`
(anabase) (psreldev) psel701: /reg/g/psdm/sw/conda/logs $ conda env export > ../manage/config/environment-anabase-1.0.0.yml`

anabase is the environment, I also add the account, psreldev, that I'm logged into, and got this output

```
n 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.2.1
       conda is private : False
      conda-env version : 2.5.2
    conda-build version : 1.21.11+0.g5b44ab3.dirty
         python version : 2.7.12.final.0
       requests version : 2.10.0
       root environment : /reg/g/psdm/sw/conda/inst/miniconda2-dev-rhel7  (writable)
    default environment : /reg/g/psdm/sw/conda/inst/miniconda2-dev-rhel7/envs/anabase
       envs directories : /reg/g/psdm/sw/conda/inst/miniconda2-dev-rhel7/envs
          package cache : /reg/g/psdm/sw/conda/inst/miniconda2-dev-rhel7/pkgs
           channel URLs : file:///reg/g/psdm/sw/conda/channels/system-rhel7
                          file:///reg/g/psdm/sw/conda/channels/psana-rhel7
                          file:///reg/g/psdm/sw/conda/channels/external-rhel7
                          defaults
                          scikit-beam
                          file:///reg/g/psdm/sw/conda/channels/testing-rhel7
            config file : /reg/g/psdm/sw/conda/inst/miniconda2-dev-rhel7/.condarc
           offline mode : False


`$ /reg/g/psdm/sw/conda/inst/miniconda2-dev-rhel7/bin/conda-env export`


    Traceback (most recent call last):
      File "/reg/g/psdm/sw/conda/inst/miniconda2-dev-rhel7/lib/python2.7/site-packages/conda/exceptions.py", line 403, in conda_exception_handler
        return_value = func(*args, **kwargs)
      File "/reg/g/psdm/sw/conda/inst/miniconda2-dev-rhel7/lib/python2.7/site-packages/conda_env/cli/main_export.py", line 93, in execute
        ignore_channels=args.ignore_prefix)
    AttributeError: 'Namespace' object has no attribute 'ignore_prefix'
../manage/config/environment-anabase-1.0.0.yml (END)

```

Here is the environment, if this matters - there is one pip in there, nose2

```
(anabase) (psreldev) psel701: /reg/g/psdm/sw/conda/logs $ conda list
# packages in environment at /reg/g/psdm/sw/conda/inst/miniconda2-dev-rhel7/envs/anabase:
#
backports                 1.0                      py27_0  
boost                     1.57.0                        4  
cairo                     1.12.18                       6  
coverage                  4.1                      py27_0  
cycler                    0.10.0                   py27_0  
cython                    0.24.1                   py27_0  
decorator                 4.0.10                   py27_0  
szip                      2.1                         100    file:///reg/g/psdm/sw/conda/channels/external-rhel7
h5py                      2.5.0           py27_hdf518_mpi4py2_100    file:///reg/g/psdm/sw/conda/channels/system-rhel7
hdf5                      1.8.17              openmpi_100    file:///reg/g/psdm/sw/conda/channels/system-rhel7
mpi4py                    2.0.0           py27_openmpi_100    file:///reg/g/psdm/sw/conda/channels/system-rhel7
openmpi                   1.10.3            lsf_verbs_100    file:///reg/g/psdm/sw/conda/channels/system-rhel7
tables                    3.2.3.1          py27_hdf18_100    file:///reg/g/psdm/sw/conda/channels/system-rhel7
fontconfig                2.11.1                        6  
freetype                  2.5.5                         1  
get_terminal_size         1.0.0                    py27_0  
glib                      2.43.0                        1  
harfbuzz                  0.9.39                        1  
icu                       54.1                          0  
ipython                   5.0.0                    py27_0  
ipython_genutils          0.1.0                    py27_0  
jbig                      2.1                           0  
jinja2                    2.8                      py27_1  
jpeg                      8d                            1  
libffi                    3.2.1                         0  
libgfortran               3.0.0                         1  
libpng                    1.6.22                        0  
libsodium                 1.0.10                        0  
libtiff                   4.0.6                         2  
libxml2                   2.9.2                         0  
markupsafe                0.23                     py27_2  
matplotlib                1.5.1               np111py27_0  
mkl                       11.3.3                        0  
mysql                     5.5.24                        0  
networkx                  1.11                     py27_0  
nose                      1.3.7                    py27_1  
nose2                     0.6.5                     <pip>
numexpr                   2.6.1               np111py27_0  
numpy                     1.11.1                   py27_0  
openssl                   1.0.2h                        1  
pandas                    0.18.1              np111py27_0  
pango                     1.39.0                        1  
path.py                   8.2.1                    py27_0  
pathlib2                  2.1.0                    py27_0  
pexpect                   4.0.1                    py27_0  
pickleshare               0.7.3                    py27_0  
pillow                    3.3.0                    py27_0  
pip                       8.1.2                    py27_0  
pixman                    0.32.6                        0  
prompt_toolkit            1.0.3                    py27_0  
ptyprocess                0.5.1                    py27_0  
pycairo                   1.10.0                   py27_0  
pygments                  2.1.3                    py27_0  
pyparsing                 2.1.4                    py27_0  
pyqt                      4.11.4                   py27_4  
pyqtgraph                 0.9.10                   py27_1  
python                    2.7.12                        1  
python-dateutil           2.5.3                    py27_0  
pytz                      2016.6.1                 py27_0  
pyzmq                     15.3.0                   py27_0  
qt                        4.8.5                         0  
readline                  6.2                           2  
lmfit                     0.8.3                    py27_0    scikit-beam
scikit-beam               0.0.8                    py27_0    scikit-beam
xraylib                   3.1.0                  nppy27_0    scikit-beam
scikit-image              0.12.3              np111py27_1  
scikit-learn              0.17.1              np111py27_2  
scipy                     0.18.0              np111py27_0  
scons                     2.3.0                    py27_0  
setuptools                23.0.0                   py27_0  
simplegeneric             0.8.1                    py27_1  
sip                       4.18                     py27_0  
six                       1.10.0                   py27_0  
sqlite                    3.13.0                        0  
tk                        8.5.18                        0  
traitlets                 4.2.2                    py27_0  
wcwidth                   0.1.7                    py27_0  
wheel                     0.29.0                   py27_0  
xz                        5.2.2                         0  
zeromq                    4.1.4                         0  
zlib                      1.2.8                         3  

```



Discussion:
Perhaps related to above, after I create the environment file with the non-canaray conda, i.e, 

```
anabase) (psreldev) psdev105: /reg/g/psdm/sw/conda $ conda info
Current conda install:

             platform : linux-64
        conda version : 4.1.11
    conda-env version : 2.5.2
  conda-build version : 1.21.9
       python version : 2.7.12.final.0
     requests version : 2.10.0
     root environment : /reg/g/psdm/sw/conda/inst/miniconda2-dev-rhel6  (writable)
  default environment : /reg/g/psdm/sw/conda/inst/miniconda2-dev-rhel6/envs/anabase
     envs directories : /reg/g/psdm/sw/conda/inst/miniconda2-dev-rhel6/envs
        package cache : /reg/g/psdm/sw/conda/inst/miniconda2-dev-rhel6/pkgs
         channel URLs : file:///reg/g/psdm/sw/conda/channels/system-rhel6/linux-64/
                        file:///reg/g/psdm/sw/conda/channels/system-rhel6/noarch/
                        file:///reg/g/psdm/sw/conda/channels/psana-rhel6/linux-64/
                        file:///reg/g/psdm/sw/conda/channels/psana-rhel6/noarch/
                        file:///reg/g/psdm/sw/conda/channels/external-rhel6/linux-64/
                        file:///reg/g/psdm/sw/conda/channels/external-rhel6/noarch/
                        https://repo.continuum.io/pkgs/free/linux-64/
                        https://repo.continuum.io/pkgs/free/noarch/
                        https://repo.continuum.io/pkgs/pro/linux-64/
                        https://repo.continuum.io/pkgs/pro/noarch/
                        https://conda.anaconda.org/t/<TOKEN>/scikit-beam/linux-64/
                        https://conda.anaconda.org/t/<TOKEN>/scikit-beam/noarch/
                        file:///reg/g/psdm/sw/conda/channels/testing-rhel7/linux-64/
                        file:///reg/g/psdm/sw/conda/channels/testing-rhel7/noarch/
          config file : /reg/g/psdm/sw/conda/inst/miniconda2-dev-rhel6/.condarc
         offline mode : False
    is foreign system : False

```

I am unable to create a new environment from it, I get the message:

```
Error: Packages missing in current linux-64 channels: 
  - file:///reg/g/psdm/sw/conda/channels/external-rhel6::szip 2.1 100
  - file:///reg/g/psdm/sw/conda/channels/system-rhel6::h5py 2.5.0 py27_hdf518_mpi4py2_100
  - file:///reg/g/psdm/sw/conda/channels/system-rhel6::hdf5 1.8.17 openmpi_100
  - file:///reg/g/psdm/sw/conda/channels/system-rhel6::mpi4py 2.0.0 py27_openmpi_100
  - file:///reg/g/psdm/sw/conda/channels/system-rhel6::openmpi 1.10.3 lsf_verbs_100
  - file:///reg/g/psdm/sw/conda/channels/system-rhel6::tables 3.2.3.1 py27_hdf18_100
  - scikit-beam::lmfit 0.8.3 py27_0
  - scikit-beam::scikit-beam 0.0.8 py27_0
  - scikit-beam::xraylib 3.1.0 nppy27_0

```

but the packages are there, for instance I can create an environment with szip:

```
anabase) (psreldev) psdev105: /reg/g/psdm/sw/conda $ conda create -n szip szip=2.1=100
Package plan for installation in environment /reg/g/psdm/sw/conda/inst/miniconda2-dev-rhel6/envs/szip:

The following NEW packages will be INSTALLED:

    szip: 2.1-100 file:///reg/g/psdm/sw/conda/channels/external-rhel6

Proceed ([y]/n)? n

```

Following along on this page http://conda.pydata.org/docs/using/envs.html#export-the-environment-file
I tried to create an environment from a spec file, but I got errors about the lines with comments:

``````
(anabase) (psreldev) psel701: /reg/g/psdm/sw/conda $ conda list -e > manage/config/spec-file-anabase-1.0.0.txt 
(anabase) (psreldev) psel701: /reg/g/psdm/sw/conda $ conda env create --name ana-1.0.0 --file manage/config/spec-file-anabase-1.0.0.txt 
Using Anaconda API: https://api.anaconda.org
Value error: invalid package specification: # This file may be used to create an environment using:

```after deleting the initial header lines that had # in the front, it seems to be working
``````

For the first bug you got, it is caused by a wrong attribute in a NameSpace, please refer to [here](https://github.com/conda/conda/blob/4.2.1/conda_env/cli/main_export.py#L93), it should be args.ignore_channels, instead of ignore_prefix

For the second bug, cannot create env from .txt file, it is caused by NoneType Error, please refer to [here](https://github.com/conda/conda/blob/4.1.x/conda/cli/common.py#L479). 

This is an error for conda 4.1.x. After strip the comment, the result may be None. However, it forward to MatchSpec class without None-checking, as a result, it will leads to a NoneType-related exception, and raise a CondaValue error  


Resolving patch:
diff --git a/conda_env/cli/main_export.py b/conda_env/cli/main_export.py
--- a/conda_env/cli/main_export.py
+++ b/conda_env/cli/main_export.py
@@ -90,7 +90,7 @@ def execute(args, parser):
         name = args.name
     prefix = get_prefix(args)
     env = from_environment(name, prefix, no_builds=args.no_builds,
-                           ignore_channels=args.ignore_prefix)
+                           ignore_channels=args.ignore_channels)
 
     if args.override_channels:
         env.remove_channels()


Test patch: