简体   繁体   English

为什么 python 说“没有名为 os 的模块”?

[英]Why does python say, “no module named os”?

As usual, I opened Notepad++ and wrote my python code.像往常一样,我打开 Notepad++ 并编写了我的 python 代码。 Then when I opened my CMD to execute it, I got this error然后当我打开我的 CMD 执行它时,我得到了这个错误

`Fatal Python error: init_import_size: Failed to import the site module
Python runtime state: initialized
Traceback (most recent call last):
  File "C:\Users\pc\AppData\Local\Programs\Python\Python38-32\Lib\site.py", line 73, in <module>
    import os
ModuleNotFoundError: No module named 'os'

I uninstalled and reinstalled python hoping that it'll run, but it didn't.我卸载并重新安装了 python 希望它能运行,但它没有。 Can anybody please help!有人可以帮忙吗!

EDIT: Python doesn't work on my pc.编辑: Python 在我的电脑上不起作用。 Whenever I type "python" in the CMD, it would throw this error, IDLE is also not opening.每当我在 CMD 中键入“python”时,都会抛出此错误,IDLE 也无法打开。 And yes, my python is added to PATH so please don't say to add it to the path.是的,我的 python 已添加到路径中,所以请不要说将其添加到路径中。

Try to run this snippet尝试运行此代码段

import os
output = os.environ['HOME']
print(output)

If this is not working then there is issue with your python installation.如果这不起作用,那么您的 python 安装存在问题。 You need to re-install it.您需要重新安装它。

To get comfortable with python modules you can learn from here要熟悉 python 模块,您可以从这里学习

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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