SamsungLabs / zero-cost-nas

Zero-Cost Proxies for Lightweight NAS
Apache License 2.0
140 stars 20 forks source link

AssertionError: _dist_info should not exist when repo is in place #10

Closed zhengyuntao123 closed 2 years ago

zhengyuntao123 commented 2 years ago

When I run python nasbench2_pred.py as mentioned in the reproducing results part, I encounter with such error: Traceback (most recent call last): File "/home/yuntao/test/zero-cost-nas/nasbench2_pred.py", line 20, in from foresight.models import File "/home/yuntao/test/zero-cost-nas/foresight/init.py", line 16, in from .version import File "/home/yuntao/test/zero-cost-nas/foresight/version.py", line 44, in assert not has_repo, '_dist_info should not exist when repo is in place' AssertionError: _dist_info should not exist when repo is in place

vaenyr commented 2 years ago

How did you install the package? This can sometimes happen if you first install without, and then with, the -e option. To make sure everything is as expected, I would recommend uninstalling the package first (run it as many times as needed until you see a message saying there's no package to uninstall), then remove the _dist_info.py file from the cloned repo, install again with the -e (if that's what you want).

Let me know if that helped.

zhengyuntao123 commented 2 years ago

Thank you for your quick reply. I didn't try pip install -e .. However, I find that whenever I remove the whole directory, git clone it again and pip install ., it runs properly at first time. But if I run pip install . again, errors would arise: Processing /home/yuntao/zero-cost-nas Preparing metadata (setup.py) ... error error: subprocess-exited-with-error

× python setup.py egg_info did not run successfully. │ exit code: 1 ╰─> [14 lines of output] Traceback (most recent call last): File "", line 2, in File "", line 34, in File "/home/yuntao/zero-cost-nas/setup.py", line 31, in spec.loader.exec_module(package_version) File "", line 850, in exec_module File "", line 228, in _call_with_frames_removed File "/home/yuntao/zero-cost-nas/foresight/version.py", line 43, in from . import _dist_info as info File "/home/yuntao/zero-cost-nas/foresight/init.py", line 16, in from .version import * File "/home/yuntao/zero-cost-nas/foresight/version.py", line 44, in assert not has_repo, '_dist_info should not exist when repo is in place' AssertionError: _dist_info should not exist when repo is in place [end of output]

note: This error originates from a subprocess, and is likely not a problem with pip. error: metadata-generation-failed

× Encountered error while generating package metadata. ╰─> See above for output.

note: This is an issue with the package mentioned above, not pip. hint: See above for details.

vaenyr commented 2 years ago

Well, in case that's not clear, please do not install the package twice (and if you need to, a short answer is: just delete _dist_info.py). Also, what pip version are you using? If I remember correctly pip has recently made some changes in the way packages are build, perhaps that's the reason.

When you install the package without the -e option it automatically generates a file called _dist_info.py which includes information about the repo (a remote's url) and commit hash at the moment of installation. This file, together with the rest of the source code, is then supposed to be installed in your site-packages directory (or wherever else you usually keep your installed packages).

So, the steps are like: 1. clone repo -> 2. generate _dist_info.py -> 3. copy _dist_info.py and other *.py files to the installation directory.

After that you should be using the source code from the installation directory (step 3). If you try to use the codebase from step 1, it might complain that there's a _dist_info.py file which shouldn't be there. Whether _dist_info.py is left behind is a detail that might depend on pip version - at least in the past pip used to copy the repo to a temporary build directory where things were happening, so _dist_info.py was generated within a dummy copy of the repo before being moved to the installation directory, the source directory was therefore left unchanged. However, at some point pip switched to building packages within their directory, meaning that any intermediate files would remain in the source directory - this is most likely what you're facing here.

I will think about a better way of handling generation of the _dist_info.py to avoid problems with in-tree builds, but in a meantime, please consider what I said before. That is, if you're installing without the -e option you shouldn't be using the code from the repo when you do import foresight. If you want import foresight to import the code from the repo directory, please install with -e. (And keep in mind that if you install without -e there might be _dist_info.py left after previous installation - it can be safely deleted).

zhengyuntao123 commented 2 years ago

Thanks a lot.

After deleting _dist_info.py, I could properly run python nasbench2_pred.py.

By the way, my pip version is 22.1.2. Maybe the problem is due to the pip version.

vaenyr commented 2 years ago

Thanks for the info, I've just pushed a small fix that should solve the issues (it basically deletes the file for you). Feel free to reopen the issue if you face more problems!