Repository: conda/conda

Issue:
CondaError: Cannot link a source that does not exist. C:\Users\...\Anaconda3\Scripts\conda.exe
I get this error when trying to conda install tqdm. Pip install works fine. However, when trying conda install spacy, I still get the same error because the conda installation for spacy attempts to conda install tqdm.   


Discussion:
Do you still get the error after running `conda clean --all --yes`?
If you need additional help, please include more details.  At a minimum, `conda info`, the command that gave the error, and the full stack trace.  Whatever details are necessary to independently reproduce the issue you're seeing.
Thanks @kalefranz. I had tried `Conda clean --all`. The error went away when I updated everything with `conda update anaconda `
Had the same error and @AVSuni thank you so much! Also thanks to @kalefranz  (it occured when installing spacy)
We've run into this with nbconvert as well. I setup [a repo](https://github.com/minrk/debug-conda-appveyor) to do some testing:

On AppVeyor, installing nbconvert from conda-forge has started failing with:

```
ERROR conda.core.link:_execute_actions(337): An error occurred while installing package 'conda-forge::nbconvert-5.3.1-py_1'.
CondaError: Cannot link a source that does not exist. C:\Miniconda-x64\Scripts\conda.exe
Attempting to roll back.
CondaError: Cannot link a source that does not exist. C:\Miniconda-x64\Scripts\conda.exe
```

Possibly relevant bits of info:

- `conda clean --all` does not help
- Failure only occurs on [Windows + Python 2](https://ci.appveyor.com/project/minrk/debug-conda-appveyor/build/1.0.9)
- It only occurs when conda is upgraded or downgraded during the same install. Disabling auto_update_conda [fixes the issue](https://ci.appveyor.com/project/minrk/debug-conda-appveyor/build/1.0.10)
- Appears to be a regression between conda [4.3.8](https://ci.appveyor.com/project/minrk/debug-conda-appveyor/build/1.0.21) and [4.3.9](https://ci.appveyor.com/project/minrk/debug-conda-appveyor/build/1.0.22)
- nbconvert has `noarch: python` and an entry-point, as does tqdm
- installing last nbconvert release prior to noarch [has no issue](https://ci.appveyor.com/project/minrk/debug-conda-appveyor/build/1.0.11)
- installing other, lighter packages with noarch + entrypoint (geojsonio) [doesn't reproduce the issue](https://ci.appveyor.com/project/minrk/debug-conda-appveyor/build/1.0.6) so there might be something else special about nbconvert+tqdm, or it could just be the ordering of packages causing the correct sequence of events to occur that `conda.exe` is removed while it's attempted to be linked.


I'm seeing this in damianavila/RISE#315 on win64 / py36 / conda 4.3.22

`conda clean --all` doesn't help - same error.

Reverting to `conda=4.2.16` *"fixed"* the problem for me.

Whereby *"fixed"* means the broken post-install script didn't run. That was easily fixed with a `jupyter nbextension enable ...`  command so perhaps thre should be an `--ignore-errors` flag to allow users to proceed at their own risk rather than forcing them to downgrade conda to do so.
Hi all, I've run into this issue while trying to install the "tweepy" package. [win10 / conda 4.3.30 / Python 3.6.3]

Command: `conda install -c conda-forge tweepy`

**Error:**
oauthlib-2.0.6 100% |###############################| Time: 0:00:00   0.00  B/s
conda-4.3.29-p 100% |###############################| Time: 0:00:00   3.20 MB/s
requests-oauth 100% |###############################| Time: 0:00:00   0.00  B/s
tweepy-3.5.0-p 100% |###############################| Time: 0:00:00   3.37 MB/s
ERROR conda.core.link:_execute_actions(337): An error occurred while installing package 'conda-forge::pyjwt-1.5.3-py_0'.
CondaError: Cannot link a source that does not exist. C:\Users\Maurice\Anaconda3\Scripts\conda.exe
Running `conda clean --packages` may resolve your problem.
Attempting to roll back.


CondaError: Cannot link a source that does not exist. C:\Users\Maurice\Anaconda3\Scripts\conda.exe
Running `conda clean --packages` may resolve your problem.
**Error End**

I tried the above steps of `conda clean --all --yes` and `conda update anaconda` but I didn't have any success. 
Any recommendations on what else I could try? Thanks.
It's clear to me that this is an issue with entry point creation for python noarch packages on windows.  Looking into it.
> or it could just be the ordering of packages causing the correct sequence of events to occur that conda.exe is removed while it's attempted to be linked.

That's exactly what's happening.

```
DEBUG conda.core.link:create_from_dists(119): instantiating UnlinkLinkTransaction with
  target_prefix: C:\Users\builder\Miniconda3
  unlink_dists:
    defaults::conda-4.3.24-py36_0
    defaults::conda-env-2.6.0-0
    defaults::openssl-1.0.2l-vc14_0
  link_dists:
    conda-forge::ca-certificates-2017.7.27.1-0
    conda-forge::conda-env-2.6.0-0
    conda-forge::openssl-1.0.2l-vc14_0
    conda-forge::vc-14-0
    conda-forge::pyjwt-1.5.3-py_0
    conda-forge::conda-4.3.29-py36_0
```

Sometime around 4.3.8, we removed the embedded `cli-64.exe` / `cli-32.exe` files like what's in conda-build (https://github.com/conda/conda-build/tree/master/conda_build), realizing we already had the identical python entry point binary already available with conda.exe.

As you can see in the above operation plan, conda is unlinked, but then installed last, after pyjwt, which is what needs the entry point binary to hard link.

Resolving patch:
diff --git a/conda/resolve.py b/conda/resolve.py
--- a/conda/resolve.py
+++ b/conda/resolve.py
@@ -6,13 +6,14 @@
 
 from .base.constants import DEFAULTS_CHANNEL_NAME, MAX_CHANNEL_PRIORITY
 from .base.context import context
-from .common.compat import iteritems, iterkeys, itervalues, odict, string_types, text_type
+from .common.compat import iteritems, iterkeys, itervalues, odict, on_win, string_types, text_type
 from .common.io import time_recorder
 from .common.logic import Clauses, minimal_unsatisfiable_subset
 from .common.toposort import toposort
 from .exceptions import ResolvePackageNotFound, UnsatisfiableError
 from .models.channel import Channel, MultiChannel
 from .models.dist import Dist
+from .models.enums import NoarchType
 from .models.index_record import PackageRef
 from .models.match_spec import MatchSpec
 from .models.version import VersionOrder
@@ -620,11 +621,29 @@ def dependency_sort(self, must_have):
         # type: (Dict[package_name, Dist]) -> List[Dist]
         assert isinstance(must_have, dict)
 
-        digraph = {}
-        for key, dist in iteritems(must_have):
+        digraph = {}  # Dict[package_name, Set[dependent_package_names]]
+        for package_name, dist in iteritems(must_have):
             if dist in self.index:
-                depends = set(ms.name for ms in self.ms_depends(dist))
-                digraph[key] = depends
+                digraph[package_name] = set(ms.name for ms in self.ms_depends(dist))
+
+        # There are currently at least three special cases to be aware of.
+        # 1. The `toposort()` function, called below, contains special case code to remove
+        #    any circular dependency between python and pip.
+        # 2. conda/plan.py has special case code for menuinst
+        #       Always link/unlink menuinst first/last on windows in case a subsequent
+        #       package tries to import it to create/remove a shortcut
+        # 3. On windows, python noarch packages need an implicit dependency on conda added, if
+        #    conda is in the list of packages for the environment.  Python noarch packages
+        #    that have entry points use conda's own conda.exe python entry point binary. If conda
+        #    is going to be updated during an operation, the unlink / link order matters.
+        #    See issue #6057.
+
+        if on_win and 'conda' in digraph:
+            for package_name, dist in iteritems(must_have):
+                record = self.index.get(dist)
+                if hasattr(record, 'noarch') and record.noarch == NoarchType.python:
+                    digraph[package_name].add('conda')
+
         sorted_keys = toposort(digraph)
         must_have = must_have.copy()
         # Take all of the items in the sorted keys


Test patch: