UnicodeDecodeError when trying to upgrade "pip" or "install pywinusb" - python

I'm trying to upgrade pip, and also install pywinusb, but I'm getting the error: "UnicodeDecodeError: 'ascii' codec can't decode byte 0xe9 in position 8: ordinal not in range(128)".
Pip upgrade:
PS C:\Python27> pip --version
pip 18.1 from c:\python27\lib\site-packages\pip (python 2.7)
PS C:\Python27> python -m pip install --upgrade pip
Collecting pip
Exception:
Traceback (most recent call last):
File "C:\Python27\lib\site-packages\pip\_internal\cli\base_command.py", line 143, in main
status = self.run(options, args)
File "C:\Python27\lib\site-packages\pip\_internal\commands\install.py", line 318, in run
resolver.resolve(requirement_set)
File "C:\Python27\lib\site-packages\pip\_internal\resolve.py", line 102, in resolve
self._resolve_one(requirement_set, req)
File "C:\Python27\lib\site-packages\pip\_internal\resolve.py", line 256, in _resolve_one
abstract_dist = self._get_abstract_dist_for(req_to_install)
File "C:\Python27\lib\site-packages\pip\_internal\resolve.py", line 209, in _get_abstract_dist_for
self.require_hashes
File "C:\Python27\lib\site-packages\pip\_internal\operations\prepare.py", line 283, in prepare_linked_requirement
progress_bar=self.progress_bar
File "C:\Python27\lib\site-packages\pip\_internal\download.py", line 836, in unpack_url
progress_bar=progress_bar
File "C:\Python27\lib\site-packages\pip\_internal\download.py", line 673, in unpack_http_url
progress_bar)
File "C:\Python27\lib\site-packages\pip\_internal\download.py", line 895, in _download_http_url
file_path = os.path.join(temp_dir, filename)
File "C:\Python27\lib\ntpath.py", line 85, in join
result_path = result_path + p_path
UnicodeDecodeError: 'ascii' codec can't decode byte 0xe9 in position 8: ordinal not in range(128)
You are using pip version 18.1, however version 19.1.1 is available.
You should consider upgrading via the 'python -m pip install --upgrade pip' command.
And in "pywinusb" install:
PS C:\Python27> pip install pywinusb
Collecting pywinusb
Exception:
Traceback (most recent call last):
File "c:\python27\lib\site-packages\pip\_internal\cli\base_command.py", line 143, in main
status = self.run(options, args)
File "c:\python27\lib\site-packages\pip\_internal\commands\install.py", line 318, in run
resolver.resolve(requirement_set)
File "c:\python27\lib\site-packages\pip\_internal\resolve.py", line 102, in resolve
self._resolve_one(requirement_set, req)
File "c:\python27\lib\site-packages\pip\_internal\resolve.py", line 256, in _resolve_one
abstract_dist = self._get_abstract_dist_for(req_to_install)
File "c:\python27\lib\site-packages\pip\_internal\resolve.py", line 209, in _get_abstract_dist_for
self.require_hashes
File "c:\python27\lib\site-packages\pip\_internal\operations\prepare.py", line 283, in prepare_linked_requirement
progress_bar=self.progress_bar
File "c:\python27\lib\site-packages\pip\_internal\download.py", line 836, in unpack_url
progress_bar=progress_bar
File "c:\python27\lib\site-packages\pip\_internal\download.py", line 673, in unpack_http_url
progress_bar)
File "c:\python27\lib\site-packages\pip\_internal\download.py", line 895, in _download_http_url
file_path = os.path.join(temp_dir, filename)
File "c:\python27\lib\ntpath.py", line 85, in join
result_path = result_path + p_path
UnicodeDecodeError: 'ascii' codec can't decode byte 0xe9 in position 8: ordinal not in range(128)
You are using pip version 18.1, however version 19.1.1 is available.
You should consider upgrading via the 'python -m pip install --upgrade pip' command.
Before this I have installed the package "pyusb" without any problem, without getting any error.
I've searched in google for this error, but not getting a very good explanation.
How to solve this error?

This occurs if your current working directory has name with non ASCII characters.Example ¢, Ë, Ñ, ß etc.
Remove those from the directory or file name and you are good to go.

