5

I have code that uses subprocess.check_output just fine, I had to reinstall Ubuntu 16.04 and afterwards it's complaining that it now can't find the attribute check_output.

import subprocess

p = subprocess.check_output("here is a command", shell=True)

/usr/bin/python2.7 /home/username/subprocess.py
Traceback (most recent call last):
  File "/home/username/subprocess.py", line 1, in <module>
    import subprocess
  File "/home/username/subprocess.py", line 4, in <module>
    p = subprocess.check_output("here is a command", shell=True)
AttributeError: 'module' object has no attribute 'check_output'

Note that I am using Python2.7 which according to this post here should resolve this problem but it doesn't.

subprocess.check_output() module object has out attribute 'check_output'

What gives? I tried pip install subprocess or pip uninstall subprocess but no luck. How do I update subprocess to the latest version so that it has the check_output attribute? I don't want to use Popen.

1
  • Can you show us how you know for sure that you're using Python2.7? Can you provide some output from running the same steps in the interactive shell? Commented Sep 12, 2017 at 15:19

1 Answer 1

7

Your problem is that you have created a script, called subprocess.py, so the original library subprocess was "overridden" by your module.

Rename your script /home/username/subprocess.py to something that is not the name of the standard Python module! This rule of course applies to all the other Python libraries!

Sign up to request clarification or add additional context in comments.

2 Comments

Wow you're right, I just overlooked the fact that I named the file subprocess.py . What a lame problem :(
just another example of how python needs to fix package vs. relative imports.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.