In VS Code I have a little python (Python 3.11.9) module I'm building beside my main code. The module works fine and runs without issue. I've installed it in edit mode via pip install -e .
Still Pylance cannot resolve my module's imports in any file inside the module.
Import "my_cool_module.utils.logging_utils" could not be resolved
# my_cool_module.main.py
from my_cool_module.core.enhancer import AwesomeEnhancer
from my_cool_module.utils.logging_utils import configure_logging
def main()
pass
# More cool code
I've setup the __init__.py
in every directory and the follow the same pattern as the one below:
# my_cool_module.utils.__init__.py
from my_cool_module.utils.logging_utils import configure_logging # This import also cannot be resolved
__all__ = ['configure_logging']
This occurs in any file in the module that is importing other parts, the __init__.py
files should all be configured and it runs without issue.
.venv
Other Code Files <- We can import and use MyCoolModule without issue
My Cool Module
┣ ...other module code
┣ utils
┃ ┣ logging_utils.py
┃ ┗ __init__.py
┣ main.py
┣ pyproject.toml
┣ Readme.md
┣ setup.py
┗ __init__.py
I've verified my setup.py, I've created a pyproject.toml file to see if that was the issue. I've created a .env
file in my main directory with to manually add my workspace to the project path,
# .env
PYTHONPATH=${workspaceFolder}
I've also added the following settings to my .code-workspace
file
// MyProject.code-workspace
"settings":{
"python.autoComplete.extraPaths": [
"${workspaceFolder}",
"${workspaceFolder}/my_cool_module"
],
"python.analysis.extraPaths": [
"${workspaceFolder}",
"${workspaceFolder}/my_cool_module"
]
}
Still it seems that Pylance can't resolve the imports inside the module itself and I'd like to get that fixed.
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744191328a4562446.html
评论列表(0条)