You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Most likely scenario would be to create a workspace at a single repository level.
However, you can have cases where you have several repositories in a workspace (e.g. loading multiple repositories from a single BitBucket project). This can be achieved using a Multi-folder workspace where each folder in the workspace can be the root of a single repository. Refer to Understanding VSCode #96 for more details on this.
Make sure to change your default shell to "cmd". You can do that from the drop down in the "Terminal window". Once you do this, you can use all conda commands in this terminal.
Setting your python interpreter
Do this as explained in the link above and do this for the whole workspace, not just for the open file.
Change linter to pylint (Update: Use flake8 instead)
Change type checker to 'mypy' - Can also use this for linting (Update: Use flake8 instead)
File >> Preferences >> Settings >> Search for "mypy" >>Add the target folders (must have folders with init.py under the target folder, else mypy will not check them recursively - more details here.
If this does not work, make sure the settings.json file under .vscode folder looks like this
Note: only add the rules below that you want to ignore (below if just an example)
Bracket Pair Colorization: extension is not maintained anymore since it is natively supported by VSCode. But you need to add this setting to enable it.
If some modules are not recognized by VSCode (for autocompletion), you can add them to the extraPaths list. After this is added, any modules used under this path will show autocompletion help when typing and will not complain about the reportMissingImports error. Note that this only impacts autocompletion. In the code, you still have to include the path in your sys.path for the module to be found, else the code will not run.
Pylance doesn't know which search paths will be used at the time you execute your Python code. You need to tell it. By default, Pylance will assume that the search paths will include the root of the workspace you open. It also automatically adds a subdirectory called "src" if it's present, since it's common practice to place your code within a subdirectory of that name. Any other subdirectories that should be included in the search path must be specified using the "python.analysis.extraPaths" setting.
NOTE: adding the path to the JSON settings is only for VSCode to recognize the module for autocompletion. For running the code, you will still need to add the path to python path. for example (depends on where you are running the code form)
importsysimportos# https://stackoverflow.com/questions/16771894/python-nameerror-global-name-file-is-not-definedif'__file__'invars():
print("We are running the script non interactively")
path=os.path.join(os.path.dirname(__file__), os.pardir)
print(f"Source Folder Path: {path}")
sys.path.append(path)
else:
print('We are running the script interactively')
path=".."print(f"Source Folder Path: {path}")
sys.path.append(path)
Important Notes about extensions and settings above
"python.formatting.provider": "black" could also be used
Syntax highlighting was not working for me (for function docstrings that contained type hints for return values) when I installed these extensions. I had to uninstall Python for VSCode per this link to make it work.
Note that sonarlint does type checking as well so mypy may be redundant. (need to verify this)
However, if you need to install mypy, it requires extra steps. These instructions can be found in the marketplace page for mypy
Setup
Creating a Workspace
How to activate conda environment in VS code
Use this link.
settings.json
file under.vscode
folder looks like thisSetup Extensions
Refer to #169
settings.json
PS: More details can be found in #170
AutoSave, Linting and Formatting
All linting options can be found here
In your config file (Control+shift+p, open settings (JSON)), add these options to enable autosave, autolinting, and auto formatting.
Bracket Pair Colorization: extension is not maintained anymore since it is natively supported by VSCode. But you need to add this setting to enable it.
Module Search Paths for extensions
If some modules are not recognized by VSCode (for autocompletion), you can add them to the
extraPaths
list. After this is added, any modules used under this path will show autocompletion help when typing and will not complain about thereportMissingImports
error. Note that this only impacts autocompletion. In the code, you still have to include the path in yoursys.path
for the module to be found, else the code will not run.Link to this help
NOTE: adding the path to the JSON settings is only for VSCode to recognize the module for autocompletion. For running the code, you will still need to add the path to python path. for example (depends on where you are running the code form)
Error:
ValueError: attempted relative import beyond top-level package
Refer to this issue for more details
Important Notes about extensions and settings above
Python for VSCode
per this link to make it work.sonarlint
does type checking as well somypy
may be redundant. (need to verify this)mypy
, it requires extra steps. These instructions can be found in the marketplace page formypy
cmd
terminalThe text was updated successfully, but these errors were encountered: