AttributeError: 'str' object has no attribute 'build_system_class'
I am getting this error when attempting to run this code. Does anyone know what is wrong?
import spack.cmd.info
import sys
pkg = sys.argv[1]
spack.cmd.info.print_text_info(pkg)
AttributeError: 'str' object has no attribute 'build_system_class'
I am getting this error when attempting to run this code. Does anyone know what is wrong?
import spack.cmd.info
import sys
pkg = sys.argv[1]
spack.cmd.info.print_text_info(pkg)
Copyright © 2021 Jogjafile Inc.
From what I have seen from your question and the documentation, I assume the following:
The problem you have has nothing to do with Spack but rather with Python or object-oriented programming. You are fetching a string, sys.argv[1], representing a package name provided in the command-line and giving it to a method, print_text_info, which expects an object of PackageBase type, or its inheritances, e.g., AutotoolsPackage.
Python calls the method using string and calls a member of PackageBase type which doesn't exist for a string, resulting in the aforementioned error.
If you check the info.py of spack, you can see that it fails the first time it tries to call a method build_system_class.
If you look at the
info()
method (which implements thespack info
command) inspack.cmd.info
, you can see how names are looked up to get package instances:So, to get the
PacakgeBase
instance to pass toprint_text_info()
, you just need toimport spack.repo
and callspack.repo.get(name)
as above.