vscode-python: Unable to use intellisense and code navigation
Hi I am working on the project which has a huge code base involving many many python source code files. I am using python extension and vscode for the first time and I am running into the following issue.
I have a python file located in path : a/b/c/d/e/legacy/file_reader.py This is imported in the second python file using the following method :
import os import sys sys.path.append(“a/b/c/d/e/legacy”) import file_reader_legacy
In this usage, I observe that the IntelliSense and code navigation work normally However, in our project we define many environment variables which point to paths that can be used in python to import. For example :
import os import sys sys.path.append(os.environ[‘PATH_TO_FILE_READER’] + “/legacy”) ==> PATH_TO_FILE_READER is an environment variable which points to a/b/c/d/e/ import file_reader_legacy
In this usage, I observe that the IntelliSense and code navigation don’t work at all. That is when I select Go to definition option, the extension is not able to navigate to the definition of the method Using absolute paths in our project is not suitable since our codebase has to support many variations and hence we try our best to abstract this as much as possible.
Please note I have created a file called: python_env.env in my ./vscode directory. This file has the definition of environment variables inside it. for example, .vscode/python_env.env PATH_TO_FILE_READER=${PATH_TO_FILE_READER}
I have also defined the following in .vscode/settings.json and .vscode/vscode_workspace.code_workspace files “python.envFile”: “${workspaceFolder}/python_env.env”
Can I kindly get some help in this matter?
Environment data
- VS Code version: 1.45.1
- Extension version (available under the Extensions sidebar): 2020.5.80290
- OS and version: Linux 3.0.101-108.108-default
- Python version (& distribution if applicable, e.g. Anaconda): 3.5.4 64 bit
- Type of virtual environment used (N/A | venv | virtualenv | conda | …): N/A
- Relevant/affected Python packages and their versions: N/A
- Jedi or Language Server? (i.e. what is
"python.jediEnabled"
set to; more info #3977): set to default setting - Value of the
python.languageServer
setting: set to the default setting
Expected behaviour
Please see the description above
Actual behaviour
Please see the description above
Steps to reproduce:
Please see the description above
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Comments: 18
thanks for the help ! now it is working