About this particular error: "UnicodeDecodeError: 'ascii' codec can't decode byte 0xe9 in position 8: ordinal not in range(128)", when trying to upgrade pip or install any python packet, was related to the user folder name.
My user folder name was "C:/Users/Sérgio Neves", and the "é" in "Sérgio" was the problem, so I changed the user folder name to "C:/Users/SergioNeves", without any accent and space.
I followed this video to change the folder name:
https://www.youtube.com/watch?v=J_rTOA4gXJI

Related

Error when pip installing simpletransformers

I am trying to install simpletransformers via pip, but it gives me the following error:
"ERROR: Exception:
Traceback (most recent call last):
File "/sw/arch/Debian10/EB_production/2021/software/Python/3.9.5-GCCcore-10.3.0/lib/python3.9/site-packages/pip/_internal/cli/base_command.py", line 180, in _main
status = self.run(options, args)
File "/sw/arch/Debian10/EB_production/2021/software/Python/3.9.5-GCCcore-10.3.0/lib/python3.9/site-packages/pip/_internal/cli/req_command.py", line 204, in wrapper
return func(self, options, args)
File "/sw/arch/Debian10/EB_production/2021/software/Python/3.9.5-GCCcore-10.3.0/lib/python3.9/site-packages/pip/_internal/commands/install.py", line 393, in run
installed = install_given_reqs(
File "/sw/arch/Debian10/EB_production/2021/software/Python/3.9.5-GCCcore-10.3.0/lib/python3.9/site-packages/pip/_internal/req/__init__.py", line 77, in install_given_reqs
requirement.install(
File "/sw/arch/Debian10/EB_production/2021/software/Python/3.9.5-GCCcore-10.3.0/lib/python3.9/site-packages/pip/_internal/req/req_install.py", line 782, in install
install_wheel(
File "/sw/arch/Debian10/EB_production/2021/software/Python/3.9.5-GCCcore-10.3.0/lib/python3.9/site-packages/pip/_internal/operations/install/wheel.py", line 810, in install_wheel
_install_wheel(
File "/sw/arch/Debian10/EB_production/2021/software/Python/3.9.5-GCCcore-10.3.0/lib/python3.9/site-packages/pip/_internal/operations/install/wheel.py", line 653, in _install_wheel
file.save()
File "/sw/arch/Debian10/EB_production/2021/software/Python/3.9.5-GCCcore-10.3.0/lib/python3.9/site-packages/pip/_internal/operations/install/wheel.py", line 419, in save
with open(self.dest_path, "wb") as dest:
UnicodeEncodeError: 'latin-1' codec can't encode character '\U0001f4f9' in position 75: ordinal not in range(256)
"
I am working on jupyterhub and have tried creating a conda environment with Python version 3.7 as suggested in other cases, but the problem was not solved.
Any tips are welcome!
The problem comes from the encodage.
I think these topics could help you.
Streamlit install fails on GitLab CI with UnicodeEncodeError
'ascii' codec can't encode character : ordinal not in range (128)
In general google your error message you'll find o lot of related post and maybe your answer.

Raspberry Pi: Fatal Python error: initsite: Failed to import the site module

With no system changes, just a reboot, my raspberry pi (buster) python 3.7 installation does this when the python3 command is run:
Traceback (most recent call last):
File "/usr/lib/python3.7/site.py", line 603, in <module>
main()
File "/usr/lib/python3.7/site.py", line 590, in main
known_paths = addsitepackages(known_paths)
File "/usr/lib/python3.7/site.py", line 366, in addsitepackages
addsitedir(sitedir, known_paths)
File "/usr/lib/python3.7/site.py", line 213, in addsitedir
addpackage(sitedir, name, known_paths)
File "/usr/lib/python3.7/site.py", line 169, in addpackage
for n, line in enumerate(f):
File "/usr/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 0xe8 in position 342: invalid continuation byte
I'm unable to uninstall python using apt-get because that same error gets thrown partway through the uninstall process.
Any idea how to fix the error, or remove python so I can re-install it?
For future users: It looks like the SD card on the pi is dying. I managed to get python semi-working by copying a working python directory for another raspberry pi, but apt-get source files were corrupted as well. Managed to get my working files off, but a new SD card is required.

UnicodeDecodeError: 'ascii' codec can't decode byte 0xc7 in position 7: ordinal not in range(128)

Before asking this question, I have searched SO, find several related links:UnicodeDecodeError: 'ascii' codec can't decode byte 0xe2 in position 13: ordinal not in range(128), regarding reading in files
But they are no useful for my post, all of them are about program, but mine is for installation.
After I install the pip, I check the pip list:
C:\Users\中jin>pip list
DEPRECATION: The default format will switch to columns in the future. You can use --format=(legacy|columns) (or define a format=(legacy|columns) in your pip.conf under the [list] section) to disable this warning.
pip (9.0.1)
setuptools (28.8.0)
When I install django use pip, I get the bellow error:
C:\Users\中jin>pip install django
Collecting django
Exception:
Traceback (most recent call last):
File "C:\Python27\lib\site-packages\pip\basecommand.py", line 215, in main
status = self.run(options, args)
File "C:\Python27\lib\site-packages\pip\commands\install.py", line 324, in run
requirement_set.prepare_files(finder)
File "C:\Python27\lib\site-packages\pip\req\req_set.py", line 380, in prepare_files
ignore_dependencies=self.ignore_dependencies))
File "C:\Python27\lib\site-packages\pip\req\req_set.py", line 620, in _prepare_file
session=self.session, hashes=hashes)
File "C:\Python27\lib\site-packages\pip\download.py", line 821, in unpack_url
hashes=hashes
File "C:\Python27\lib\site-packages\pip\download.py", line 659, in unpack_http_url
hashes)
File "C:\Python27\lib\site-packages\pip\download.py", line 880, in _download_http_url
file_path = os.path.join(temp_dir, filename)
File "C:\Python27\lib\ntpath.py", line 85, in join
result_path = result_path + p_path
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc7 in position 7: ordinal not in range(128)
EDIT-1
I am in Windows10, and python 2.7.
I suspect that your temporary directory contains a non-ASCII 7 bit character in the actual path.
If you are on Windows make sure that the environment variable %TEMP% is set to a directory that only uses in it's full path the values in the ranges A-Za-z0-9 no accented characters, symbols, etc.
Note
On windows 10 and python 2.7.13 I have just tested and got:
> pip install django
Collecting django
Downloading Django-1.11.6-py2.py3-none-any.whl (6.9MB)
100% |################################| 7.0MB 152kB/s
Requirement already satisfied: pytz in c:\python27\lib\site-packages (from django)
Installing collected packages: django
Successfully installed django-1.11.6
> pip --version
pip 9.0.1 from c:\python27\lib\site-packages (python 2.7)
BUT
> mkdir Témp
> set TEMP=.\Témp
> pip install django
Collecting django
Exception:
Traceback (most recent call last):
File "c:\python27\lib\site-packages\pip\basecommand.py", line 215, in main
status = self.run(options, args)
File "c:\python27\lib\site-packages\pip\commands\install.py", line 335, in run
wb.build(autobuilding=True)
File "c:\python27\lib\site-packages\pip\wheel.py", line 749, in build
self.requirement_set.prepare_files(self.finder)
File "c:\python27\lib\site-packages\pip\req\req_set.py", line 380, in prepare_files
ignore_dependencies=self.ignore_dependencies))
File "c:\python27\lib\site-packages\pip\req\req_set.py", line 620, in _prepare_file
session=self.session, hashes=hashes)
File "c:\python27\lib\site-packages\pip\download.py", line 821, in unpack_url
hashes=hashes
File "c:\python27\lib\site-packages\pip\download.py", line 659, in unpack_http_url
hashes)
File "c:\python27\lib\site-packages\pip\download.py", line 880, in _download_http_url
file_path = os.path.join(temp_dir, filename)
File "c:\python27\lib\ntpath.py", line 85, in join
result_path = result_path + p_path
UnicodeDecodeError: 'ascii' codec can't decode byte 0xe9 in position 31: ordinal not in range(128)

