SyntaxError:创建virtualenv时语法无效 [英] SyntaxError: invalid syntax when creating virtualenv

查看:141
本文介绍了SyntaxError:创建virtualenv时语法无效的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想为python 2.7创建一个virtualenv(我正在使用3.7)

I wanted to create a virtualenv for python 2.7 (I'm using 3.7)

我以admin身份运行cmd(在Windows 10上):

I run the cmd as admin (on windows 10) :

C:\WINDOWS\system32>virtualenv -p C:\Python27\python.exe py27

我得到了一个错误:

Running virtualenv with interpreter C:\Python27\python.exe
Traceback (most recent call last):
  File "c:\path\to\virtualenv.py", line 26, in <module>
    import logging
  File "C:\Python27\lib\logging\__init__.py", line 43, in <module>
    import threading
  File "C:\Python27\lib\threading.py", line 15, in <module>
    from collections import deque
  File "C:\Python27\lib\collections\__init__.py", line 55
    raise AttributeError(f'module {__name__!r} has no attribute {name!r}')
                                                                        ^
SyntaxError: invalid syntax

当我启动Python2.7并尝试导入日志记录模块时:它显示相同的错误,但是当我重新键入它时.效果很好:

When I Launch Python2.7 and try to import the logging module: It show the same error but When I retype it. It work just fine:

>>> import logging
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Python27\lib\logging\__init__.py", line 43, in <module>
    import threading
  File "C:\Python27\lib\threading.py", line 15, in <module>
    from collections import deque
  File "C:\Python27\lib\collections\__init__.py", line 55
    raise AttributeError(f'module {__name__!r} has no attribute {name!r}')
                                                                        ^
SyntaxError: invalid syntax
>>> import logging
>>> logging.warning('hello word')
WARNING:root:hello word
>>>

我不知道为什么会这么做.

I can't figure out why it does that.

我已经用python 3.6配置了一个虚拟环境

I have already configured a virtual env with python 3.6

任何帮助将不胜感激.

推荐答案

您有版本问题.这行

raise AttributeError(f'module {__name__!r} has no attribute {name!r}')

在Python 2.7下运行,但在Python 3.6(或3.7)下运行,并且会在早期版本中给您带来语法错误.在您的情况下,我认为Python 2.7的安装是无法修复的,因为很明显,标准库不应该被所有人都认为是一致的版本.

is being run under Python 2.7, but is Python 3.6 (or 3.7) and will give you a syntax error in earlier versions. In your case I would treat that Python 2.7 installation as irretrievably broken, because it is clear that the standard library isn't to be trusted to all be of a consistent version.

这篇关于SyntaxError:创建virtualenv时语法无效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