-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
UnicodeDecodeError when running pipenv install on Windows #3382
Comments
Thanks for your effort! It may relate with https://github.com/sarugaku/shellingham. @uranusjr do you mind to have a look for this? |
Similar to #2820, but on Windows. Thanks for the debugging effort! I think I know what is going on here. Will fix in the next release. |
By the way, @pansila can you provide the value of |
@uranusjr It's 'utf-8'. And furthermore, sys.getdefaultencoding() also gives 'utf-8'. The problem is that there are some processes with Chinese names, so when I tried to decode them with 'GBK', pipenv succeeded to run. I'm using a Windows 10 with English as the default language, but I installed some Chinese softwares. It might be difficult to guess all encodings that processes use in this case. |
Thanks! I believe my solution is correct, then. |
It shouldn’t actually be necessary — but going to and from mbcs will be lossy, since The correct behavior is to aim for If you want to make this easier I just finished implementing this in full in Source: sarugaku/vistir#54 |
We can afford to be lossy here since all we want to know is whether an executable is a shell. If the name fails to be decoded, it is definitely not a shell. I’ve released 1.2.8 for Shellingham. This can be closed after the vendor upgrades for the next release. |
thats ok with me then, although possibly not actually necessary? do we have a way to test it? |
@pansila if you add an import: from ctypes import create_unicode_buffer and then you make the following changes: executable = create_unicode_buffer(pe.szExeFile)
info = {'executable': executable.value} I'd be a lot more comfortable letting windows handle this itself than randomly using mbcs for it, since python doesn't actually encode and decode mbcs correctly (which is why they switched to UTF8) Does this also work? I'd love a test case (i.e. the code points) for the characters that are breaking -- you can get those with |
@techalchemy It fails with another exception. pipenv --support
|
thanks a lot, I think you should pull a request to fix this error. |
This will be caught in vendored dependency updates as Tzu-ping mentioned |
Still no success, under Windows7 russian, without russian letters in paths...
Full output> pipenv install
Creating a virtualenv for this project…
Pipfile: C:\Users\swasher\PycharmProjects\test\Pipfile
Using c:\users\swasher\appdata\local\programs\python\python37\python.exe (3.7.3) to create virtualenv…
[=== ] Creating virtual environment...Already using interpreter c:\users\swasher\appdata\local\programs\python\python37\python.exe
Using base prefix 'c:\\users\\swasher\\appdata\\local\\programs\\python\\python37'
New python executable in C:\Users\swasher\.virtualenvs\test-tQmITBdN\Scripts\python.exe
Installing setuptools, pip, wheel...
done.
Failed creating virtual environment
[pipenv.exceptions.VirtualenvCreationException]: File "C:\Users\swasher\AppData\Roaming\Python\Python37\site-packages\pipenv\cli\command.py", line 254, in install
[pipenv.exceptions.VirtualenvCreationException]: editable_packages=state.installstate.editables,
[pipenv.exceptions.VirtualenvCreationException]: File "C:\Users\swasher\AppData\Roaming\Python\Python37\site-packages\pipenv\core.py", line 1741, in do_install
[pipenv.exceptions.VirtualenvCreationException]: pypi_mirror=pypi_mirror,
[pipenv.exceptions.VirtualenvCreationException]: File "C:\Users\swasher\AppData\Roaming\Python\Python37\site-packages\pipenv\core.py", line 574, in ensure_project
[pipenv.exceptions.VirtualenvCreationException]: pypi_mirror=pypi_mirror,
[pipenv.exceptions.VirtualenvCreationException]: File "C:\Users\swasher\AppData\Roaming\Python\Python37\site-packages\pipenv\core.py", line 506, in ensure_virtualenv
[pipenv.exceptions.VirtualenvCreationException]: python=python, site_packages=site_packages, pypi_mirror=pypi_mirror
[pipenv.exceptions.VirtualenvCreationException]: File "C:\Users\swasher\AppData\Roaming\Python\Python37\site-packages\pipenv\core.py", line 935, in do_create_virtualenv
[pipenv.exceptions.VirtualenvCreationException]: extra=[crayons.blue("{0}".format(c.err)),]
[pipenv.exceptions.VirtualenvCreationException]: Traceback (most recent call last):
File "C:\Users\swasher\AppData\Roaming\Python\Python37\site-packages\virtualenv.py", line 903, in call_subprocess
line = line.decode(encoding)
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xd1 in position 280: invalid continuation byte
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "c:\users\swasher\appdata\local\programs\python\python37\lib\runpy.py", line 193, in _run_module_as_main
"__main__", mod_spec)
File "c:\users\swasher\appdata\local\programs\python\python37\lib\runpy.py", line 85, in _run_code
exec(code, run_globals)
File "C:\Users\swasher\AppData\Roaming\Python\Python37\site-packages\virtualenv.py", line 2610, in <module>
main()
File "C:\Users\swasher\AppData\Roaming\Python\Python37\site-packages\virtualenv.py", line 834, in main
symlink=options.symlink,
File "C:\Users\swasher\AppData\Roaming\Python\Python37\site-packages\virtualenv.py", line 1129, in create_environment
install_wheel(to_install, py_executable, search_dirs, download=download)
File "C:\Users\swasher\AppData\Roaming\Python\Python37\site-packages\virtualenv.py", line 976, in install_wheel
_install_wheel_with_search_dir(download, project_names, py_executable, search_dirs)
File "C:\Users\swasher\AppData\Roaming\Python\Python37\site-packages\virtualenv.py", line 1066, in _install_wheel_with_search_dir
call_subprocess(cmd, show_stdout=False, extra_env=env, stdin=script)
File "C:\Users\swasher\AppData\Roaming\Python\Python37\site-packages\virtualenv.py", line 905, in call_subprocess
line = line.decode(fs_encoding)
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xd1 in position 280: invalid continuation byte
Failed to create virtual environment.
$ pipenv --supportPipenv version: Pipenv location: Python location: Python installations found:
PEP 508 Information:
System environment variables:
Pipenv–specific environment variables: Debug–specific environment variables:
Contents of UPDATE |
Same error when running |
Fixed this by going to - "c:\Python38-32\lib\site-packages\virtualenv.py" and changing a fs_encoding variable to = 'GBK' |
When can we include this fix? There are no releases for almost a year since the last pipenv release. sarugaku/shellingham@3813720 |
I would also need a real fix for this, not a hack... |
thanks, the problem has been solved. |
Every time I got this error reboot system solves, but the error keep repeat after a while. |
error output: |
Fix this by replacing shellingham/nt.py [L85-L89] |
For Windows10 users, possible solution is change system-wide default encoding to utf-8 Hint: this may break some old application which is incompatible with utf-8. |
This problem has been solved after I upgrade |
@JalinWang Thanks for the reminder! |
@JalinWang Which accurate version is |
Thant you!!! |
Is there any solution for this? Still getting the error after setting the environment variable: |
Nothing of the mentioned worked for me... I am using a work-around:
I put this inside a script so it's convenient to execute. Maybe this helps somebody else... |
For me this problem was caused by the fake Windows Python App Execution Alias (the one which tries to redirect to the Windows store). It dumps a non UTF-8 error message which causes the problem. |
Issue description
I'm installing a pipenv virtual env from a virtualenv project that has a requirement.txt, but it doesn't matter, I can't run any pipenv commands, even pipenv --support.
Expected result
Installation should be successful.
Actual result
pipenv install or pipenv --support
Traceback (most recent call last):
File "c:\users\panzi\appdata\local\programs\python\python36\lib\runpy.py", line 193, in run_module_as_main
"main", mod_spec)
File "c:\users\panzi\appdata\local\programs\python\python36\lib\runpy.py", line 85, in run_code
exec(code, run_globals)
File "C:\Users\panzi\AppData\Local\Programs\Python\Python36\Scripts\pipenv.exe_main.py", line 5, in
File "c:\users\panzi\appdata\local\programs\python\python36\lib\site-packages\pipenv_init.py", line 47, in
from .cli import cli
File "c:\users\panzi\appdata\local\programs\python\python36\lib\site-packages\pipenv\cli_init_.py", line 3, in
from .command import cli
File "c:\users\panzi\appdata\local\programs\python\python36\lib\site-packages\pipenv\cli\command.py", line 7, in
import crayons
File "c:\users\panzi\appdata\local\programs\python\python36\lib\site-packages\pipenv\patched\crayons.py", line 49, in
is_powershell = "powershell" in shellingham.detect_shell()[0]
File "c:\users\panzi\appdata\local\programs\python\python36\lib\site-packages\pipenv\vendor\shellingham_init_.py", line 22, in detect_shell
shell = get_shell(pid, max_depth=max_depth)
File "c:\users\panzi\appdata\local\programs\python\python36\lib\site-packages\pipenv\vendor\shellingham\nt.py", line 100, in get_shell
processes = dict(_iter_process())
File "c:\users\panzi\appdata\local\programs\python\python36\lib\site-packages\pipenv\vendor\shellingham\nt.py", line 78, in _iter_process
info = {'executable': str(pe.szExeFile.decode('utf-8'))}
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xc3 in position 2: invalid continuation byte
Steps to replicate
pipenv install
After some debugging, I found it's a decoding bug in
Python36\Lib\site-packages\pipenv\vendor\shellingham\nt.py
I added a try catch to capture the exception and try to decode it in my locale encoding, then it succeeded. Is there a more elegant way to fix it?
The text was updated successfully, but these errors were encountered: