17

When I'm trying to install StringGenerator with pip, I am prompted with this error:

C:\Users\Administrator> pip install StringGenerator

Collecting StringGenerator 
Using cached StringGenerator-0.3.0.tar.gz
Complete output from command python setup.py egg_info:
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "C:\Users\ADMINI~1\AppData\Local\Temp\2\pip-build-mdvrj2cf\StringGenerator\setup.py", line 7, in <module>
    long_description = file.read()
  File "c:\users\administrator\appdata\local\programs\python\python36-32\lib\encodings\cp1252.py", line 23, in decode
    return codecs.charmap_decode(input,self.errors,decoding_table)[0]
UnicodeDecodeError: 'charmap' codec can't decode byte 0x9d in position 1264: character maps to <undefined>

    ----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in C:\Users\ADMINI~1\AppData\Local\Temp\2\pip-build-mdvrj2cf\StringGenerator\
Taku
  • 31,927
  • 11
  • 74
  • 85
Kyle
  • 391
  • 2
  • 5
  • 18
  • Try an administrator command prompt – Mattwmaster58 Apr 03 '18 at 23:29
  • Still getting an error. – Kyle Apr 03 '18 at 23:33
  • have you tried using pip? `pip install StringGenerator`....https://pypi.python.org/pypi/StringGenerator/0.3.0 – johnashu Apr 03 '18 at 23:38
  • Yep, that's whats giving me the error :/ – Kyle Apr 03 '18 at 23:43
  • Is that really the full output from `pip`? – abarnert Apr 03 '18 at 23:46
  • Also, is there really a space between `ADMINI~1` and `\AppData` in those errors? If so, that seems like a serious problem that could break all kinds of things, but I can't imagine how it could even happen. – abarnert Apr 03 '18 at 23:49
  • I have installed other modules with pip no problem. Not sure why this is popping up. This is also a fresh server that I just deployed. – Kyle Apr 03 '18 at 23:52
  • You need to post the full traceback of the pip install error (with the inclusion of the command you ran that produces this error). The current error message is not enough to do any debugging. – Taku Apr 03 '18 at 23:54
  • The fact that you've used `pip` before doesn't answer the question of whether that's really the full output, and whether it's the accurate output. – abarnert Apr 03 '18 at 23:54
  • I have updated the post. – Kyle Apr 04 '18 at 00:00

4 Answers4

35

The problem is caused during the setup process when reading README.txt. In Windows, the default encoding is cp1252, but that readme file is most likely encoded in UTF8.

The error message tells you that cp1252 codec is unable to decode the character with the byte 0x9D. When I browsed through the readme file, I found this character: (also known as: "RIGHT DOUBLE QUOTATION MARK"), which has the bytes 0xE2 0x80 0x9D, which includes the problematic byte.

What you can do is:

  1. Download the package here
  2. Decompress the package
  3. Open setup.py
  4. Change the following:

From:

with open('README.txt') as file:
    long_description = file.read()

Change into:

with open('README.txt', encoding="utf8") as file:
    long_description = file.read()

This will open the file with the proper encoding.

Or you can remove these two line altogether and also remove long_description=long_description, at line 18 inside setup().

  1. In console, run python setup.py install
  2. And you're done!

Since there's no actual setup in the setup.py script, you can just directly clone the source folder from GitHub, the package should still work properly.

Taku
  • 31,927
  • 11
  • 74
  • 85
10

Simply add encoding="utf8" inside "open('path', here)".

with open('path to csv file',  encoding="utf8") as csv_file:
  • 1
    Thank you! I was loading JSON file with the following code: import json with open('movie.json', encoding='utf8') as JSONFile: data = json.load(JSONFile) print(len(data['movie'][0])) and it was throwing the above-mentioned error, by adding "encoding='utf8'" to the "with open()", it is solved. – sediq khan May 15 '22 at 16:49
5

I also had this problem with a pip install on a Windows version of python. The solution is to set the following environment variable:

PYTHONUTF8=1

You can unset it after the installation is complete if it could interfere with your normal development.

Andy Brown
  • 11,766
  • 2
  • 42
  • 61
  • This is correct if the goal is to obtain Unicode output in UTF-8 encoding, but not a proper solution for the cases where it is not. – tripleee Jan 31 '22 at 10:59
1

Go to https://pypi.python.org/pypi/StringGenerator/0.3.0 and download the latest version (or source in this case), extract the .gz file and then the .tar file.

Next go in StringGenerator-0.2.0 folder and open a terminal and run:

python setup.py build
python setup.py install 

Or from PowerShell run:

python ./setup.py build
python ./setup.py install 
Xantium
  • 11,201
  • 10
  • 62
  • 89