vscode自定義的模塊,在不同目錄調用時,一直報錯"No module named 'xxx' "


從pycharm換到vscode,被一個錯誤糾結好久,就是自定義的模塊,在不同目錄相互調用時,一直報錯"No module named 'xxx' "

查了好多資料,一直沒解決,最后發現,為什么pycharm可以,但vs code不行,主要是因為pycharm創建時會創建__init__.py文件,所以調用不報錯,在vscode文件夾下創建__init__.py就不會報錯了

還要更改:

 

 

{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Python",
"type": "python",
"request": "launch",
"stopOnEntry": false,
"pythonPath": "${command:python.interpreterPath}",
"program": "${file}",
"cwd": "${workspaceRoot}",
"env": {"PYTHONPATH":"${workspaceRoot}"},
"envFile": "${workspaceRoot}/.env"
}
]
}

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM