9

When I'm trying to install beautifulsoup4 on my new notebook (Win 7 64) using pip, I get this error:

Cleaning up...
Exception:
Traceback (most recent call last):
  File "C:\Python27\lib\site-packages\pip\basecommand.py", line 122, in main
    status = self.run(options, args)
  File "C:\Python27\lib\site-packages\pip\commands\install.py", line 278, in run

    requirement_set.prepare_files(finder, force_root_egg_info=self.bundle, bundl
e=self.bundle)
  File "C:\Python27\lib\site-packages\pip\req.py", line 1234, in prepare_files
    req_to_install.assert_source_matches_version()
  File "C:\Python27\lib\site-packages\pip\req.py", line 464, in assert_source_ma
tches_version
    % (display_path(self.source_dir), version, self))
UnicodeDecodeError: 'ascii' codec can't decode byte 0x9e in position 58: ordinal
 not in range(128)

Traceback (most recent call last):
  File "C:\Python27\lib\runpy.py", line 162, in _run_module_as_main
    "__main__", fname, loader, pkg_name)
  File "C:\Python27\lib\runpy.py", line 72, in _run_code
    exec code in run_globals
  File "C:\Python27\Scripts\pip.exe\__main__.py", line 9, in <module>
  File "C:\Python27\lib\site-packages\pip\__init__.py", line 185, in main
    return command.main(cmd_args)
  File "C:\Python27\lib\site-packages\pip\basecommand.py", line 161, in main
    text = '\n'.join(complete_log)
UnicodeDecodeError: 'ascii' codec can't decode byte 0x9e in position 73: ordinal
 not in range(128)

I use: pip install beautifulsoup4 command

Do you have an idea where could be the problem?

PS: The notebook was used for presentations before get it, so there are programs in multiple languages installed.

Milano
  • 16,084
  • 32
  • 124
  • 293
  • 2
    have you tried easy_install? – Selva Jul 30 '14 at 12:35
  • @Selva After I've read your advice, I tried it and it works! Thank you! But I'm still wondering why PIP throws error. – Milano Jul 30 '14 at 15:01
  • 1
    https://python-packaging-user-guide.readthedocs.org/en/latest/technical.html#pip-vs-easy-install this is will give you some idea – Selva Jul 31 '14 at 05:28
  • In my case, [changing the cmd.exe terminal to UTF-8 worked](https://stackoverflow.com/questions/388490/how-to-use-unicode-characters-in-windows-command-line/388500#388500) – José May 22 '18 at 21:55

5 Answers5

25

Or simply, you can run the following command on your system right before pip install, and voila:

export LC_ALL="en_US.UTF-8"
sherifzain
  • 357
  • 3
  • 6
  • 5
    1) Could you elaborate why you think this helps to solve the OPs question. Maybe it helps someone else. 2) This looks like a bash command. The OP is using Windows so this would be of no use for him. – m00am Nov 05 '15 at 10:01
  • 1
    A similar solution worked for me on Amazon Linux, I've set the following environment variable in the console: `LANG=en_US.UTF-8` – ulysses May 17 '16 at 22:49
  • This worked for me also. I had to add the locale to /etc/local.gen and run locale-gen first, tho! – tu-Reinstate Monica-dor duh May 23 '16 at 08:44
  • If you get a warning `cannot change locale` you might need to install en_US.UTF-8 -- https://askubuntu.com/a/227513 – MatrixManAtYrService Nov 29 '17 at 04:47
7

This is a known issue with pip with an unreleased (as of 26/11/2014) fix. Since you are using Python 2.7, you can manually patch pip for now.

jds
  • 7,509
  • 8
  • 58
  • 95
5

This is because your current working directory contains non-ascii characters. E.g.:

$ pwd
$ /home/abuser/Загрузки

This issue is still present in pip 1.5.6 and this is awful. So, you can avoid patching pip and just change your working dir.

oblalex
  • 4,696
  • 2
  • 22
  • 25
  • 1
    Unfortunately this did not work for me. I changed dir back to `C:\` but still got the error. In my case my username has cyrillic characters. – asmaier Nov 07 '16 at 22:13
  • It seems having a username with non-ascii characters is another problem of pip I stumbled upon: https://github.com/pypa/pip/issues/2501 – asmaier Nov 07 '16 at 22:21
0

In my case it was caused because where were non US-ASCII letters in requirements.txt

Matt
  • 1,317
  • 1
  • 13
  • 21
0

In my case it was because pip was facing encoding issues when reading setup.cfg file of the repository. Initially when I used PyCharm venvpy creator with default terminal set to gitbash, I was constantly getting this error. Then I manually created my virtual environment with venv in powershell and I didn't get this error, although I got following warning WARNING: Ignore distutils configs in setup.cfg due to encoding errors.