Closed itsayellow closed 3 years ago
The full pipx log file: cmd_2021-03-08_17.13.54.log
I'm guessing this is a mismatch between the locale's encoding and 'utf-8'.
Probably this could be fixed by changing the appropriate lines in utils.py
to:
def get_flat_output(command, sep=os.pathsep, **kwargs):
process = subprocess.Popen(command, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True, **kwargs)
output = process.communicate()[0].strip()
universal_newlines
is valid for python > 3.3 (https://docs.python.org/3/library/subprocess.html#frequently-used-arguments)
Changed in version 3.3: When universal_newlines is True, the class uses the encoding locale.getpreferredencoding(False) instead of locale.getpreferredencoding(). See the io.TextIOWrapper class for more information on this change.
Or if you don't want to use the universal_newlines
keyword, (still supporting python 2.7?) equivalently:
import locale
def get_flat_output(command, sep=os.pathsep, **kwargs):
process = subprocess.Popen(command, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, **kwargs)
output = process.communicate()[0].decode(locale.getpreferredencoding(False)).strip()
Thanks! Mind making a PR?
Hi @ofek, yes I was thinking about it! 😄 Just got a bit busy.
Do you have a preference to the approach? Using universal_newlines
with subprocess.Popen
is probably great for all the currently-active Python 3 versions. It exists for Python 2.7 but I'm not sure it does the right thing with respect to encodings.
Are you still trying to maintain Python 2.7 compatibility? If so then I'll probably do the second version with import locale
.
Still py2, yes
pipxproject/pipx#644
We recently had a user who got a stacktrace when trying to use
pipx ensurepath
which usesuserpath
. He was using shell fish. The actual python error seemed to be in the middle of userpath, inutils.py
when executing this command:The error:
He was using the fish shell, and seemed to verify that his locale (
LANG
) was set to utf-8. When using bash to runpipx ensurepath
it worked fine.Here's the two caught stacktraces:
and
And here is his
PATH
: