ModulenotFoundError:无模块
我一直在编写的代码上遇到这个问题,我无法弄清楚原因。
我的项目结构:
├──code
| ├── Bot_Tracker
| | ├── __init__.py
| | ├── matchhistory.py
| | ├── discordUI.py
| ├── Tests
| | ├── __init__.py
| | └── test_matchhistory.py
test_matchhistory.py
中的导入语句:
from Bot_Tracker.matchhistory import compMatchHistory
我不明白为什么我会继续遇到错误。
I keep having this issue with the code I had written, I cant figure out why.
My project structure:
├──code
| ├── Bot_Tracker
| | ├── __init__.py
| | ├── matchhistory.py
| | ├── discordUI.py
| ├── Tests
| | ├── __init__.py
| | └── test_matchhistory.py
My import statements in test_matchhistory.py
:
from Bot_Tracker.matchhistory import compMatchHistory
I don't understand why I keep getting the error.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是一个简单的问题,与Python如何处理包装的存储位置有关。如果软件包不在Python路径中,则Python将无法在导入上访问它。
为了解决这个问题,我需要将软件包目录和父添加到系统路径的软件包目录。
我使用的代码:
此代码基本上找到了当时存储文件的目录以及该目录的父,然后检查该目录的路径是否存在于
sys.path
中。This was a simple problem related to how Python works out where packages are stored. If the package is not in the python path, then python won't be able to access it on the import.
To solve this I needed to add the package directory and the parent to the package directory to the system path.
The code I used:
This code basically finds the directory where the file is stored then and the parent of that directory, after which it checks if the paths to this directories exist in
sys.path
.