New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

8.1.1 locale.Error: unsupported locale setting in the Docker container #3575

Closed
generalov opened this Issue Mar 18, 2016 · 10 comments

Comments

Projects
None yet
7 participants
@generalov

generalov commented Mar 18, 2016

  • Pip version: 8.1.1
  • Python version: 2.7.6
  • Operating System: ubuntu:14.04 in the Docker container

Description:

Traceback after upgrading pip from to 8.1.0 to 8.1.1 when LC_* environment variables are empty.

What I've run:

(env) root@cccf5e39dacc:/opt/project# locale -a
locale: Cannot set LC_CTYPE to default locale: No such file or directory
locale: Cannot set LC_MESSAGES to default locale: No such file or directory
locale: Cannot set LC_COLLATE to default locale: No such file or directory
C
C.UTF-8
POSIX

(env) root@cccf5e39dacc:/opt/project# locale
locale: Cannot set LC_CTYPE to default locale: No such file or directory
locale: Cannot set LC_MESSAGES to default locale: No such file or directory
locale: Cannot set LC_ALL to default locale: No such file or directory
LANG=en_US.UTF-8
LANGUAGE=
LC_CTYPE="en_US.UTF-8"
LC_NUMERIC="en_US.UTF-8"
LC_TIME="en_US.UTF-8"
LC_COLLATE="en_US.UTF-8"
LC_MONETARY="en_US.UTF-8"
LC_MESSAGES="en_US.UTF-8"
LC_PAPER="en_US.UTF-8"
LC_NAME="en_US.UTF-8"
LC_ADDRESS="en_US.UTF-8"
LC_TELEPHONE="en_US.UTF-8"
LC_MEASUREMENT="en_US.UTF-8"
LC_IDENTIFICATION="en_US.UTF-8"
LC_ALL=
(env) root@cccf5e39dacc:/opt/project# env | grep LC_

(env) root@cccf5e39dacc:/opt/project# pip install pip==8.1.0
Traceback (most recent call last):
  File "/opt/project/env/bin/pip", line 11, in <module>
    sys.exit(main())
  File "/opt/project/env/local/lib/python2.7/site-packages/pip/__init__.py", line 215, in main
    locale.setlocale(locale.LC_ALL, '')
  File "/opt/project/env/lib/python2.7/locale.py", line 579, in setlocale
    return _setlocale(category, locale)
locale.Error: unsupported locale setting

(env) root@cccf5e39dacc:/opt/project# LC_ALL=C pip install pip==8.1.0
  Downloading pip-8.1.0-py2.py3-none-any.whl (1.2MB)

UPD. I've added this lines into the my Dockerfile to fix locale settings:

# Set the locale
RUN locale-gen en_US.UTF-8  
ENV LANG en_US.UTF-8  
ENV LANGUAGE en_US:en  
ENV LC_ALL en_US.UTF-8  

but traceback still looks like a regression in the pip ))

@Zaharid

This comment has been minimized.

Show comment
Hide comment
@Zaharid

Zaharid Mar 22, 2016

I encountered a similar problem, running on a computer cluster where I don't have admin rights (so can't run locale-gen trivially). I think the exception should be handled somehow, or pip becomes useless.

Zaharid commented Mar 22, 2016

I encountered a similar problem, running on a computer cluster where I don't have admin rights (so can't run locale-gen trivially). I think the exception should be handled somehow, or pip becomes useless.

@christophgysin

This comment has been minimized.

Show comment
Hide comment
@christophgysin

christophgysin Mar 23, 2016

This is introduced by 5589ff2 and can be reproduced with:

$ LC_ALL=foo virtualenv/bin/pip list
Traceback (most recent call last):
  File "virtualenv/bin/pip", line 11, in <module>
    sys.exit(main())
  File "virtualenv/local/lib/python2.7/site-packages/pip/__init__.py", line 215, in main
    locale.setlocale(locale.LC_ALL, '')
  File "virtualenv/lib/python2.7/locale.py", line 579, in setlocale
    return _setlocale(category, locale)
locale.Error: unsupported locale setting

christophgysin commented Mar 23, 2016

This is introduced by 5589ff2 and can be reproduced with:

$ LC_ALL=foo virtualenv/bin/pip list
Traceback (most recent call last):
  File "virtualenv/bin/pip", line 11, in <module>
    sys.exit(main())
  File "virtualenv/local/lib/python2.7/site-packages/pip/__init__.py", line 215, in main
    locale.setlocale(locale.LC_ALL, '')
  File "virtualenv/lib/python2.7/locale.py", line 579, in setlocale
    return _setlocale(category, locale)
locale.Error: unsupported locale setting
@christophgysin