when install OSMnx get erroe "UnicodeDecodeError: 'utf-8' codec can't decode byte 0xd5 in position 24: invalid continuation byte"

I have Python 3.6.1 32 bit,
OS windows 10 x64,
Tried install
pip install OSMnx
get error
Exception:
Traceback (most recent call last):
File "C:\Users\liuzi\AppData\Local\Programs\Python\Python36-32\lib\site-packages\pip\compat__init__.py", line 73, in console_to_str
return s.decode(sys.stdout.encoding)
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xd5 in position 24: invalid continuation byte
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\liuzi\AppData\Local\Programs\Python\Python36-32\lib\site-packages\pip\basecommand.py", line 215, in main
status = self.run(options, args)
File "C:\Users\liuzi\AppData\Local\Programs\Python\Python36-32\lib\site-packages\pip\commands\install.py", line 324, in run
requirement_set.prepare_files(finder)
File "C:\Users\liuzi\AppData\Local\Programs\Python\Python36-32\lib\site-packages\pip\req\req_set.py", line 380, in prepare_files
ignore_dependencies=self.ignore_dependencies))
File "C:\Users\liuzi\AppData\Local\Programs\Python\Python36-32\lib\site-packages\pip\req\req_set.py", line 634, in _prepare_file
abstract_dist.prep_for_dist()
File "C:\Users\liuzi\AppData\Local\Programs\Python\Python36-32\lib\site-packages\pip\req\req_set.py", line 129, in prep_for_dist
self.req_to_install.run_egg_info()
File "C:\Users\liuzi\AppData\Local\Programs\Python\Python36-32\lib\site-packages\pip\req\req_install.py", line 439, in run_egg_info
command_desc='python setup.py egg_info')
File "C:\Users\liuzi\AppData\Local\Programs\Python\Python36-32\lib\site-packages\pip\utils__init__.py", line 676, in call_subprocess
line = console_to_str(proc.stdout.readline())
File "C:\Users\liuzi\AppData\Local\Programs\Python\Python36-32\lib\site-packages\pip\compat__init__.py", line 75, in console_to_str
return s.decode('utf-8')
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xd5 in position 24: invalid continuation byte
The OSMnx installation instructions suggest using conda-forge to install. This is particularly important on Windows, as you want to avoid compiling all the C extensions required by the geospatial dependencies.
conda install -c conda-forge osmnx
Or if all else fails, do the install in a nice clean virtual environment:
conda create --yes -c conda-forge -n OSMNX python=3 osmnx
source activate OSMNX
That should solve any Windows-related install problems (and works for Mac and Linux too).

