0

use pipenv -h and other commands like --venv -install, UnicodeDecodeError: 'utf-8', pipenv commands are error.And i can't find answers in other places.

F:\proc_py\pipEnv>pipenv -h
Traceback (most recent call last):
  File "e:\python3.6\lib\runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "e:\python3.6\lib\runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "E:\python3.6\Scripts\pipenv.exe\__main__.py", line 5, in <module>
  File "e:\python3.6\lib\site-packages\pipenv\__init__.py", line 47, in <module>
    from .cli import cli
  File "e:\python3.6\lib\site-packages\pipenv\cli\__init__.py", line 3, in <modu
le>
    from .command import cli
  File "e:\python3.6\lib\site-packages\pipenv\cli\command.py", line 7, in <modul
e>
    import crayons
  File "e:\python3.6\lib\site-packages\pipenv\patched\crayons.py", line 49, in <
module>
    is_powershell = "powershell" in shellingham.detect_shell()[0]
  File "e:\python3.6\lib\site-packages\pipenv\vendor\shellingham\__init__.py", l
ine 22, in detect_shell
    shell = get_shell(pid, max_depth=max_depth)
  File "e:\python3.6\lib\site-packages\pipenv\vendor\shellingham\nt.py", line 10
0, in get_shell
    processes = dict(_iter_process())
  File "e:\python3.6\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 0xba in position 0: invalid
start byte

I do not know why, pipenv commands are error.And i can't find answers in other places.

WangTanxu
  • 71
  • 6
  • Possible duplicate of [UnicodeDecodeError: 'utf8' codec can't decode byte 0xa5 in position 0: invalid start byte](https://stackoverflow.com/questions/22216076/unicodedecodeerror-utf8-codec-cant-decode-byte-0xa5-in-position-0-invalid-s) – v0rtex Nov 24 '18 at 03:45
  • You mean I need to modify the source code of pipenv module? – WangTanxu Nov 24 '18 at 03:50
  • Are you actually installing anything with pipenv, your error message shows that you didn't. I get a similar error message when I do not tell pipenv to install something. – v0rtex Nov 24 '18 at 03:52

1 Answers1

0

I've met same problem and was lurking internet for a solution but having not much time and figured out some possible workaround for making it

I was tryin to install PIPEnvironment through Pycharm interpreter settings and problem occured:

Failed creating virtual environment 
[pipenv.exceptions.VirtualenvCreationException]:   File "C:\Users\ogmamedo\AppData\Roaming\Python\Python37\site-packages\pipenv\vendor\click\decorators.py", line 17, in new_func
[pipenv.exceptions.VirtualenvCreationException]:       return f(get_current_context(), *args, **kwargs)
[pipenv.exceptions.VirtualenvCreationException]:   File "C:\Users\ogmamedo\AppData\Roaming\Python\Python37\site-packages\pipenv\cli\command.py", line 208, in cli
[pipenv.exceptions.VirtualenvCreationException]:       clear=state.clear,
[pipenv.exceptions.VirtualenvCreationException]:   File "C:\Users\ogmamedo\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\ogmamedo\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\ogmamedo\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\ogmamedo\AppData\Roaming\Python\Python37\site-packages\virtualenv.py", line 939, in call_subprocess
    line = line.decode(encoding)
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xcf in position 280: invalid continuation byte

I went to a file

"C:\Users\ogmamedo\AppData\Roaming\Python\Python37\site-packages\virtualenv.py"

And changed code like this:

encoding = sys.getdefaultencoding()
fs_encoding = 'OEM' #sys.getfilesystemencoding()

This helped me to pass that stage (first 10 seconds) when bug was occuring.

Why it's 'OEM'? Because as we see in that file - there are a call to a system prompt (cmd shell), and my system's cmd shell has encoding 'OEM'.

I'll point that this is a workaround, not a proper solution, but due to a lack of time and interest figuring out which of sides this bug belongs to (pycharm or pipenv) I wont continue to a proper solution.

Orkhan M.
  • 143
  • 1
  • 11