This comment has been minimized.

Show comment
Hide comment
@christophgysin

christophgysin Mar 23, 2016

Also, this is not restricted to docker.

christophgysin commented Mar 23, 2016

Also, this is not restricted to docker.

@christophgysin

This comment has been minimized.

Show comment
Hide comment
@christophgysin

christophgysin Mar 23, 2016

@xavfernandez: Could you take a look at this?

christophgysin commented Mar 23, 2016

@xavfernandez: Could you take a look at this?

@deliro

This comment has been minimized.

Show comment
Hide comment
@deliro

deliro Mar 28, 2016

I've got the same thing on my Raspberry Pi B

locale -a output:
C C.UTF-8 en_GB.utf8 en_US.utf8 POSIX

deliro commented Mar 28, 2016

I've got the same thing on my Raspberry Pi B

locale -a output:
C C.UTF-8 en_GB.utf8 en_US.utf8 POSIX

@wichert

This comment has been minimized.

Show comment
Hide comment
@wichert

wichert Apr 1, 2016

I'm seeing this on OSX as well, so it is certainly not specific to docker. Interestingly setlocale(3) does document that the empty string is a valid: the empty string "" (which denotes the native environment), and this C code works fine:

#include <locale.h>
#include <stdio.h>
#include <stdlib.h>

int main(int argc, char** argv) {
    char* old = setlocale(LC_ALL, "");
    if (old==NULL) {
        printf("Locale setting failed\n");
        return 1;
    }
    return 0;
}

But doing the same thing in Python (both 2 and 3) fails:

Python 2.7.11 (default, Mar 31 2016, 15:25:28) 
[GCC 4.2.1 Compatible Apple LLVM 7.3.0 (clang-703.0.29)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import locale
>>> locale.setlocale(locale.LC_ALL, '')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/wichert/.pbin/lib/python2.7/locale.py", line 579, in setlocale
    return _setlocale(category, locale)
locale.Error: unsupported locale setting

So possibly this is a Python bug that pip needs to work around.

wichert commented Apr 1, 2016

I'm seeing this on OSX as well, so it is certainly not specific to docker. Interestingly setlocale(3) does document that the empty string is a valid: the empty string "" (which denotes the native environment), and this C code works fine:

#include <locale.h>
#include <stdio.h>
#include <stdlib.h>

int main(int argc, char** argv) {
    char* old = setlocale(LC_ALL, "");
    if (old==NULL) {
        printf("Locale setting failed\n");
        return 1;
    }
    return 0;
}

But doing the same thing in Python (both 2 and 3) fails:

Python 2.7.11 (default, Mar 31 2016, 15:25:28) 
[GCC 4.2.1 Compatible Apple LLVM 7.3.0 (clang-703.0.29)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import locale
>>> locale.setlocale(locale.LC_ALL, '')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/wichert/.pbin/lib/python2.7/locale.py", line 579, in setlocale
    return _setlocale(category, locale)
locale.Error: unsupported locale setting

So possibly this is a Python bug that pip needs to work around.

@fdemmer

This comment has been minimized.

Show comment
Hide comment
@fdemmer

fdemmer Apr 1, 2016

definitely not a docker issue. eg also causing trouble in fresh ubuntu images used with vagrant when locale is not configured on initial provisioning run.

fdemmer commented Apr 1, 2016

definitely not a docker issue. eg also causing trouble in fresh ubuntu images used with vagrant when locale is not configured on initial provisioning run.

xavfernandez added a commit to xavfernandez/pip that referenced this issue Apr 3, 2016

Fix crash on systems with uninitialized locale
locale.setlocale(locale.LC_ALL, '') apparently crashes in such case.
The raised exception can be safely ignored as locale loading is only
used to automatically detect the default encoding for requirements.txt
files.
Closes pypa#3575
@xavfernandez

This comment has been minimized.

Show comment
Hide comment
@xavfernandez

xavfernandez Apr 3, 2016

Contributor

Does #3598 fixes it ?

Contributor

xavfernandez commented Apr 3, 2016

Does #3598 fixes it ?

@generalov

This comment has been minimized.

Show comment
Hide comment
@generalov

generalov Apr 4, 2016

Yes, thanks!

generalov commented Apr 4, 2016

Yes, thanks!

@wichert

This comment has been minimized.

Show comment
Hide comment
@wichert

wichert Apr 14, 2016

Can we please get a pip release with this fix?

wichert commented Apr 14, 2016

Can we please get a pip release with this fix?

AnalogJ added a commit to AnalogJ/capsulecd-docker that referenced this issue Nov 5, 2017

AnalogJ added a commit to AnalogJ/capsulecd-docker that referenced this issue Nov 5, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment