Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Seeing an error ModuleNotFoundError: No module named 'langchain.globals' #13064

Closed
14 tasks
amrit2cisco opened this issue Nov 8, 2023 · 3 comments
Closed
14 tasks
Labels
🤖:bug Related to a bug, vulnerability, unexpected error with an existing feature

Comments

@amrit2cisco
Copy link

System Info

LangChain version pinned to "^0.0.278" (using Poetry)
Python 3.11.5

Other modules from langchain (such as langchain.cache and langchain.chains) are imported within the same file in the application code and are able to be found. Only the langchain.globals module is not being recognized

Who can help?

No response

Information

  • The official example notebooks/scripts
  • My own modified scripts

Related Components

  • LLMs/Chat Models
  • Embedding Models
  • Prompts / Prompt Templates / Prompt Selectors
  • Output Parsers
  • Document Loaders
  • Vector Stores / Retrievers
  • Memory
  • Agents / Agent Executors
  • Tools / Toolkits
  • Chains
  • Callbacks/Tracing
  • Async

Reproduction

Import langchain.globals

Error happens on application startup

Expected behavior

Expected to be able to find the module, as langchain's other module's are able to be found by the same application code

@dosubot dosubot bot added the 🤖:bug Related to a bug, vulnerability, unexpected error with an existing feature label Nov 8, 2023
Copy link

dosubot bot commented Nov 8, 2023

🤖

Hello @amrit2cisco,

Nice to meet you! I'm here to assist you with your issues related to LangChain. I'm a bot, designed to help solve bugs, answer questions, and guide you to become a contributor while we wait for a human maintainer. Let's get started on this!

Based on the information provided, it seems like the 'langchain.globals' module is not directly importable in the LangChain version "^0.0.278". This is likely because the 'langchain.globals' module is not imported at the top level of the 'init.py' file. Instead, it's imported within the 'getattr' function, which is a special Python function that is called when trying to access a non-existent attribute.

To resolve this issue, you should replace any direct imports of 'langchain.globals' with the appropriate function calls to 'langchain.globals.set_verbose()', 'langchain.globals.get_verbose()', 'langchain.globals.set_debug()', 'langchain.globals.get_debug()', 'langchain.globals.set_llm_cache()', or 'langchain.globals.get_llm_cache()', as suggested by the warning messages.

Here's an example of how you can use these functions:

from langchain import globals

# Set verbose
globals.set_verbose(True)

# Get verbose
verbose = globals.get_verbose()

# Set debug
globals.set_debug(True)

# Get debug
debug = globals.get_debug()

# Set llm_cache
globals.set_llm_cache(True)

# Get llm_cache
llm_cache = globals.get_llm_cache()

Please note that these functions should be used instead of directly accessing the 'verbose', 'debug', and 'llm_cache' attributes.

For more information, you can refer to the following files in the LangChain repository:

I hope this helps! Let me know if you have any other questions.

Sources


This response is meant to be useful and save you time. It is not meant to be a precise solution, but rather a starting point for your own research.

Help me be more useful! Please leave a 👍 if this is helpful and 👎 if it is irrelevant.

If you want to continue the conversation, start your reply with @dosu-bot.

@aisu-programming
Copy link

Did what the bot said and I got the following error:

ImportError: cannot import name 'globals' from partially initialized module 'langchain' (most likely due to a circular import) (SOMAEPATH\langchain.py)

@aisu-programming
Copy link

#2079 (comment)

Found the comment here and found that I'm not a smart man either.😅

@dosubot dosubot bot added the stale Issue has not had recent activity or appears to be solved. Stale issues will be automatically closed label Apr 28, 2024
@dosubot dosubot bot closed this as not planned Won't fix, can't repro, duplicate, stale May 5, 2024
@dosubot dosubot bot removed the stale Issue has not had recent activity or appears to be solved. Stale issues will be automatically closed label May 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🤖:bug Related to a bug, vulnerability, unexpected error with an existing feature
Projects
None yet
Development

No branches or pull requests

2 participants