[英]Syntax error when I try to import any module
C:\Users\sanji\PycharmProjects\pythonProject2\venv\Scripts\python.exe C:/Users/sanji/PycharmProjects/pythonProject2/file.py
Traceback (most recent call last):
File "C:\Users\sanji\PycharmProjects\pythonProject2\file.py", line 1, in
import tkinter
File "C:\Users\sanji\AppData\Local\Programs\Python\Python39\lib\tkinter\__init__.py", line 1769
if self._name in self.master.children:
^
SyntaxError: invalid syntax
Process finished with exit code 1
In the __init__.py
file for Tkinter
, versions 3.9.2
through 3.9.5
inclusive have that statement appearing only on lines 2556
and 2581
.在
Tkinter
的__init__.py
文件中,版本3.9.2
到3.9.5
包含该语句仅出现在第2556
和2581
。 See here , for example.例如,请参见此处。
In the 3.9
variants before that, it's on various similar lines, around 2552
and 2577
give or take a couple of lines for small file changes.在之前的
3.9
变体中,它位于各种类似的行上,大约2552
和2577
为小文件更改提供或取几行。
It has never been anywhere near line 1769
in any of the 3.9
releases (including the release candidates).在任何
3.9
版本(包括候选版本)中,它从未接近第1769
行。
So, given it's complaining about the file in the path containing ...Python\\Python39\\lib\\...
, I don't think we need to look at any other versions.因此,鉴于它抱怨路径中包含
...Python\\Python39\\lib\\...
,我认为我们不需要查看任何其他版本。 I would say it's a safe bet that the file has become corrupted somehow.我会说文件已以某种方式损坏是一个安全的赌注。
You should check that file for validity and, if there's something wrong with it (probable), you may need to re-install Python to fix it.您应该检查该文件的有效性,如果有问题(可能),您可能需要重新安装 Python 来修复它。 We can probably only speculate as to how it became corrupted (if indeed it did).
我们可能只能推测它是如何损坏的(如果确实如此)。
Maybe someone accidentally edited it or maybe you have a problematic disk.也许有人不小心编辑了它,或者您的磁盘有问题。 It's hard to say without seeing the entire file (or at least some twenty lines around the one the error's reported on).
很难说没有看到整个文件(或者至少在报告错误的那个文件周围有二十行)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.