1

When I installed PyAuduo for my MIPS embedded platform, I got this error:

 running build
 Traceback (most recent call last):
 File "setup.py", line 122, in <module>
 extra_link_args=extra_link_args)
 File "/usr/local/lib/python3.5/distutils/core.py", line 148, in setup
     dist.run_commands()
 File "/usr/local/lib/python3.5/distutils/dist.py", line 955, in 
   run_commands
   self.run_command(cmd)
  File "/usr/local/lib/python3.5/distutils/dist.py", line 973, in 
 run_command
   cmd_obj.ensure_finalized()
  File "/usr/local/lib/python3.5/distutils/cmd.py", line 107, in  
     ensure_finalized
   self.finalize_options()
   File "/usr/local/lib/python3.5/site-packages/distutilscross-0.1-   
    py3.5.egg/distutilscross/crosscompile.py", line 16, in finalize_options
   AttributeError: '_Environ' object has no attribute 'has_key'

It seems "crosscompile.py" cannot run python3 normally. Does anyone have idea how to modify the code in crosscompile.py to work normally in pyhton3?

Apoorv Kansal
  • 3,210
  • 6
  • 27
  • 37
  • the code is [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)] could you provide the example about how to modify for python3.5? – user1450650 Oct 28 '16 at 15:04

1 Answers1

0

how to solve AttributeError: '_Environ' object has no attribute 'has_key'

It seems like PyAudio was built in Python 2x. Python 2x had support for has_key() function to check if keys existed in dictionaries. In Python 3x, you simply do this:

if 'the_key' in os.environ:

You can potentially change this line in crosscompile.py as a quickfix and then contact the developer (http://people.csail.mit.edu/hubert/pyaudio/#contact).

Community
  • 1
  • 1
Apoorv Kansal
  • 3,210
  • 6
  • 27
  • 37
  • the code is : `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)` could you show the example about how to modify to work for python3.5? – user1450650 Oct 28 '16 at 15:06