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
This is just a personal development experience share. Since I'll include a bit of personal story later, I've put the key points at the beginning.
In your VSCode settings.json (either globally or within a project), set the following content:
I used to be a PyCharm user, and its many features provided a lot of convenience when I was first using Python.
It could enable all functions comprehensively with almost no configuration.
However, its downside is that it places a heavy load on the CPU and memory.
The rise of AI led me to switch to using VSCode (or Cursor).
Even before AI became prominent, I had tried several times to transition to VSCode.
Although it's relatively lightweight and efficient, if you don't know how to configure settings.json to customize your Python experience, you might find it difficult to get used to VSCode's incomplete Python features.
However, VSCode actually offers many hidden features and a high degree of customization for Python.
Many useful functions aren't enabled by default and require manual activation.
Auto import is one of these features.
In VSCode, Pylance by default only recognizes the top-level modules of installed third-party packages.
For example, if I type ChatOpenAI, it knows to import it using from langchain_openai import ChatOpenAI because it's at the top level of that package.
However, without manually modifying settings.json, when I type AIMessage, Pylance doesn't know where to import it from (whereas PyCharm can do this without any configuration).
This is because AIMessage is at the second level in langchain_core (specifically, langchain_core.messages).
It must be imported using from langchain_core.messages import AIMessage.
In langchain_core, most commonly used objects are accessible at the second level, so we set the depth to 2.
In langgraph, most frequently used objects are located at the second or third level, so you need to set the depth to 3.
Additionally, because the root directory of this package lacks an __init__.py (for specific reasons, refer to #4331), you also need to add includeAllSymbols: true for Pylance to automatically import most objects from langgraph.
Here are some features of VSCode that I only discovered after using it for a while, and I wish I had known about them sooner.
Langchain is a relatively large library, and often I remember the names of its objects but forget their import paths.
The auto-import feature has greatly improved my development experience.
There are many other Python features in VSCode that I have yet to discover. Exploring them and configuring my own settings.json is one of the joys of programming for me!
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
This is just a personal development experience share.
Since I'll include a bit of personal story later, I've put the key points at the beginning.In your VSCode
settings.json
(either globally or within a project), set the following content:You can refer to the relevant documentation here
https://github.com/microsoft/pylance-release/blob/main/docs/settings/python_analysis_packageIndexDepths.md
I used to be a
PyCharm
user, and its many features provided a lot of convenience when I was first using Python.It could enable all functions comprehensively with almost no configuration.
However, its downside is that it places a heavy load on the CPU and memory.
The rise of AI led me to switch to using VSCode (or Cursor).
Even before AI became prominent, I had tried several times to transition to VSCode.
Although it's relatively lightweight and efficient, if you don't know how to configure settings.json to customize your Python experience, you might find it difficult to get used to VSCode's incomplete Python features.
However, VSCode actually offers many hidden features and a high degree of customization for Python.
Many useful functions aren't enabled by default and require manual activation.
Auto import is one of these features.
In VSCode, Pylance by default only recognizes the top-level modules of installed third-party packages.
For example, if I type
ChatOpenAI
, it knows to import it usingfrom langchain_openai import ChatOpenAI
because it's at the top level of that package.However, without manually modifying
settings.json
, when I typeAIMessage
, Pylance doesn't know where to import it from (whereas PyCharm can do this without any configuration).This is because
AIMessage
is at the second level inlangchain_core
(specifically,langchain_core.messages
).It must be imported using
from langchain_core.messages import AIMessage
.In
langchain_core
, most commonly used objects are accessible at the second level, so we set thedepth
to 2.In
langgraph
, most frequently used objects are located at the second or third level, so you need to set thedepth
to 3.Additionally, because the root directory of this package lacks an
__init__.py
(for specific reasons, refer to #4331), you also need to addincludeAllSymbols: true
for Pylance to automatically import most objects fromlanggraph
.Here are some features of VSCode that I only discovered after using it for a while, and I wish I had known about them sooner.
Langchain is a relatively large library, and often I remember the names of its objects but forget their import paths.
The auto-import feature has greatly improved my development experience.
There are many other Python features in VSCode that I have yet to discover. Exploring them and configuring my own
settings.json
is one of the joys of programming for me!Beta Was this translation helpful? Give feedback.
All reactions