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

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

我已经在 windows 10 和 Python 2.7.1 上安装了 virtualenv 但是当我 运行:

virtualenv my-virtual

我有这个错误: UnicodeDecodeError: 'ascii' codec can't decode byte 0xe9 in position 20: ordinal not in range(128)

我认为 Python 2.7 不理解我的 windows 路径,因为重音符号...

我该如何解决这个错误?

简单的解决方案是:更改您的名字 ;) 当然我是在开玩笑,您不应该因为某些工具坏了而不得不更改您的名字!

我可以用 virtualenv 重现您的问题:

/tmp$ mkdir "Carlos Andrés Moreno"
/tmp$ cd Carlos\ Andrés\ Moreno/
/tmp/Carlos Andrés Moreno$ virtualenv kernel
New python executable in kernel/bin/python2
Also creating executable in kernel/bin/python
Traceback (most recent call last):
  File "<string>", line 1, in <module>
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 16: ordinal not in range(128)
ERROR: The executable kernel/bin/python2 is not functioning
ERROR: It thinks sys.prefix is u'/tmp/Carlos Andr\xe9s Moreno' (should be u'/tmp/Carlos Andr\xe9s Moreno/kernel')
ERROR: virtualenv is not compatible with this system or executable

使用virtualenvwrapper,我没有任何问题:

/tmp/Carlos Andrés Moreno$ mkvirtualenv kernel
New python executable in kernel/bin/python2
Also creating executable in kernel/bin/python
Installing setuptools, pip, wheel...done.
virtualenvwrapper.user_scripts creating /home/wglenn/.virtualenvs/kernel/bin/predeactivate
virtualenvwrapper.user_scripts creating /home/wglenn/.virtualenvs/kernel/bin/postdeactivate
virtualenvwrapper.user_scripts creating /home/wglenn/.virtualenvs/kernel/bin/preactivate
virtualenvwrapper.user_scripts creating /home/wglenn/.virtualenvs/kernel/bin/postactivate
virtualenvwrapper.user_scripts creating /home/wglenn/.virtualenvs/kernel/bin/get_env_details
(kernel)/tmp/Carlos Andrés Moreno$ 

他们似乎在处理非 ascii 字符时更加小心。所以尝试使用 virtualenvwrapper.sh

中的 mkvirtualenv 辅助函数