导入错误:Python 中没有名为 ***** 的模块
我对 python 很陌生,大约一个月,我正在尝试弄清楚 python 中的导入是如何工作的。有人告诉我,我可以导入任何包含 Python 代码的“模块”。因此,我尝试导入一个模块只是为了尝试一下,但我不断收到“ImportError:没有名为 redue 的模块”。这是 python shell 的一个示例:
>>> import os
>>> os.chdir('C:\Users\Cube\Documents\Python')
>>> for file in os.listdir(os.getcwd()):
print file
pronounce.py
pronounce.pyc
readwrite.py
rectangle.py
reduc.py
>>> import reduc
Traceback (most recent call last):
File "<pyshell#32>", line 1, in <module>
import reduc
ImportError: No module named reduc
我做错了什么?我是否忽略了某些事情,或者我只是被错误地告知了?
I am very new to python, about one month, and am trying to figure out how the importing works in python. I was told that I can import any 'module' that has Python code in it. So I am trying to import a module just to try it out, but I keep getting an 'ImportError: No module named redue'. This is an example of the python shell:
>>> import os
>>> os.chdir('C:\Users\Cube\Documents\Python')
>>> for file in os.listdir(os.getcwd()):
print file
pronounce.py
pronounce.pyc
readwrite.py
rectangle.py
reduc.py
>>> import reduc
Traceback (most recent call last):
File "<pyshell#32>", line 1, in <module>
import reduc
ImportError: No module named reduc
What am I doing wrong? I am I overlooking something, or was I just wrongly informed?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这些文件不在 sys.path 上。本来应该如此。
如果您想从解释器访问它们,则需要将位置添加到 sys.path 您
还可以将路径包含在环境变量 - PYTHONPATH 中,
请参阅此处有关模块搜索路径的详细信息:
另请在此处查看 (PYTHONPATH) 环境变量详细信息:
These files are not on sys.path. It should have been though.
If you want to access them from the interpreter, you will need to add the location to sys.path
You could also include the path in environment variable - PYTHONPATH
See the details on module search path here :
Also look at (PYTHONPATH) environment variable details here: