Repository: conda/conda-build

Issue:
After conda-convert from win -> unix, can only install using "-c file://some/dir"
Hello!

I am on a windows machine and I am trying build an osx-64 package. I run the following commands:
* ```conda build --py 3.6 --output-folder output```
* ```conda convert -p osx-64 -o output output\win-64\{my_package}.tar.bz2```
* ```conda index output\osx-64```
* ```anaconda upload output\osx-64\{my_package}.tar.bz2```

```output\osx-64``` now contains {my_package}.tar.bz2, repodata.json, .paths.json, etc. My anaconda cloud account contains just the {my_package}.tar.bz2 file.

I copy the whole ```output``` folder to my osx machine, and run the following commands:

* ```conda create --name new_blank_env```
* ```source activate new_blank_env```
* ```conda install -c file:///path/to/output {my_package} --use-local```

The install will prompt to me to install new packages, I say 'y'. My conda package installs correctly, without hitch.

_HOWEVER_, if I run:

* ```conda create --name new_blank_env```
* ```source activate new_blank_env```
* ```conda install -c {my_username} {my_package}```

The install will prompt to me to install new packages, I say 'y'. The install will then hang for a few minutes, spitting out this error:

```
ERROR conda.core.link:_execute_actions(337): An error occurred while installing package 'file:///path/to/output::{my_package}'.
CondaError: Cannot link a source that does not exist. /anaconda3/pkgs/{my_package}/lib\python3.6\site-packages\{my_package}.egg-info\PKG-INFO
Running `conda clean --packages` may resolve your problem.
Attempting to roll back.

CondaError: Cannot link a source that does not exist. /anaconda3/pkgs/{my_package}/lib\python3.6\site-packages\{my_package}.egg-info\PKG-INFO
Running `conda clean --packages` may resolve your problem.
```

Interestingly enough, that same error exists if I run ```conda install -c file:///path/to/output {my_package}``` without --use-local

I ran 'conda clean --packages' and it did not fix the issue. You may notice that the error contains a unix path mixed with a windows path: I checked, ```/anaconda3/pkgs/{my_package}/lib/python3.6/site-packages/{my_package}.egg-info/PKG-INFO``` _DOES_ exist.

[Here is my conda env in root](https://github.com/conda/conda-build/files/1476262/conda_list_of_root.txt), I  am running ```conda-build               3.0.27           py36hb78d8cd_0```

Here is the DEBUG output of ```conda install -c {my_username} {my_package} -v -v &> conda_install_debug.txt```: [conda_install_debug.txt](https://github.com/conda/conda-build/files/1476279/conda_install_debug.txt)

Let me know if you need any more information from me, thanks!


Discussion:
Thanks for reporting this. I was able to reproduce by converting a Win64 package to Linux64. At first glance, it seemed that the paths in ``info/files`` and ``info/paths.json`` were the culprits. I changed the paths in those two files and still received the error. After running diffoscope on a package built on Linux64 and the converted package, nothing stood out so I'm not sure where the bug lies. It may be related to https://github.com/conda/conda/issues/4374. Hopefully someone else can chime in.

Resolving patch:
diff --git a/conda_build/convert.py b/conda_build/convert.py
--- a/conda_build/convert.py
+++ b/conda_build/convert.py
@@ -11,6 +11,8 @@
 import glob
 import json
 import hashlib
+import ntpath
+import posixpath
 import os
 import re
 import shutil
@@ -253,7 +255,8 @@ def update_lib_contents(lib_directory, temp_dir, target_platform, file_path):
         try:
             for lib_file in glob.iglob('{}/python*/**' .format(lib_directory)):
                 if 'site-packages' in lib_file:
-                    new_site_packages_path = os.path.join(temp_dir, 'lib/site-packages')
+                    new_site_packages_path = os.path.join(
+                        temp_dir, os.path.join('lib', 'site-packages'))
                     os.renames(lib_file, new_site_packages_path)
                 else:
                     if retrieve_python_version(lib_file) is not None:
@@ -276,7 +279,7 @@ def update_lib_contents(lib_directory, temp_dir, target_platform, file_path):
                 new_lib_file = re.sub('Lib', os.path.join('lib', python_version), lib_file)
                 os.renames(lib_file, new_lib_file)
 
-            os.rename(os.path.join(temp_dir, 'Lib'), os.path.join(temp_dir, 'lib'))
+            os.rename(ntpath.join(temp_dir, 'Lib'), posixpath.join(temp_dir, 'lib'))
 
         except OSError:
             pass
@@ -366,7 +369,7 @@ def update_paths_file(temp_dir, target_platform):
                     paths['paths'].remove(path)
 
         with open(paths_file, 'w') as file:
-            json.dump(paths, file)
+            json.dump(paths, file, indent=2)
 
 
 def retrieve_executable_name(executable):
@@ -525,7 +528,6 @@ def update_files_file(temp_dir, verbose):
                 package_file_path = os.path.join(
                     dirpath, filename).replace(temp_dir, '').lstrip(os.sep)
                 if not package_file_path.startswith('info'):
-                    # files.write(package_file_path + '\n')
                     file_paths.append(package_file_path)
 
                     if verbose:


Test patch: