Python SyntaxError:创建virtualenv时语法无效
我想为Python2.7创建一个virtualenv(我正在使用3.7) 我以管理员身份运行cmd(在windows 10上): 我得到了一个错误:Python SyntaxError:创建virtualenv时语法无效,python,logging,module,virtualenv,Python,Logging,Module,Virtualenv,我想为Python2.7创建一个virtualenv(我正在使用3.7) 我以管理员身份运行cmd(在windows 10上): 我得到了一个错误: 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
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
使用解释器C:\Python27\python.exe运行virtualenv
回溯(最近一次呼叫最后一次):
文件“c:\path\to\virtualenv.py”,第26行,在
导入日志记录
文件“C:\Python27\lib\logging\\uuuu init\uuuuu.py”,第43行,在
导入线程
文件“C:\Python27\lib\threading.py”,第15行,在
从集合导入deque
文件“C:\Python27\lib\collections\\uuuu init\uuuu.py”,第55行
raise AttributeError(f'module{{U_________!r}没有属性{name!r})
^
SyntaxError:无效语法
当我启动Python2.7并尝试导入日志模块时:它显示相同的错误,但当我重新键入它时。它工作得很好:
>>> 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
>>>
导入日志记录
回溯(最近一次呼叫最后一次):
文件“”,第1行,在
文件“C:\Python27\lib\logging\\uuuu init\uuuuu.py”,第43行,在
导入线程
文件“C:\Python27\lib\threading.py”,第15行,在
从集合导入deque
文件“C:\Python27\lib\collections\\uuuu init\uuuu.py”,第55行
raise AttributeError(f'module{{U_________!r}没有属性{name!r})
^
SyntaxError:无效语法
>>>导入日志记录
>>>logging.warning('hello word')
警告:root:hello-word
>>>
我不明白为什么会这样
我已经用Python3.6配置了一个虚拟环境
任何帮助都将不胜感激。您遇到了版本问题。这条线
raise AttributeError(f'module {__name__!r} has no attribute {name!r}')
在Python2.7下运行,但在Python3.6(或3.7)下运行,在早期版本中会出现语法错误。在您的情况下,我会将Python 2.7安装视为无可挽回的损坏,因为很明显,标准库的版本并不一致。问题已经解决,删除c:\Python27目录,然后使用安装工具卸载Python 2.7,重新启动计算机并重新安装Python 2.7是否可以检查下载的Python 2.7软件包是否与系统配置(32位或64位)匹配?第二:可能您的2.7虚拟环境中没有安装
日志记录
模块。尝试使用pip安装日志安装它
在虚拟环境中重新安装64位的Python2.7,我仍然有相同的错误。我在Environment var中没有Python2.7,因此安装了日志模块。我设法获得了一个logging.warning(“hello word”)warning:root:hello word
,但仅在第二次尝试时
raise AttributeError(f'module {__name__!r} has no attribute {name!r}')