When trying to create a venv on ubuntu 16.04 in a freshly created Hetzner CX60 instance, I got an error:
foo@dev:/tmp/unpip$ python3 -m venv python-env
The virtual environment was not created successfully because ensurepip is not
available. On Debian/Ubuntu systems, you need to install the python3-venv
package using the following command.
apt-get install python3-venv
You may need to use sudo with that command. After installing the python3-venv
package, recreate your virtual environment.
Failing command: ['/tmp/python-env/bin/python3', '-Im', 'ensurepip', '--upgrade', '--default-pip']
foo@dev:/tmp/unpip$
The error is quite misleading. Running the actual command gave me:
foo@dev:/tmp/unpip$ /tmp/python-env/bin/python3 -Im ensurepip --upgrade --default-pip
Traceback (most recent call last):
File "/usr/lib/python3.5/runpy.py", line 184, in _run_module_as_main
"__main__", mod_spec)
File "/usr/lib/python3.5/runpy.py", line 85, in _run_code
exec(code, run_globals)
File "/usr/lib/python3.5/ensurepip/__main__.py", line 4, in <module>
ensurepip._main()
File "/usr/lib/python3.5/ensurepip/__init__.py", line 268, in _main
default_pip=args.default_pip,
File "/usr/lib/python3.5/ensurepip/__init__.py", line 174, in bootstrap
_run_pip(args + _PROJECTS, additional_paths)
File "/usr/lib/python3.5/ensurepip/__init__.py", line 67, in _run_pip
pip.main(args)
File "/tmp/tmp8ai4kkpj/pip-8.1.1-py2.py3-none-any.whl/pip/__init__.py", line 215, in main
File "/usr/lib/python3.5/locale.py", line 594, in setlocale
return _setlocale(category, locale)
locale.Error: unsupported locale setting
foo@dev:/tmp/unpip$
So a locale issue..
foo@dev:~$ locale
LANG=en_US.UTF-8
LANGUAGE=
LC_CTYPE="en_US.UTF-8"
LC_NUMERIC=nl_NL.UTF-8
LC_TIME=nl_NL.UTF-8
LC_COLLATE="en_US.UTF-8"
LC_MONETARY=nl_NL.UTF-8
LC_MESSAGES="en_US.UTF-8"
LC_PAPER=nl_NL.UTF-8
LC_NAME=nl_NL.UTF-8
LC_ADDRESS=nl_NL.UTF-8
LC_TELEPHONE=nl_NL.UTF-8
LC_MEASUREMENT=nl_NL.UTF-8
LC_IDENTIFICATION=nl_NL.UTF-8
LC_ALL=
foo@dev:~$ Python 3.5.2 (default, Nov 23 2017, 16:37:01)
[GCC 5.4.0 20160609] on linux
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 "/usr/lib/python3.5/locale.py", line 594, in setlocale
return _setlocale(category, locale)
locale.Error: unsupported locale setting
>>>
So I ran
sudo dpkg-reconfigure locales and made sure en_US.UTF-8 and nl_NL.UTF-8 were checked, which re-generated the locales. This made it work.
Python 3.5.2 (default, Nov 23 2017, 16:37:01)
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import locale
>>> locale.setlocale(locale.LC_ALL, '')
'LC_CTYPE=en_US.UTF-8;LC_NUMERIC=nl_NL.UTF-8;LC_TIME=nl_NL.UTF-8;LC_COLLATE=en_US.UTF-8;LC_MONETARY=nl_NL.UTF-8;LC_MESSAGES=en_US.UTF-8;LC_PAPER=nl_NL.UTF-8;LC_NAME=nl_NL.UTF-8;LC_ADDRESS=nl_NL.UTF-8;LC_TELEPHONE=nl_NL.UTF-8;LC_MEASUREMENT=nl_NL.UTF-8;LC_IDENTIFICATION=nl_NL.UTF-8'
>>>
--
KoenMartens - 15 Jan 2018