fix a bug of setup.py when torch can't be imported #252
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
setup.py里在import不到torch的时候有一个奇怪的try except(我猜可能是为了处理这里的报错 https://github.com/pytorch/pytorch/blob/v2.0.0/torch/__init__.py#L443 ),但是问题是如果环境里就是import不到torch的话就会导致拿到的include_dirs有问题,然后会在编译extension的时候报找不到头文件,比较难以发现问题的原因。除了去掉try except这里也可以考虑改成except ImportError
get_pytorch_dir函数看起来是从https://github.com/Ascend/pytorch/blob/d6623f2f5b9f592c6a2665aec840231b08e7e5be/setup.py#L95 借鉴的