Virtualenv: Problema com carro não ASCII no caminho

Criado em 29 jul. 2013  ·  20Comentários  ·  Fonte: pypa/virtualenv

Não sei se isso está relacionado ao # 186, mas com a minha nova instalação do python no meu Windows 8, tenho o seguinte erro ao usar o virtualenv no caminho C: \ Users \ oncleben \ Dropbox \ Developement \ fraisDeSanté

C:\Users\oncleben\Dropbox\Developement\fraisDeSanté> virtualenv ENV
New python executable in ENV\Scripts\python.exe
Traceback (most recent call last):
  File "<string>", line 1, in <module>
UnicodeDecodeError: 'ascii' codec can't decode byte 0xe9 in position 50: ordinal not in range(128)
ERROR: The executable ENV\Scripts\python.exe is not functioning
ERROR: It thinks sys.prefix is u'c:\\users\\oncleben\\dropbox\\developement\\fraisdesant\xe9' (should be u'c:\\users\\on
cleben\\dropbox\\developement\\fraisdesant\xe9\\env')
ERROR: virtualenv is not compatible with this system or executable
Note: some Windows users have reported this error when they installed Python for "Only this user" or have multiple versi
ons of Python installed. Copying the appropriate PythonXX.dll to the virtualenv Scripts/ directory may fix this problem.

python v2.7.5
lista de pip
nariz (1.3.0)
pip (1,4)
Scaffold (0.1.3)
ferramentas de configuração (0.9.7)
virtualenv (1.10)

Editar:

bug help-wanted

Comentários muito úteis

Isso agora foi corrigido, contanto que o codec do sistema de arquivos possa lidar com isso, nós vamos lidar com isso também 👍 se não, vamos gerar a mensagem de erro apropriada 👍 No Windows pré python3.6 isso implica no codec mcbs 👍 em todos os casos posteriores nós está falando sobre utf-8.

Todos 20 comentários

Olá,
Tenho exatamente o mesmo problema aqui com:
python v2.7.5
Win7 64 bits
Pode ser reproduzido à vontade

Parece # 453

Esse problema ocorre também no Mac OS X 10.8.4 com Python v2.7.2:

New python executable in venv/bin/python
Traceback (most recent call last):
  File "<string>", line 1, in <module>
UnicodeDecodeError: 'ascii' codec can't decode byte 0xe5 in position 16: ordinal not in range(128)
ERROR: The executable venv/bin/python is not functioning
ERROR: It thinks sys.prefix is u'/Users/RSChiang/\u539f\u59cb\u78bc/repo' (should be u'/Users/RSChiang/\u539f\u59cb\u78bc/repo/venv')
ERROR: virtualenv is not compatible with this system or executable

A solicitação de pull nº 187 mencionou algo sobre a codificação FS é diferente da codificação padrão. Provavelmente a configuração do sistema resolveria isso?

A correção de Atykhonov funciona para mim.

Colisão. Algum progresso? @atykhonov Que tal enviar seu patch como uma solicitação de pull?

Idem. O problema também ocorre no Linux, aqui com caracteres chineses:

$ virtualenv /tmp/中文
New python executable in /tmp/中文/bin/python
Traceback (most recent call last):
  File "<string>", line 1, in <module>
UnicodeDecodeError: 'ascii' codec can't decode byte 0xe4 in position 5: ordinal not in range(128)
ERROR: The executable /tmp/中文/bin/python is not functioning
ERROR: It thinks sys.prefix is u'/home/vinay/projects/scratch' (should be u'/tmp/\u4e2d\u6587')
ERROR: virtualenv is not compatible with this system or executable
vinay<strong i="6">@ubuntu</strong>:~/projects/scratch$ virtualenv --version
13.1.2
vinay<strong i="7">@ubuntu</strong>:~/projects/scratch$ /tmp/中文/bin/python
Python 2.7.10 (default, Oct 14 2015, 16:09:02) 
[GCC 5.2.1 20151010] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> 

Eu tenho um patch WIP para este problema, embora nada possa ser feito antes que o bug em https://bitbucket.org/pypa/distlib/pull-requests/27 seja corrigido.

@ yan12125 - Não tenho certeza se seu PR está correto, veja meus comentários sobre ele. Além disso, não está claro se o despejo do console acima está relacionado ao problema distlib - parece ser um bug diferente em virtualenv que é invocado ao testar se o venv foi criado corretamente.

Existem muitas solicitações pull tentando resolver isso:

  • # 900 (# 875): aberto por mim, todos os testes foram aprovados
  • # 902 (# 894): aberto por @aodag
  • # 907 (# 453): aberto por @magres
  • # 908 (# 492): aberto por @atykhonov
  • # 912 (# 630): aberto por @dholth

Eu acho que um ambiente de teste do Windows como o Appveyor também é necessário. pypa / pip já o está

FI, recebi o mesmo erro no Debian GNU / Linux 9.2, Python 2.7.14.

% pwd
/home/tiger-222/Téléchargements

Python 2:

% python2 -m pip install --user --upgrade virtualenv
Collecting virtualenv
  Using cached virtualenv-15.1.0-py2.py3-none-any.whl
Installing collected packages: virtualenv
Successfully installed virtualenv-15.1.0

% python2 -m virtualenv test-python2   
New python executable in /home/tiger-222/Téléchargements/test-python2/bin/python2
Also creating executable in /home/tiger-222/Téléchargements/test-python2/bin/python
Traceback (most recent call last):
  File "<string>", line 1, in <module>
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 17: ordinal not in range(128)
ERROR: The executable /home/tiger-222/Téléchargements/test-python2/bin/python2 is not functioning
ERROR: It thinks sys.prefix is u'/home/tiger-222/T\xe9l\xe9chargements' (should be u'/home/tiger-222/T\xe9l\xe9chargements/test-python2')
ERROR: virtualenv is not compatible with this system or executable

Python 3:

% python3 -m pip install --user --upgrade virtualenv
Collecting virtualenv
  Using cached virtualenv-15.1.0-py2.py3-none-any.whl
Installing collected packages: virtualenv
Successfully installed virtualenv-15.1.0

% python3 -m virtualenv test-python3
Using base prefix '/usr'
New python executable in /home/tiger-222/Téléchargements/test-python3/bin/python3
Also creating executable in /home/tiger-222/Téléchargements/test-python3/bin/python
Installing setuptools, pip, wheel...done.

Seja como for, posso reproduzir esse problema no Windows 7, Python 3.6.4, virtualenv 15.1.0, ao trabalhar com uma conta de usuário com nome de usuário começando com $ .

PS C:\Users\$scuthbertson\Desktop\bugtest> python -m virtualenv .
Using base prefix 'C:\\Program Files\\Python36'
New python executable in C:\Users\$scuthbertson\Desktop\bugtest\Scripts\python.exe
Installing setuptools, pip, wheel...
  Complete output from command C:\Users\$scuthberts...t\Scripts\python.exe - setuptools pip wheel:
  Collecting setuptools
  Using cached setuptools-39.0.1-py2.py3-none-any.whl
Collecting pip
  Using cached pip-9.0.3-py2.py3-none-any.whl
Collecting wheel
  Using cached wheel-0.30.0-py2.py3-none-any.whl
Installing collected packages: setuptools, pip, wheel
Exception:
Traceback (most recent call last):
  File "C:\Program Files\Python36\Lib\distutils\util.py", line 202, in subst_vars
    return re.sub(r'\$([a-zA-Z_][a-zA-Z_0-9]*)', _subst, s)
  File "C:\Users\$scuthbertson\Desktop\bugtest\lib\re.py", line 191, in sub
    return _compile(pattern, flags).sub(repl, string, count)
  File "C:\Program Files\Python36\Lib\distutils\util.py", line 199, in _subst
    return os.environ[var_name]
  File "C:\Users\$scuthbertson\Desktop\bugtest\lib\os.py", line 669, in __getitem__
    raise KeyError(key) from None
KeyError: 'scuthbertson'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Program Files\Python36\lib\site-packages\virtualenv_support\pip-9.0.1-py2.py3-none-any.whl\pip\basecommand.py
", line 215, in main
    status = self.run(options, args)
  File "C:\Program Files\Python36\lib\site-packages\virtualenv_support\pip-9.0.1-py2.py3-none-any.whl\pip\commands\insta
ll.py", line 342, in run
    prefix=options.prefix_path,
  File "C:\Program Files\Python36\lib\site-packages\virtualenv_support\pip-9.0.1-py2.py3-none-any.whl\pip\req\req_set.py
", line 784, in install
    **kwargs
  File "C:\Program Files\Python36\lib\site-packages\virtualenv_support\pip-9.0.1-py2.py3-none-any.whl\pip\req\req_instal
l.py", line 851, in install
    self.move_wheel_files(self.source_dir, root=root, prefix=prefix)
  File "C:\Program Files\Python36\lib\site-packages\virtualenv_support\pip-9.0.1-py2.py3-none-any.whl\pip\req\req_instal
l.py", line 1064, in move_wheel_files
    isolated=self.isolated,
  File "C:\Program Files\Python36\lib\site-packages\virtualenv_support\pip-9.0.1-py2.py3-none-any.whl\pip\wheel.py", lin
e 247, in move_wheel_files
    prefix=prefix,
  File "C:\Program Files\Python36\lib\site-packages\virtualenv_support\pip-9.0.1-py2.py3-none-any.whl\pip\locations.py",
 line 153, in distutils_scheme
    i.finalize_options()
  File "C:\Program Files\Python36\Lib\distutils\command\install.py", line 307, in finalize_options
    self.expand_basedirs()
  File "C:\Program Files\Python36\Lib\distutils\command\install.py", line 475, in expand_basedirs
    self._expand_attrs(['install_base', 'install_platbase', 'root'])
  File "C:\Program Files\Python36\Lib\distutils\command\install.py", line 469, in _expand_attrs
    val = subst_vars(val, self.config_vars)
  File "C:\Program Files\Python36\Lib\distutils\util.py", line 204, in subst_vars
    raise ValueError("invalid variable '$%s'" % var)
ValueError: invalid variable '$'scuthbertson''
----------------------------------------
...Installing setuptools, pip, wheel...done.
Traceback (most recent call last):
  File "C:\Program Files\Python36\lib\runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "C:\Program Files\Python36\lib\runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "C:\Program Files\Python36\lib\site-packages\virtualenv.py", line 2328, in <module>
    main()
  File "C:\Program Files\Python36\lib\site-packages\virtualenv.py", line 713, in main
    symlink=options.symlink)
  File "C:\Program Files\Python36\lib\site-packages\virtualenv.py", line 945, in create_environment
    download=download,
  File "C:\Program Files\Python36\lib\site-packages\virtualenv.py", line 901, in install_wheel
    call_subprocess(cmd, show_stdout=False, extra_env=env, stdin=SCRIPT)
  File "C:\Program Files\Python36\lib\site-packages\virtualenv.py", line 797, in call_subprocess
    % (cmd_desc, proc.returncode))