UnicodeDecodeError during pip installation on linux

On Red Hat 4.8 with python 2.7.5 during installation pip 9.0.1 with command
pip install --upgrade pip
I get this error:
Traceback (most recent call last):
File "/usr/lib/python2.7/site-packages/pip/basecommand.py", line 215, in main
status = self.run(options, args)
File "/usr/lib/python2.7/site-packages/pip/commands/install.py", line 272, in run
with self._build_session(options) as session:
File "/usr/lib/python2.7/site-packages/pip/basecommand.py", line 72, in _build_session
insecure_hosts=options.trusted_hosts,
File "/usr/lib/python2.7/site-packages/pip/download.py", line 329, in __init__
self.headers["User-Agent"] = user_agent()
File "/usr/lib/python2.7/site-packages/pip/download.py", line 93, in user_agent
from pip._vendor import distro
File "/usr/lib/python2.7/site-packages/pip/_vendor/distro.py", line 1050, in <module>
_distro = LinuxDistribution()
File "/usr/lib/python2.7/site-packages/pip/_vendor/distro.py", line 594, in __init__
if include_lsb else {}
File "/usr/lib/python2.7/site-packages/pip/_vendor/distro.py", line 922, in _get_lsb_release_info
stdout, stderr = stdout.decode('utf-8'), stderr.decode('utf-8')
File "/usr/lib64/python2.7/encodings/utf_8.py", line 16, in decode
return codecs.utf_8_decode(input, errors, True)
UnicodeDecodeError: 'utf8' codec can't decode byte 0xea in position 22: invalid continuation byte
Some commands of pip work as they should, for example, pip list shows the information, but
in the end it also shows traceback as above.
pip install pandas doesn't work at all.
pip --version command shows:
pip 9.0.1 from /usr/lib/python2.7/site-packages (python 2.7)
Also I cannot install the previous version with command:
pip install pip=8.1.1
Does this mean that installation failed or I need just
make some changes to make pip work properly?
(By the way all locales are cp1251)
I think, you need to change the default encoding of your systems,
this code allow you to change it to 'ISO-8859-1':
import sys
reload(sys)
sys.setdefaultencoding('ISO-8859-1')

Categories

Resources