-3
def finalize_options(self):
    if self.cross_compile and os.environ.has_key('PYTHONXCPREFIX'):
        prefix = os.environ['PYTHONXCPREFIX']
        sysconfig.get_python_lib = get_python_lib
        sysconfig.PREFIX = prefix
        sysconfig.EXEC_PREFIX = prefix
        # reinitialize variables
        sysconfig._config_vars = None
        sysconfig.get_config_var("LDSHARED")

    _build.finalize_options(self)

the code above that will get the error when run on python3.5. the error is : crosscompile.py", line 16, in finalize_options AttributeError: '_Environ' object has no attribute 'has_key'

does anyone have idea how to modify the code to workable in python3.5?

2 Answers2

4

has_key is removed in python3, but you shouldn't be using it in 2 either. Use the in operator:

if self.cross_compile and 'PYTHONXCPREFIX' in os.environ:
tzaman
  • 46,925
  • 11
  • 90
  • 115
1

has_key() was removed in Python 3.x. Use in or get

'PYTHONXCPREFIX' in os.environ

Using get

os.environ.get('PYTHONXCPREFIX'). if does not exists it returns None.

It can returns False as well, passing it as default value.

os.environ.get('PYTHONXCPREFIX', False)
levi
  • 22,001
  • 7
  • 73
  • 74