OSError: Command C:\Users\$scuthberts...t\Scripts\python.exe - setuptools pip wheel failed with error code 2
PS C:\Users\$scuthbertson\Desktop\bugtest>

@philosophicles : parece um problema diferente dos caracteres chineses ou espaços no caminho. Você poderia abrir uma nova edição?

Aliás, o venv também é afetado e seria ótimo se um problema fosse aberto em https://bugs.python.org/ para o venv também.

@philosophicles Isso pode não ser um bug - parece estar acontecendo porque distutils está vendo $cuthbertson como um espaço reservado e tentando substituí-lo por uma variável, que não foi encontrada. Veja esta parte da documentação .

Vou levantar questões separadas (no virtualenv e no venv) para o meu problema atualmente.

@vsajip - minha opinião é que definitivamente é um bug. Eu olhei a documentação que você faz referência, mas é uma referência de API para alguém que desenvolve usando distutils. Estou apenas tentando executar um comando simples como > python -m virtualenv . no Windows e encontrando um erro fatal que impede o virtualenv de fazer o que deve fazer. Eu não deveria ter que me preocupar com a implementação interna do virtualenv, ou como o distutils funciona, ou mesmo qual é o caminho completo do meu diretório. É legítimo que caminhos de diretório do Windows contenham $ portanto, idealmente, eles devem ser suportados.

