pip cannot install or upgrade, with UnicodeDecodeError reported - python

I am using anaconda Powershell Prompt in Win10. UnicodeDecodeError was reported when installing package with pip (version: 21.2.4). I found this error would reported with the kernel Python 3.6.7 and Python 3.9.7.Both the installation and the upgrade failed and reported the same error. I've tried the following command.
pip install simplejson
pip install simplejson --upgrade
The package can be anything and report the same bug.
Same error was reported using the Windows CMD. I tried the following command using Windows CMD.
py -m pip install simplejson
py -m pip install --upgrade pip
Here is the error report I got.
ERROR: Exception:
Traceback (most recent call last):
File "E:\Program Files\Anaconda3\lib\site-packages\pip\_internal\cli\base_command.py", line 173, in _main
status = self.run(options, args)
File "E:\Program Files\Anaconda3\lib\site-packages\pip\_internal\cli\req_command.py", line 203, in wrapper
return func(self, options, args)
File "E:\Program Files\Anaconda3\lib\site-packages\pip\_internal\commands\install.py", line 315, in run
requirement_set = resolver.resolve(
File "E:\Program Files\Anaconda3\lib\site-packages\pip\_internal\resolution\resolvelib\resolver.py", line 94, in resolve
result = self._result = resolver.resolve(
File "E:\Program Files\Anaconda3\lib\site-packages\pip\_vendor\resolvelib\resolvers.py", line 472, in resolve
state = resolution.resolve(requirements, max_rounds=max_rounds)
File "E:\Program Files\Anaconda3\lib\site-packages\pip\_vendor\resolvelib\resolvers.py", line 341, in resolve
self._add_to_criteria(self.state.criteria, r, parent=None)
File "E:\Program Files\Anaconda3\lib\site-packages\pip\_vendor\resolvelib\resolvers.py", line 172, in _add_to_criteria
if not criterion.candidates:
File "E:\Program Files\Anaconda3\lib\site-packages\pip\_vendor\resolvelib\structs.py", line 151, in __bool__
return bool(self._sequence)
File "E:\Program Files\Anaconda3\lib\site-packages\pip\_internal\resolution\resolvelib\found_candidates.py", line 140, in __bool__
return any(self)
File "E:\Program Files\Anaconda3\lib\site-packages\pip\_internal\resolution\resolvelib\found_candidates.py", line 128, in <genexpr>
return (c for c in iterator if id(c) not in self._incompatible_ids)
File "E:\Program Files\Anaconda3\lib\site-packages\pip\_internal\resolution\resolvelib\found_candidates.py", line 29, in _iter_built
for version, func in infos:
File "E:\Program Files\Anaconda3\lib\site-packages\pip\_internal\resolution\resolvelib\factory.py", line 272, in iter_index_candidate_infos
result = self._finder.find_best_candidate(
File "E:\Program Files\Anaconda3\lib\site-packages\pip\_internal\index\package_finder.py", line 851, in find_best_candidate
candidates = self.find_all_candidates(project_name)
File "E:\Program Files\Anaconda3\lib\site-packages\pip\_internal\index\package_finder.py", line 798, in find_all_candidates
page_candidates = list(page_candidates_it)
File "E:\Program Files\Anaconda3\lib\site-packages\pip\_internal\index\sources.py", line 134, in page_candidates
yield from self._candidates_from_page(self._link)
File "E:\Program Files\Anaconda3\lib\site-packages\pip\_internal\index\package_finder.py", line 758, in process_project_url
html_page = self._link_collector.fetch_page(project_url)
File "E:\Program Files\Anaconda3\lib\site-packages\pip\_internal\index\collector.py", line 490, in fetch_page
return _get_html_page(location, session=self.session)
File "E:\Program Files\Anaconda3\lib\site-packages\pip\_internal\index\collector.py", line 400, in _get_html_page
resp = _get_html_response(url, session=session)
File "E:\Program Files\Anaconda3\lib\site-packages\pip\_internal\index\collector.py", line 115, in _get_html_response
resp = session.get(
File "E:\Program Files\Anaconda3\lib\site-packages\pip\_vendor\requests\sessions.py", line 555, in get
return self.request('GET', url, **kwargs)
File "E:\Program Files\Anaconda3\lib\site-packages\pip\_internal\network\session.py", line 454, in request
return super().request(method, url, *args, **kwargs)
File "E:\Program Files\Anaconda3\lib\site-packages\pip\_vendor\requests\sessions.py", line 528, in request
prep = self.prepare_request(req)
File "E:\Program Files\Anaconda3\lib\site-packages\pip\_vendor\requests\sessions.py", line 456, in prepare_request
p.prepare(
File "E:\Program Files\Anaconda3\lib\site-packages\pip\_vendor\requests\models.py", line 320, in prepare
self.prepare_auth(auth, url)
File "E:\Program Files\Anaconda3\lib\site-packages\pip\_vendor\requests\models.py", line 556, in prepare_auth
r = auth(self)
File "E:\Program Files\Anaconda3\lib\site-packages\pip\_internal\network\auth.py", line 208, in __call__
url, username, password = self._get_url_and_credentials(req.url)
File "E:\Program Files\Anaconda3\lib\site-packages\pip\_internal\network\auth.py", line 180, in _get_url_and_credentials
username, password = self._get_new_credentials(original_url)
File "E:\Program Files\Anaconda3\lib\site-packages\pip\_internal\network\auth.py", line 145, in _get_new_credentials
netrc_auth = get_netrc_auth(original_url)
File "E:\Program Files\Anaconda3\lib\site-packages\pip\_vendor\requests\utils.py", line 216, in get_netrc_auth
_netrc = netrc(netrc_path).authenticators(host)
File "E:\Program Files\Anaconda3\lib\netrc.py", line 30, in __init__
self._parse(file, fp, default_netrc)
File "E:\Program Files\Anaconda3\lib\netrc.py", line 39, in _parse
toplevel = tt = lexer.get_token()
File "E:\Program Files\Anaconda3\lib\shlex.py", line 109, in get_token
raw = self.read_token()
File "E:\Program Files\Anaconda3\lib\shlex.py", line 140, in read_token
nextchar = self.instream.read(1)
UnicodeDecodeError: 'gbk' codec can't decode byte 0xff in position 0: illegal multibyte sequence
I have reinstalled the pip, Anaconda, and the python interpreter. It still failed. I think it has nothing to do with the pip. Something went wrong with the input stream. The default decode format is "GBK". I tried to change decode format to "utf-8" with the following command. It failed again with the same error.
chcp 65001
Thanks the suggestion from #Mobfi, I tried other similar commands, which return the same error notification.
chcp 437
chcp 850
Thanks the suggestion from #BoarGules, I start python with utf-8 decoder and tried to install/upgrade package with pip.
py -X utf8
I started the python console in powershell.
import pip
pip.main(['install', 'simplejson'])
Besides the similar traceback, I got another new traceback:
*same as aforementioned traceback*
File "E:\Program Files\Anaconda3\lib\codecs.py", line 322, in decode
(result, consumed) = self._buffer_decode(data, self.errors, final)
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xff in position 0: invalid start byte
Anybody can help? Any potential solution, clues or similar experiences is welcomed.

Related

running any pip commands results in an attribute error

Pip seems to have broken all of a sudden in my virtual environment (venv). When running any pip command, (like pip install --upgrade pip), I get the following error:
Traceback (most recent call last):
File "/home/user/code/home-stuff/.venv/lib/python3.10/site-packages/pip/_internal/cli/base_command.py", line 165, in exc_logging_wrapper
status = run_func(*args)
File "/home/user/code/home-stuff/.venv/lib/python3.10/site-packages/pip/_internal/cli/req_command.py", line 205, in wrapper
return func(self, options, args)
File "/home/user/code/home-stuff/.venv/lib/python3.10/site-packages/pip/_internal/commands/install.py", line 339, in run
requirement_set = resolver.resolve(
File "/home/user/code/home-stuff/.venv/lib/python3.10/site-packages/pip/_internal/resolution/resolvelib/resolver.py", line 94, in resolve
result = self._result = resolver.resolve(
File "/home/user/code/home-stuff/.venv/lib/python3.10/site-packages/pip/_vendor/resolvelib/resolvers.py", line 481, in resolve
state = resolution.resolve(requirements, max_rounds=max_rounds)
File "/home/user/code/home-stuff/.venv/lib/python3.10/site-packages/pip/_vendor/resolvelib/resolvers.py", line 348, in resolve
self._add_to_criteria(self.state.criteria, r, parent=None)
File "/home/user/code/home-stuff/.venv/lib/python3.10/site-packages/pip/_vendor/resolvelib/resolvers.py", line 172, in _add_to_criteria
if not criterion.candidates:
File "/home/user/code/home-stuff/.venv/lib/python3.10/site-packages/pip/_vendor/resolvelib/structs.py", line 151, in __bool__
return bool(self._sequence)
File "/home/user/code/home-stuff/.venv/lib/python3.10/site-packages/pip/_internal/resolution/resolvelib/found_candidates.py", line 155, in __bool__
return any(self)
File "/home/user/code/home-stuff/.venv/lib/python3.10/site-packages/pip/_internal/resolution/resolvelib/found_candidates.py", line 143, in <genexpr>
return (c for c in iterator if id(c) not in self._incompatible_ids)
File "/home/user/code/home-stuff/.venv/lib/python3.10/site-packages/pip/_internal/resolution/resolvelib/found_candidates.py", line 44, in _iter_built
for version, func in infos:
File "/home/user/code/home-stuff/.venv/lib/python3.10/site-packages/pip/_internal/resolution/resolvelib/factory.py", line 294, in iter_index_candidate_infos
result = self._finder.find_best_candidate(
File "/home/user/code/home-stuff/.venv/lib/python3.10/site-packages/pip/_internal/index/package_finder.py", line 868, in find_best_candidate
candidates = self.find_all_candidates(project_name)
File "/home/user/code/home-stuff/.venv/lib/python3.10/site-packages/pip/_internal/index/package_finder.py", line 809, in find_all_candidates
page_candidates = list(page_candidates_it)
File "/home/user/code/home-stuff/.venv/lib/python3.10/site-packages/pip/_internal/index/sources.py", line 134, in page_candidates
yield from self._candidates_from_page(self._link)
File "/home/user/code/home-stuff/.venv/lib/python3.10/site-packages/pip/_internal/index/package_finder.py", line 769, in process_project_url
html_page = self._link_collector.fetch_page(project_url)
File "/home/user/code/home-stuff/.venv/lib/python3.10/site-packages/pip/_internal/index/collector.py", line 604, in fetch_page
return _get_html_page(location, session=self.session)
File "/home/user/code/home-stuff/.venv/lib/python3.10/site-packages/pip/_internal/index/collector.py", line 509, in _get_html_page
resp = _get_html_response(url, session=session)
File "/home/user/code/home-stuff/.venv/lib/python3.10/site-packages/pip/_internal/index/collector.py", line 125, in _get_html_response
resp = session.get(
File "/home/user/code/home-stuff/.venv/lib/python3.10/site-packages/pip/_vendor/requests/sessions.py", line 542, in get
return self.request('GET', url, **kwargs)
File "/home/user/code/home-stuff/.venv/lib/python3.10/site-packages/pip/_internal/network/session.py", line 454, in request
return super().request(method, url, *args, **kwargs)
File "/home/user/code/home-stuff/.venv/lib/python3.10/site-packages/pip/_vendor/requests/sessions.py", line 529, in request
resp = self.send(prep, **send_kwargs)
File "/home/user/code/home-stuff/.venv/lib/python3.10/site-packages/pip/_vendor/requests/sessions.py", line 645, in send
r = adapter.send(request, **kwargs)
File "/home/user/code/home-stuff/.venv/lib/python3.10/site-packages/pip/_vendor/cachecontrol/adapter.py", line 57, in send
resp = super(CacheControlAdapter, self).send(request, **kw)
File "/home/user/code/home-stuff/.venv/lib/python3.10/site-packages/pip/_vendor/requests/adapters.py", line 413, in send
conn = self.get_connection(request.url, proxies)
File "/home/user/code/home-stuff/.venv/lib/python3.10/site-packages/pip/_vendor/requests/adapters.py", line 316, in get_connection
conn = self.poolmanager.connection_from_url(url)
File "/home/user/code/home-stuff/.venv/lib/python3.10/site-packages/pip/_vendor/urllib3/poolmanager.py", line 299, in connection_from_url
u.host_ip, port=u.port, scheme=u.scheme, pool_kwargs=pool_kwargs
AttributeError: 'Url' object has no attribute 'host_ip'
I'm running linux mint 21 with Python 3.10. Not sure what caused this issue as the only changes I've made recently were system updates (via apt upgrade).
After poking around for a bit and trying a few things, I deleted my virtual environment (rm -rf .venv) and recreated it via python -m venv .venv.

PIP fails installing pylint

I have been using spyder for last three years, and just moved on to Visual Studio Code.
VSC is recommending me to install pylint, but my cmd outputs this.
C:\WINDOWS\system32>pip install pylint
ERROR: Exception:
Traceback (most recent call last):
File "c:\users\newsk\appdata\local\programs\python\python38-32\lib\site-packages\pip\_internal\cli\base_command.py", line 188, in _main
status = self.run(options, args)
File "c:\users\newsk\appdata\local\programs\python\python38-32\lib\site-packages\pip\_internal\cli\req_command.py", line 185, in wrapper
return func(self, options, args)
File "c:\users\newsk\appdata\local\programs\python\python38-32\lib\site-packages\pip\_internal\commands\install.py", line 332, in run
requirement_set = resolver.resolve(
File "c:\users\newsk\appdata\local\programs\python\python38-32\lib\site-packages\pip\_internal\resolution\legacy\resolver.py", line 179, in resolve
discovered_reqs.extend(self._resolve_one(requirement_set, req))
File "c:\users\newsk\appdata\local\programs\python\python38-32\lib\site-packages\pip\_internal\resolution\legacy\resolver.py", line 362, in _resolve_one
abstract_dist = self._get_abstract_dist_for(req_to_install)
File "c:\users\newsk\appdata\local\programs\python\python38-32\lib\site-packages\pip\_internal\resolution\legacy\resolver.py", line 313, in _get_abstract_dist_for
self._populate_link(req)
File "c:\users\newsk\appdata\local\programs\python\python38-32\lib\site-packages\pip\_internal\resolution\legacy\resolver.py", line 279, in _populate_link
req.link = self.finder.find_requirement(req, upgrade)
File "c:\users\newsk\appdata\local\programs\python\python38-32\lib\site-packages\pip\_internal\index\package_finder.py", line 900, in find_requirement
best_candidate_result = self.find_best_candidate(
File "c:\users\newsk\appdata\local\programs\python\python38-32\lib\site-packages\pip\_internal\index\package_finder.py", line 883, in find_best_candidate
candidates = self.find_all_candidates(project_name)
File "c:\users\newsk\appdata\local\programs\python\python38-32\lib\site-packages\pip\_internal\index\package_finder.py", line 827, in find_all_candidates
package_links = self.process_project_url(
File "c:\users\newsk\appdata\local\programs\python\python38-32\lib\site-packages\pip\_internal\index\package_finder.py", line 792, in process_project_url
html_page = self._link_collector.fetch_page(project_url)
File "c:\users\newsk\appdata\local\programs\python\python38-32\lib\site-packages\pip\_internal\index\collector.py", line 612, in fetch_page
return _get_html_page(location, session=self.session)
File "c:\users\newsk\appdata\local\programs\python\python38-32\lib\site-packages\pip\_internal\index\collector.py", line 451, in _get_html_page
resp = _get_html_response(url, session=session)
File "c:\users\newsk\appdata\local\programs\python\python38-32\lib\site-packages\pip\_internal\index\collector.py", line 149, in _get_html_response
resp = session.get(
File "c:\users\newsk\appdata\local\programs\python\python38-32\lib\site-packages\pip\_vendor\requests\sessions.py", line 543, in get
return self.request('GET', url, **kwargs)
File "c:\users\newsk\appdata\local\programs\python\python38-32\lib\site-packages\pip\_internal\network\session.py", line 421, in request
return super(PipSession, self).request(method, url, *args, **kwargs)
File "c:\users\newsk\appdata\local\programs\python\python38-32\lib\site-packages\pip\_vendor\requests\sessions.py", line 520, in request
settings = self.merge_environment_settings(
File "c:\users\newsk\appdata\local\programs\python\python38-32\lib\site-packages\pip\_vendor\requests\sessions.py", line 697, in merge_environment_settings
env_proxies = get_environ_proxies(url, no_proxy=no_proxy)
File "c:\users\newsk\appdata\local\programs\python\python38-32\lib\site-packages\pip\_vendor\requests\utils.py", line 766, in get_environ_proxies
if should_bypass_proxies(url, no_proxy=no_proxy):
File "c:\users\newsk\appdata\local\programs\python\python38-32\lib\site-packages\pip\_vendor\requests\utils.py", line 750, in should_bypass_proxies
bypass = proxy_bypass(parsed.hostname)
File "c:\users\newsk\appdata\local\programs\python\python38-32\lib\site-packages\pip\_vendor\requests\utils.py", line 96, in proxy_bypass
return proxy_bypass_registry(host)
File "c:\users\newsk\appdata\local\programs\python\python38-32\lib\site-packages\pip\_vendor\requests\utils.py", line 61, in proxy_bypass_registry
proxyEnable = int(winreg.QueryValueEx(internetSettings,
ValueError: invalid literal for int() with base 10: b'\x00\x00\x00\x00'
I had a similar message last time when I tried to install tensorflow using pip.
Can anybody help me with this issue?
Thanks.

MacOS Python 3 netrc operations end up with UnicodeDecodeError

On MacOS (Mojave, same on High Sierra) with Python 3, after installing and using pyenv for some time, seemingly all operations that use a network connection return a UnicodeDecodeError.
So far I've tried using various versions of Python 3 (3.6.Xs, 3.7 tried), system provided python, uninstalling pyenv and reinstalling Python3 with brew, setting locale in ~/.bashrc, ~/.bash_profile, ~/.profile to en_US.UTF-8, running commands with prefixed PYTHONIOENCODING=utf-8 or LC_CTYPE=en_US.UTF-8.
The issue still presents when used with different Python 3 distributions (tried Anaconda, brew).
Returning to MacOs's python 2 fixed similar issue with python2 stack.
Examples (all issues present with different python3 distributions):
Using pip3 (pyenv 3.7)
pip3 install requests
Collecting requests
Exception:
Traceback (most recent call last):
File "/Users/nikolaj/.pyenv/versions/3.7.1/lib/python3.7/site-packages/pip/_internal/basecommand.py", line 228, in main
status = self.run(options, args)
File "/Users/nikolaj/.pyenv/versions/3.7.1/lib/python3.7/site-packages/pip/_internal/commands/install.py", line 291, in run
resolver.resolve(requirement_set)
File "/Users/nikolaj/.pyenv/versions/3.7.1/lib/python3.7/site-packages/pip/_internal/resolve.py", line 103, in resolve
self._resolve_one(requirement_set, req)
File "/Users/nikolaj/.pyenv/versions/3.7.1/lib/python3.7/site-packages/pip/_internal/resolve.py", line 257, in _resolve_one
abstract_dist = self._get_abstract_dist_for(req_to_install)
File "/Users/nikolaj/.pyenv/versions/3.7.1/lib/python3.7/site-packages/pip/_internal/resolve.py", line 210, in _get_abstract_dist_for
self.require_hashes
File "/Users/nikolaj/.pyenv/versions/3.7.1/lib/python3.7/site-packages/pip/_internal/operations/prepare.py", line 245, in prepare_linked_requirement
req.populate_link(finder, upgrade_allowed, require_hashes)
File "/Users/nikolaj/.pyenv/versions/3.7.1/lib/python3.7/site-packages/pip/_internal/req/req_install.py", line 307, in populate_link
self.link = finder.find_requirement(self, upgrade)
File "/Users/nikolaj/.pyenv/versions/3.7.1/lib/python3.7/site-packages/pip/_internal/index.py", line 484, in find_requirement
all_candidates = self.find_all_candidates(req.name)
File "/Users/nikolaj/.pyenv/versions/3.7.1/lib/python3.7/site-packages/pip/_internal/index.py", line 442, in find_all_candidates
for page in self._get_pages(url_locations, project_name):
File "/Users/nikolaj/.pyenv/versions/3.7.1/lib/python3.7/site-packages/pip/_internal/index.py", line 587, in _get_pages
page = self._get_page(location)
File "/Users/nikolaj/.pyenv/versions/3.7.1/lib/python3.7/site-packages/pip/_internal/index.py", line 705, in _get_page
return HTMLPage.get_page(link, session=self.session)
File "/Users/nikolaj/.pyenv/versions/3.7.1/lib/python3.7/site-packages/pip/_internal/index.py", line 814, in get_page
"Cache-Control": "max-age=600",
File "/Users/nikolaj/.pyenv/versions/3.7.1/lib/python3.7/site-packages/pip/_vendor/requests/sessions.py", line 521, in get
return self.request('GET', url, **kwargs)
File "/Users/nikolaj/.pyenv/versions/3.7.1/lib/python3.7/site-packages/pip/_internal/download.py", line 397, in request
return super(PipSession, self).request(method, url, *args, **kwargs)
File "/Users/nikolaj/.pyenv/versions/3.7.1/lib/python3.7/site-packages/pip/_vendor/requests/sessions.py", line 494, in request
prep = self.prepare_request(req)
File "/Users/nikolaj/.pyenv/versions/3.7.1/lib/python3.7/site-packages/pip/_vendor/requests/sessions.py", line 437, in prepare_request
hooks=merge_hooks(request.hooks, self.hooks),
File "/Users/nikolaj/.pyenv/versions/3.7.1/lib/python3.7/site-packages/pip/_vendor/requests/models.py", line 309, in prepare
self.prepare_auth(auth, url)
File "/Users/nikolaj/.pyenv/versions/3.7.1/lib/python3.7/site-packages/pip/_vendor/requests/models.py", line 540, in prepare_auth
r = auth(self)
File "/Users/nikolaj/.pyenv/versions/3.7.1/lib/python3.7/site-packages/pip/_internal/download.py", line 161, in __call__
netrc_auth = get_netrc_auth(req.url)
File "/Users/nikolaj/.pyenv/versions/3.7.1/lib/python3.7/site-packages/pip/_vendor/requests/utils.py", line 195, in get_netrc_auth
_netrc = netrc(netrc_path).authenticators(host)
File "/Users/nikolaj/.pyenv/versions/3.7.1/lib/python3.7/netrc.py", line 30, in __init__
self._parse(file, fp, default_netrc)
File "/Users/nikolaj/.pyenv/versions/3.7.1/lib/python3.7/netrc.py", line 39, in _parse
toplevel = tt = lexer.get_token()
File "/Users/nikolaj/.pyenv/versions/3.7.1/lib/python3.7/shlex.py", line 105, in get_token
raw = self.read_token()
File "/Users/nikolaj/.pyenv/versions/3.7.1/lib/python3.7/shlex.py", line 136, in read_token
nextchar = self.instream.read(1)
File "/Users/nikolaj/.pyenv/versions/3.7.1/lib/python3.7/codecs.py", line 322, in decode
(result, consumed) = self._buffer_decode(data, self.errors, final)
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xc5 in position 104: invalid continuation byte
Decoding responses to standard requests (on Anaconda)
Python 3.7.1 (default, Dec 14 2018, 13:28:58)
[Clang 4.0.1 (tags/RELEASE_401/final)] :: Anaconda, Inc. on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import requests
>>> requests.get("http://www.google.pl")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/anaconda3/lib/python3.7/site-packages/requests/api.py", line 75, in get
return request('get', url, params=params, **kwargs)
File "/anaconda3/lib/python3.7/site-packages/requests/api.py", line 60, in request
return session.request(method=method, url=url, **kwargs)
File "/anaconda3/lib/python3.7/site-packages/requests/sessions.py", line 519, in request
prep = self.prepare_request(req)
File "/anaconda3/lib/python3.7/site-packages/requests/sessions.py", line 449, in prepare_request
auth = get_netrc_auth(request.url)
File "/anaconda3/lib/python3.7/site-packages/requests/utils.py", line 203, in get_netrc_auth
_netrc = netrc(netrc_path).authenticators(host)
File "/anaconda3/lib/python3.7/netrc.py", line 30, in __init__
self._parse(file, fp, default_netrc)
File "/anaconda3/lib/python3.7/netrc.py", line 39, in _parse
toplevel = tt = lexer.get_token()
File "/anaconda3/lib/python3.7/shlex.py", line 105, in get_token
raw = self.read_token()
File "/anaconda3/lib/python3.7/shlex.py", line 136, in read_token
nextchar = self.instream.read(1)
File "/anaconda3/lib/python3.7/codecs.py", line 322, in decode
(result, consumed) = self._buffer_decode(data, self.errors, final)
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xc5 in position 104: invalid continuation byte
My locale configuration
locale
LANG="en_US.UTF-8"
LC_COLLATE="en_US.UTF-8"
LC_CTYPE="en_US.UTF-8"
LC_MESSAGES="en_US.UTF-8"
LC_MONETARY="en_US.UTF-8"
LC_NUMERIC="en_US.UTF-8"
LC_TIME="en_US.UTF-8"
LC_ALL="en_US.UTF-8"
You need to fix your ~/.netrc file to contain UTF-8-clean data. Currently it does not.
See the .netrc file documentation on what the file should contain.
The problem doesn't arise on Python 2, because there the file is not opened as Unicode text (Python 2 mostly operates in a binary data world).

Installing Flask on python

I'm trying to install Flask and I get this error:
C:\Users\Eirik\myproject>venv\scripts\activate
(venv) C:\Users\Eirik\myproject>pip install flask
Collecting flask
Exception:
Traceback (most recent call last):
File "c:\users\eirik\myproject\venv\lib\site-packages\pip\basecommand.py", line 211, in main
status = self.run(options, args)
File "c:\users\eirik\myproject\venv\lib\site-packages\pip\commands\install.py", line 305, in run
wb.build(autobuilding=True)
File "c:\users\eirik\myproject\venv\lib\site-packages\pip\wheel.py", line 705, in build
self.requirement_set.prepare_files(self.finder)
File "c:\users\eirik\myproject\venv\lib\site-packages\pip\req\req_set.py", line 334, in prepare_files
functools.partial(self._prepare_file, finder))
File "c:\users\eirik\myproject\venv\lib\site-packages\pip\req\req_set.py", line 321, in _walk_req_to_install
more_reqs = handler(req_to_install)
File "c:\users\eirik\myproject\venv\lib\site-packages\pip\req\req_set.py", line 461, in _prepare_file
req_to_install.populate_link(finder, self.upgrade)
File "c:\users\eirik\myproject\venv\lib\site-packages\pip\req\req_install.py", line 250, in populate_link
self.link = finder.find_requirement(self, upgrade)
File "c:\users\eirik\myproject\venv\lib\site-packages\pip\index.py", line 486, in find_requirement
all_versions = self._find_all_versions(req.name)
File "c:\users\eirik\myproject\venv\lib\site-packages\pip\index.py", line 404, in _find_all_versions
index_locations = self._get_index_urls_locations(project_name)
File "c:\users\eirik\myproject\venv\lib\site-packages\pip\index.py", line 378, in _get_index_urls_locations
page = self._get_page(main_index_url)
File "c:\users\eirik\myproject\venv\lib\site-packages\pip\index.py", line 818, in _get_page
return HTMLPage.get_page(link, session=self.session)
File "c:\users\eirik\myproject\venv\lib\site-packages\pip\index.py", line 928, in get_page
"Cache-Control": "max-age=600",
File "c:\users\eirik\myproject\venv\lib\site-packages\pip\_vendor\requests\sessions.py", line 477, in get
return self.request('GET', url, **kwargs)
File "c:\users\eirik\myproject\venv\lib\site-packages\pip\download.py", line 373, in request
return super(PipSession, self).request(method, url, *args, **kwargs)
File "c:\users\eirik\myproject\venv\lib\site-packages\pip\_vendor\requests\sessions.py", line 465, in request
resp = self.send(prep, **send_kwargs)
File "c:\users\eirik\myproject\venv\lib\site-packages\pip\_vendor\requests\sessions.py", line 605, in send
r.content
File "c:\users\eirik\myproject\venv\lib\site-packages\pip\_vendor\requests\models.py", line 750, in content
self._content = bytes().join(self.iter_content(CONTENT_CHUNK_SIZE)) or bytes()
File "c:\users\eirik\myproject\venv\lib\site-packages\pip\_vendor\requests\models.py", line 673, in generate
for chunk in self.raw.stream(chunk_size, decode_content=True):
File "c:\users\eirik\myproject\venv\lib\site-packages\pip\_vendor\requests\packages\urllib3\response.py", line 307, in stream
data = self.read(amt=amt, decode_content=decode_content)
File "c:\users\eirik\myproject\venv\lib\site-packages\pip\_vendor\requests\packages\urllib3\response.py", line 243, in read
data = self._fp.read(amt)
File "c:\users\eirik\myproject\venv\lib\site-packages\pip\_vendor\cachecontrol\filewrapper.py", line 54, in read
self.__callback(self.__buf.getvalue())
File "c:\users\eirik\myproject\venv\lib\site-packages\pip\_vendor\cachecontrol\controller.py", line 244, in cache_response
self.serializer.dumps(request, response, body=body),
File "c:\users\eirik\myproject\venv\lib\site-packages\pip\download.py", line 276, in set
return super(SafeFileCache, self).set(*args, **kwargs)
File "c:\users\eirik\myproject\venv\lib\site-packages\pip\_vendor\cachecontrol\caches\file_cache.py", line 99, in set
with self.lock_class(name) as lock:
File "c:\users\eirik\myproject\venv\lib\site-packages\pip\_vendor\lockfile\mkdirlockfile.py", line 18, in __init__
LockBase.__init__(self, path, threaded, timeout)
File "c:\users\eirik\myproject\venv\lib\site-packages\pip\_vendor\lockfile\__init__.py", line 189, in __init__
hash(self.path)))
File "c:\users\eirik\myproject\venv\lib\ntpath.py", line 85, in join
result_path = result_path + p_path
UnicodeDecodeError: 'ascii' codec can't decode byte 0xe6 in position 13: ordinal not in range(128)
I suspect the error might be caused by some special char or something like that, but not sure what. I can't find anything that should cause this, tho i'm very inexperienced with this.
Installing Python went fine, then I installed virtualenv (easy_tools or what it's called again) I got everything working, even activating the virtualenv, but when I try to install Flask as mentioned I get this error.
this is python problem as Python 3 has default UTF-8 encodings while it is not in case of earlier versions....try this to resolve
Search mimetypes.py in your python directory it would be in Lib folder of Python
Open it and find the following lines
try:
ctype = ctype.encode(default_encoding) # omit in 3.x!
except UnicodeEncodeError:
pass and change it to
try:
ctype = ctype.encode(default_encoding) # omit in 3.x!
except UnicodeDecodeError:
print ctype
Hope this might have solved the problem...and try to use Python 3
I found the solution! Because I live in Scandinavia we have some special letters like "æ, ø, å" - This is what was causing the problem. To get "Virtualenv" to work I had to change my username (and my user folder under C:\Users) to something without those letters in them. Then I managed to install Virtualenv.
However, I got the same error when trying to install flask as this post was about: I found out that my computer name was causing the problem. It also contained special letters, but I changed it late last night and forgot to reboot the computer so the changes take effect - after I rebooted now (I always put my computer to sleep from my tablet and wake it up the same way) it works.
So I guess it's 10 hours of google and forum posting for nothing.
Anyway the solution is to not have any special letters in your username or computer name.
Thanks for all the help you guys gave me! Now on to the assignment!

UnicodeDecodeError in pip install flake8 on Windows 8.1

I'm trying to install the flake8 module for Python (in order to use the SublimeLinter-flake8 package to Sublime Text 3) but get an error message on install (below). What am I doing wrong here?
C:\Windows\system32>python -m pip install flake8
Collecting flake8
Exception:
Traceback (most recent call last):
File "C:\Python27\lib\site-packages\pip\basecommand.py", line 223, in main
status = self.run(options, args)
File "C:\Python27\lib\site-packages\pip\commands\install.py", line 280, in run
requirement_set.prepare_files(finder)
File "C:\Python27\lib\site-packages\pip\req\req_set.py", line 317, in prepare_files
functools.partial(self._prepare_file, finder))
File "C:\Python27\lib\site-packages\pip\req\req_set.py", line 304, in _walk_req_to_install
more_reqs = handler(req_to_install)
File "C:\Python27\lib\site-packages\pip\req\req_set.py", line 439, in _prepare_file
req_to_install.populate_link(finder, self.upgrade)
File "C:\Python27\lib\site-packages\pip\req\req_install.py", line 244, in populate_link
self.link = finder.find_requirement(self, upgrade)
File "C:\Python27\lib\site-packages\pip\index.py", line 486, in find_requirement
all_versions = self._find_all_versions(req.name)
File "C:\Python27\lib\site-packages\pip\index.py", line 404, in _find_all_versions
index_locations = self._get_index_urls_locations(project_name)
File "C:\Python27\lib\site-packages\pip\index.py", line 378, in _get_index_urls_locations
page = self._get_page(main_index_url)
File "C:\Python27\lib\site-packages\pip\index.py", line 810, in _get_page
return HTMLPage.get_page(link, session=self.session)
File "C:\Python27\lib\site-packages\pip\index.py", line 920, in get_page
"Cache-Control": "max-age=600",
File "C:\Python27\lib\site-packages\pip\_vendor\requests\sessions.py", line 477, in get
return self.request('GET', url, **kwargs)
File "C:\Python27\lib\site-packages\pip\download.py", line 373, in request
return super(PipSession, self).request(method, url, *args, **kwargs)
File "C:\Python27\lib\site-packages\pip\_vendor\requests\sessions.py", line 465, in request
resp = self.send(prep, **send_kwargs)
File "C:\Python27\lib\site-packages\pip\_vendor\requests\sessions.py", line 605, in send
r.content
File "C:\Python27\lib\site-packages\pip\_vendor\requests\models.py", line 750, in content
self._content = bytes().join(self.iter_content(CONTENT_CHUNK_SIZE)) or bytes()
File "C:\Python27\lib\site-packages\pip\_vendor\requests\models.py", line 673, in generate
for chunk in self.raw.stream(chunk_size, decode_content=True):
File "C:\Python27\lib\site-packages\pip\_vendor\requests\packages\urllib3\response.py", line 307, in stream
data = self.read(amt=amt, decode_content=decode_content)
File "C:\Python27\lib\site-packages\pip\_vendor\requests\packages\urllib3\response.py", line 243, in read
data = self._fp.read(amt)
File "C:\Python27\lib\site-packages\pip\_vendor\cachecontrol\filewrapper.py", line 54, in read
self.__callback(self.__buf.getvalue())
File "C:\Python27\lib\site-packages\pip\_vendor\cachecontrol\controller.py", line 244, in cache_response
self.serializer.dumps(request, response, body=body),
File "C:\Python27\lib\site-packages\pip\download.py", line 276, in set
return super(SafeFileCache, self).set(*args, **kwargs)
File "C:\Python27\lib\site-packages\pip\_vendor\cachecontrol\caches\file_cache.py", line 99, in set
with self.lock_class(name) as lock:
File "C:\Python27\lib\site-packages\pip\_vendor\lockfile\mkdirlockfile.py", line 18, in __init__
LockBase.__init__(self, path, threaded, timeout)
File "C:\Python27\lib\site-packages\pip\_vendor\lockfile\__init__.py", line 189, in __init__
hash(self.path)))
File "C:\Python27\lib\ntpath.py", line 85, in join
result_path = result_path + p_path
UnicodeDecodeError: 'ascii' codec can't decode byte 0xe4 in position 9: ordinal not in range(128)
After startlingly generous help from Padraic, we eventually figured out that the problem was my computer name, which was Fredrik-Bärbar (notice the ä, i.e. 0xe4 in code page 850, there in the 10th place, or 9th place using Python's 0-based indexing).
(This error is related to that in Pip Error when installing, another question solved by Padraic.)

Categories

Resources