UnicodeDecodeError:'ascii'编解码器无法解码位置20中的字节0xe9:序数不在范围内(128)

时间:2016-04-20 14:32:22

标签: python python-2.7 virtualenv

我已经在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路径,因为重音标记......

enter image description here

如何解决此错误?

1 个答案:

答案 0 :(得分:2)

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

我可以使用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辅助函数