Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
zhengyuntao123 opened this issue Sep 13, 2022 · 5 comments
Closed

Comments

@zhengyuntao123
Copy link

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
Copy link
Contributor

vaenyr commented Sep 13, 2022

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
Copy link
Author

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
Copy link
Contributor

vaenyr commented Sep 13, 2022

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
Copy link
Author

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
Copy link
Contributor

vaenyr commented Sep 14, 2022

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!

@vaenyr vaenyr closed this as completed Sep 14, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants