简体   繁体   English

尝试导入任何模块时出现语法错误

[英]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.23.9.5包含该语句仅出现在第25562581 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变体中,它位于各种类似的行上,大约25522577为小文件更改提供或取几行。

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.

相关问题 尝试导入模块时出错 - Error when I try to import a module 当我尝试将mwclient模块用于Python时,为什么会出现错误“无法导入名称扫描仪”? - Why am I getting the error “cannot import name Scanner” when I try to use the mwclient module for Python? 尝试导入skimage时缺少什么模块? Python 3.5 - What module is missing when I try to import skimage? Python 3.5 当我尝试导入模块时在Jupyter Notebook NameError中 - In Jupyter Notebook NameError when I try to import a module 当我尝试导入 lxml.html 时出现导入错误 - import error when i try to import lxml.html 在 django 中,我创建了“工具”应用程序,当我尝试将工具导入其他文件时出现错误“没有名为‘工具’的模块” - In django I have created "tool" app, When I try to import tool to other file I got error "No module named 'tool' " 尝试从 areelle 模块导入 Cntlr 时出现语法错误 - Syntax error when trying to import Cntlr from arelle module 我收到消息:“错误的导入语法:”当我尝试在我的 gnuradio 流程图中导入一个 python 函数时 - I got the message: "Bad import syntax:" when I try to import a python function inside my gnuradio flowgraph 当我尝试运行“import matplotlib.pyplot as plt”时,我收到以下错误:“ModuleNotFoundError: No module named 'PIL'” - When I try to run “import matplotlib.pyplot as plt”, I receive the following error: “ModuleNotFoundError: No module named 'PIL'” 当我尝试使用“”字符进行打印时,出现语法错误 - When I try to use the “”" thing for print, i get a syntax error
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM