目前看起来文件在两个软件下运行时工作目录不一样,但是也不应该啊, 我问 chatgpt 回答是 Python 中,当您想要导入一个模块时,Python 解释器会按照以下路径搜索模块:
当前目录:Python 会首先在当前工作目录中查找要导入的模块,所以 vscode 为啥会找不到这个模块呢
1
ClericPy 2023-04-08 20:08:06 +08:00
我记得 Pycharm 自动把当前项目加入路径, 还是说启动脚本的 cwd 和 vscode 不一样
简单对比就是你在最开头分别打印 sys.path 和 os.getcwd |
2
shinonome OP 确实,少了一个
## VScode ['/Volumes/save/my_code/Auto_Bangumi/src/module/downloader', '/Library/Frameworks/Python.framework/Versions/3.10/lib/python310.zip', '/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10', '/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/lib-dynload', '/Volumes/save/my_code/Auto_Bangumi/src/venv/lib/python3.10/site-packages'] ## Pycharm ['/Volumes/save/my_code/Auto_Bangumi/src/module/downloader', * '/Volumes/save/my_code/Auto_Bangumi/src' *, '/Applications/PyCharm.app/Contents/plugins/python/helpers/pycharm_display', '/Library/Frameworks/Python.framework/Versions/3.10/lib/python310.zip', '/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10', '/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/lib-dynload', '/Volumes/save/my_code/Auto_Bangumi/src/venv/lib/python3.10/site-packages', '/Applications/PyCharm.app/Contents/plugins/python/helpers/pycharm_matplotlib_backend'] |
3
shinonome OP "terminal.integrated.env.osx": {
"PYTHONPATH": "${workspaceFolder}" }, 在设置中添加就好了, |