如何解决“ModuleError:No module named‘new’”问题?

2024-10-01 11:24:56 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图运行一个程序,但是我得到一个错误,说:

Traceback (most recent call last):
 File "C:\Users\mmv456\AppData\Local\Programs\Python\Python36\lib\site.py", line 168, in addpackage
  exec(line)
File "<string>", line 1, in <module>
ModuleNotFoundError: No module named 'new'

我试着找到这个站点.py文件在那个目录中,但它不在那里,所以我看不出python文件中到底有什么问题。我很感激你的帮助。在

编辑:添加代码:

^{pr2}$

Tags: 文件inpy程序most错误linecall
1条回答
网友
1楼 · 发布于 2024-10-01 11:24:56

ModuleNotFoundError: No module named 'new'这一行表示导入中有错误。在

如果我添加了新的代码,你就可以运行它了:

import collections
import itertools
import sys
import new # I just added

if sys.platform == 'cli':
    import System
    CPU_COUNT = System.Environment.ProcessorCount
else:
    #try:
    #    import multiprocessing
    #    CPU_COUNT = multiprocessing.cpu_count()
    #except ImportError:
    #    CPU_COUNT = 1

    # IronPython seems to be the only common Python implementation that   doesn't
    # have a GIL and therefore the only implementation that benefits from this.
    # Therefore, don't bother making any threads on other implementations.
CPU_COUNT = 1

try:
    import thread
    import threading
except ImportError:
    import dummy_threading as threading
    import _dummy_thread as thread
    CPU_COUNT = 1

错误:

^{pr2}$

但问题是我的错误在test.py中,而你的错误指向的是python库中的site.py。这意味着你的python环境出了问题。即使在世界各地也有类似的issues。在

Simple solution is uninstalling and reinstalling your python environment.

相关问题 更多 >