0

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)
Fredrik P
  • 682
  • 1
  • 8
  • 21
  • 1
    what version of pip are you using? – Padraic Cunningham Jun 06 '15 at 19:49
  • I don't know :-( I installed Python 2.7.10 just a few minutes ago, if that tells you what you need. – Fredrik P Jun 06 '15 at 20:00
  • @PadraicCunningham Where? In the command prompt, I get `Did not provide a command` and, in the Python command line, I get `NameError: name 'pip' is not defined` – Fredrik P Jun 06 '15 at 20:04
  • 1
    Ah ok so you are using the pip installed with the python install. You need to add pip to your path. I would probably upgrade pip to the latest anyway . – Padraic Cunningham Jun 06 '15 at 20:24
  • 1
    You can get the latest from here https://bootstrap.pypa.io/get-pip.py then python get-pip.py and add the c:\pthon2.7\scripts folder to your environment variables – Padraic Cunningham Jun 06 '15 at 20:25
  • @PadraicCunningham I did add it to PATH (as you see above pip started collecting flake8 before there was an error). I will try to upgrade tomorrow and see if that changes anything. – Fredrik P Jun 06 '15 at 20:31
  • 1
    You should be able to type `pip install ...` without needing to use python -m if it were in your path. What is your shell encoding? – Padraic Cunningham Jun 06 '15 at 20:32
  • @PadraicCunningham These are deep waters for me. Shell encoding? How do I see that? I'm using Windows 8.1 in Swedish. (Sorry for being such a n00b and thanks for bearing with me.) – Fredrik P Jun 06 '15 at 20:41
  • 1
    I think `chcp` should get the encoding, I presume you have non ascii in your path names? – Padraic Cunningham Jun 06 '15 at 20:45
  • @PadraicCunningham The code page is 850. And I _can_ use non ascii characters in paths, but there are not any in the error output pasted above so I wouldn't think that was an issue here. – Fredrik P Jun 07 '15 at 04:31
  • 1
    There is, the error is coming from `ntpath` trying to decode `0xe4 -> ä` to ascii – Padraic Cunningham Jun 07 '15 at 11:38
  • @PadraicCunningham Shame on me! I didn't notice it. But I can't see what path might contain ä. I've installed Python in `C:\Python27`. – Fredrik P Jun 07 '15 at 14:36
  • @PadraicCunningham Also, `C:\Python27\Scripts\` _is_ in the `%PATH%` environment variable. Yet, `pip install flake8` does not execute `pip` from any other directory than `C:\Python\Scripts\`. – Fredrik P Jun 07 '15 at 14:44
  • 1
    Did you try installing pip with get-pip? – Padraic Cunningham Jun 07 '15 at 14:45
  • @PadraicCunningham I actually get practically the same error output from `python get-pip.py`. A path is different and `File "...\req\req_set.py", line 439, in _prepare_file req_to_install.populate_link(finder, self.upgrade) File "...\req\req_install.py", line 244, in populate_link self.link = finder.find_requirement(self, upgrade)` is replaced by `File "...\req\req_set.py", line 387, in _prepare_file req_to_install, finder) File "...\req\req_set.py", line 348, in _check_skip_installed finder.find_requirement(req_to_install, self.upgrade)`. – Fredrik P Jun 07 '15 at 15:01
  • 1
    so again an ascii error? Do you have swedish characters in your directory paths? – Padraic Cunningham Jun 07 '15 at 15:34
  • @PadraicCunningham Yes, again an ascii error. But I don't know what you mean by directory paths, so I couldn't say if I've swedish characters in them :-( – Fredrik P Jun 07 '15 at 15:42
  • 1
    I mean like `C:\Users\name_with_non-ascii_chars` – Padraic Cunningham Jun 07 '15 at 16:54
  • @PadraicCunningham Afraid not, there is only one user on this computer, `Fredrik`, and that's also the name of the user folder. – Fredrik P Jun 07 '15 at 17:02
  • In reference to [this post](http://stackoverflow.com/questions/28580439/pip-error-when-installing) that you solved a while back, the corresponding path for me is `c:\users\fredrik\appdata\local\temp\tmp0nax2w\pip.zip\pip\_vendor\lockfile\__init__.py`. But for me it is position 9 as in the question here that contains the faulty character. If it really is that path that causes the error then the character should be the `e` in `Fredrik`. But that doesn't really make any sense :-/ – Fredrik P Jun 07 '15 at 18:27
  • 1
    what does `import locale;locale.getdefaultlocale()` output? Also what did the ascii error point to when you tried installing pip? – Padraic Cunningham Jun 07 '15 at 18:33
  • @PadraicCunningham `('sv_SE', 'cp1252')` – Fredrik P Jun 07 '15 at 19:39
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/79906/discussion-between-fredrik-p-and-padraic-cunningham). – Fredrik P Jun 07 '15 at 19:40

1 Answers1

1

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.)

Community
  • 1
  • 1
Fredrik P
  • 682
  • 1
  • 8
  • 21