Reputation: 1
ubuntu version 20.04
python --version
Python 2.7.18
scons -version
script: v0.98.1.r2881
engine: v0.98.1.r2881
Since the latest gem5 use python3/scons3.0.0 and i tried the project with old version which is only support the old version
when i built with the command scons build/X86/gem5.opt -j5
the error jumped and the message showed
*** Error loading site_init file './site_scons/site_init.py':
File "./site_scons/site_init.py", line 51
except SystemExit, e:
^
SyntaxError: invalid syntax
It's a simple python2/python3 syntax error. I can resolve this by replace "," to "as".
but it comes to another serious question. There are a lot of files different from the old to the latest one. Which means i have to fix all the syntax error files. (if this is the only way ...)
This is the reason i tried to use the old scons and python to build the project
First, i simply thought it could resolved by forcing the python using 2.7 version and it popped
** Error loading site_init file './site_scons/site_init.py':
File "./site_scons/site_init.py", line 55
print """
For more details, see:
http://gem5.org/Dependencies
"""
^
SyntaxError: invalid syntax
Then i download the old scons(0.98.0 and 0.98.1)
I have no idea which is the right place to install it so i installed these two both in
/usr/local/lib and /usr/lib
after this step the version successfully switch to 0.98.1
but it still failed
Site init file './site_scons/site_init.py' raised exception: name 'EnsureSConsVersion' is not defined
NameError: name 'EnsureSConsVersion' is not defined:
File "/usr/lib/scons-0.98.0/SCons/Script/Main.py", line 1231:
_exec_main(parser, values)
File "/usr/lib/scons-0.98.0/SCons/Script/Main.py", line 1195:
_main(parser)
File "/usr/lib/scons-0.98.0/SCons/Script/Main.py", line 833:
_load_site_scons_dir(d)
File "/usr/lib/scons-0.98.0/SCons/Script/Main.py", line 682:
imp.load_module(site_init_modname, fp, pathname, description)
File "./site_scons/site_init.py", line 49:
EnsureSConsVersion(0, 98)
Upvotes: 0
Views: 319
Reputation: 16941
It is a shame that you have been landed with a package of technical debt in the form of Python 2 configuration scripts that the authors chose to write to be compatible with Python 1.5.2 rather than with Python 3. It was already possible in Python 2.5 (2006) to write except
clauses and print()
calls that would also work in Python 3. But it was common in some settings to ignore this possibility. Whether you regard that as irresponsible intellectual laziness, or prudent conservatism, is a matter of taste.
The scons
project has, like everyone else, dropped support for Python 2, and I think your best approach is to migrate the Python 2 configuration scripts to Python 3.
It may seem initially easier to get an old version of scons
to work with the existing configuration scripts. That may solve the immediate problem, but it also just pushes out the technical debt. And it it will be difficult to find help if you get stuck.
It appears that you are not aware that Python provides tools for migration that will do most of the tedious work. The module is called lib2to3
, which will rewrite the except
clauses and print()
calls, adjust import
s to take care of renamed standard library modules, and quite a few other things.
There are things that lib2to3
won't fix: it can fix syntax, but not semantic problems, such as integer division being //
not /
, and Python 2 code that relies on the absence of the Python 3 distinction between strings and bytestrings. For help with those, I recommend Lennart Regebro's book Supporting Python 3. I made grateful use of that book in a recent migration project.
Upvotes: 1