Python 2.7 : LookupError: unknown encoding: cp65001 [duplicate]
Asked Answered
M

2

63

I have installed python 2(64 bit), on windows 8.1 (64 bit) and wanted to know pip version and for that I fired pip --version but it is giving error.

    C:\Users\ADMIN>pip --version
Traceback (most recent call last):
  File "c:\dev\python27\lib\runpy.py", line 162, in _run_module_as_main
    "__main__", fname, loader, pkg_name)
  File "c:\dev\python27\lib\runpy.py", line 72, in _run_code
    exec code in run_globals
  File "C:\dev\Python27\Scripts\pip.exe\__main__.py", line 5, in <module>
  File "c:\dev\python27\lib\site-packages\pip\__init__.py", line 15, in <module>
    from pip.vcs import git, mercurial, subversion, bazaar  # noqa
  File "c:\dev\python27\lib\site-packages\pip\vcs\mercurial.py", line 10, in <module>
    from pip.download import path_to_url
  File "c:\dev\python27\lib\site-packages\pip\download.py", line 35, in <module>
    from pip.utils.ui import DownloadProgressBar, DownloadProgressSpinner
  File "c:\dev\python27\lib\site-packages\pip\utils\ui.py", line 51, in <module>
    _BaseBar = _select_progress_class(IncrementalBar, Bar)
  File "c:\dev\python27\lib\site-packages\pip\utils\ui.py", line 44, in _select_progress_class
    six.text_type().join(characters).encode(encoding)
LookupError: unknown encoding: cp65001

Note : The same command works fine for python 3. I have uninstalled both and installed again but still no success.

Merrygoround answered 3/2, 2016 at 11:50 Comment(4)
cp65001 is Windows double-speak for UTF-8. You can probably reconfigure your terminal temporarily to use an encoding which is known to your Python version (good old cp1252 perhaps?) and see if that helps.Christan
This happened to me spontaneously in Powershell after enabling Japanese input and output on Windows 10. Disabling it and restarting Powershell evidently resolved the issue.Loella
chcp 850 solved it for me - something else in Windows randomly shifted the console to 65001, (an term emulator) so setting to 850 as a workaround to restarting the console.Ringlet
You shouldn't get this error on Python 3.8 where cp65001 has become an alias of utf-8. docs.python.org/3/library/codecs.html#standard-encodings (scroll to the bottom)Disforest
S
133

The error means that Unicode characters that your script are trying to print can't be represented using the current console character encoding.

Also try to run set PYTHONIOENCODING=UTF-8 after execute pip --version without reloading terminal if everything going well add PYTHONIOENCODING as env variable with value UTF-8. See How to set the path and environment variables in Windows article to get info how to add Windows variable.

NOTE: For PowerShell use $env:PYTHONIOENCODING = "UTF-8"

Also you can try to install win-unicode-console with pip:

pip install win-unicode-console

Then reload your terminal and try to execute pip --version

However you can follow suggestions from Windows cmd encoding change causes Python crash answer because you have same problem.

Six answered 3/2, 2016 at 13:4 Comment(13)
It also fails with the same error. I am not able to use pip at all :(Merrygoround
try to run set PYTHONIOENCODING=UTF-8 after execute pip --version withour reloading terminalSix
Thanks :) it worked... So i need to set it each time? Can you please explain what was happening and how to stop it? Please write it as a answer so that I can accept it as answer.Merrygoround
"without reloading terminal" is what I was missing.Merrygoround
@HimanshuBhandari , sure , i've extended answer ...Six
@Himanshu Good Luck !Six
Can't install anything since trying to install something with pip gives me UnicodeDecodeError in ntpath.py:68 error =( Strange,Jonis
For me the workaround mentioned here fixed the issue: github.com/pypa/pip/issues/2501Jonis
$env:PYTHONIOENCODING = "UTF-8" for powershell usersAnnulus
@Annulus makes sense, thanks !Six
I recently ran into the error in the title after installing the Google Cloud Platform SDK on Windows when trying to run gcloud app deploy. This command fixed it for me. "set PYTHONIOENCODING=UTF-8".Calcariferous
The set PYTHONIOENCODING=UTF-8 command did it for me, thanks!Keeler
Answer is set PYTHONIOENCODING=UTF-8 can be set in your .bashrc for future use.Colemancolemanite
B
1

First of all you need to upgrade your pip. You can do this in Windows by:

python -m pip install -U pip

Then go manually to your script folder, enter command line from that folder (you can do this by clicking shift + right mouse button -> Open console window), and then you should use one of this commands.

pip -V
pip --version

This will result in

pip 7.1.2 from c:\python27\lib\site-packages (python 2.7)

If you still have trouble, you can try to remove your current Python PATH, and add a new one to Python 2.7.

Behoove answered 3/2, 2016 at 12:13 Comment(4)
I am unable to print even the version of pip, so other commands are also giving the same error.Merrygoround
Try to uninstall temporary python 3, reinstall your python 2.7 and try Windows power shell maybe ? I can do this command on my Windows 10 without any problem using only CMD. can u enter python interpreter?Behoove
windows power shell? I don't have any idea. Yes I have already uninstalled python 3, and yes I can enter into python interpreter.Merrygoround
Okay. first of all we have to chec what encodning are you using.Behoove

© 2022 - 2024 — McMap. All rights reserved.