1. 解决模块找不到问题(ModuleNotFoundError: No module named 'test5')
- 比如import test5时,找不到test5,如果test5在
D:/test
目录下,则现在添加到工作目录中,再import相关模块
python
import sys
print("path:", sys.path)
sys.path.append("D:/test")
print("path2:", sys.path)
import test5
- 打印
log
path: ['E:\\code\\pythonProject', 'E:\\code\\pythonProject', 'D:\\Program Files\\Python312\\python312.zip', 'D:\\Program Files\\Python312\\DLLs', 'D:\\Program Files\\Python312\\Lib', 'D:\\Program Files\\Python312', 'E:\\code\\pythonProject\\venv', 'E:\\code\\pythonProject\\venv\\Lib\\site-packages']
path2: ['E:\\code\\pythonProject', 'E:\\code\\pythonProject', 'D:\\Program Files\\Python312\\python312.zip', 'D:\\Program Files\\Python312\\DLLs', 'D:\\Program Files\\Python312\\Lib', 'D:\\Program Files\\Python312', 'E:\\code\\pythonProject\\venv', 'E:\\code\\pythonProject\\venv\\Lib\\site-packages', 'D:/test']