Este problema foi marcado automaticamente como obsoleto porque não teve atividades recentes. Ele será fechado se nenhuma outra atividade ocorrer. Basta adicionar um comentário se quiser mantê-lo aberto. Obrigado por suas contribuições.

@stale fechou isso .... mas ping. Isso ainda é um bug ... mas estou bem se isso não for corrigido no 2.7.x ... Eu só preciso saber

Isso agora foi corrigido, contanto que o codec do sistema de arquivos possa lidar com isso, nós vamos lidar com isso também 👍 se não, vamos gerar a mensagem de erro apropriada 👍 No Windows pré python3.6 isso implica no codec mcbs 👍 em todos os casos posteriores nós está falando sobre utf-8.

@gaborbernat Obrigado ++

Olá @gaborbernat , este problema foi corrigido no último branch master?
Usei o branch master e obtive erros semelhantes ao problema # 1375 .
caso contrário, posso criar um PR para corrigir esse problema.

Não no branch master, mas no branch rewrite que em breve substituirá o master.

OK, obrigado pela sua resposta.

Esta página foi útil?
0 / 5 - 0 avaliações

Questões relacionadas

erbatyr picture erbatyr  ·  5Comentários

asottile picture asottile  ·  5Comentários

asottile picture asottile  ·  6Comentários

Tset-Noitamotua picture Tset-Noitamotua  ·  4Comentários

jwarren116 picture jwarren116  ·  5Comentários