0

I have instaled virtualenv on windows 10 and Python 2.7.1 but when I run:

virtualenv my-virtual

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

I think Python 2.7 does not understand my windows path because accent mark...

enter image description here

How can I resolve this error?

Carmoreno
  • 1,271
  • 17
  • 29
  • Have you tried adding `# encoding: utf-8` at the start of your script? – Krishh Apr 20 '16 at 14:50
  • I have wirtten in virtualenv file `reload(sys) sys.setdefaultencoding('Cp1252')` and working for me. See http://stackoverflow.com/questions/21129020/how-to-fix-unicodedecodeerror-ascii-codec-cant-decode-byte – Carmoreno Apr 20 '16 at 14:59

1 Answers1

2

The easy solution is: change your name ;) Of course I am joking, you shouldn't have to change your name because some tool is broken!

I can reproduce your problems with 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

With using virtualenvwrapper, I don't have any problem:

/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$ 

It seems they were more careful with handling non-ascii characters. So try using the mkvirtualenv helper function from virtualenvwrapper.sh

wim
  • 338,267
  • 99
  • 616
  • 750
  • "The easy solution is: change your name" -- You said that as a joke, but it actually is the _best_ solution: Change your account name. An account name that contains spaces, non-ascii characters or even upper case characters can cause needless problems. I speak from experience, as I have a given name containing an “é”. – Kijewski Apr 20 '16 at 15:17
  • 2
    I have mixed feelings on the issue. For sure, practicality beats purity. But on the other hand, if everybody takes this "lazy" approach then broken tools will never be fixed! sadface.jpg – wim Apr 20 '16 at 15:22