简体   繁体   中英

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 . 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.

It has never been anywhere near line 1769 in any of the 3.9 releases (including the release candidates).

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. 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. 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).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM