python-import

Langchain: ModuleNotFoundError: No module named 'langchain'

Langchain: ModuleNotFoundError: No module named 'langchain' Question: When I write code in VS Code, beginning with: import os from langchain.chains import RetrievalQA from langchain.llms import OpenAI from langchain.document_loaders import TextLoader I am met with the error: ModuleNotFoundError: No module named ‘langchain’ I have updated my Python to version 3.11.4, have updated pip, and reinstalled langchain. …

Total answers: 7

How to resolve ModuleNotFoundError when importing a local Python file?

How to resolve ModuleNotFoundError when importing a local Python file? Question: I am studying python. I’m trying to do a simple exercise from the course I’m studying. I tried to separate the classes into different files to make it easier to keep track of the inheritance and to be able to update the program in …

Total answers: 1

Python – overwrite constant from imported file and use in imported functions

Python – overwrite constant from imported file and use in imported functions Question: I have a module where some constants are defined and also used in several functions. How can I over-ride their values from my main file ? Say this is the module, test_import.py MY_CONST = 1 def my_func(var = MY_CONST): print(var) And this …

Total answers: 1

Using BeautifulSoup in a BeeWare app gives `ModuleNotFoundError: No module named 'bs4'

Using BeautifulSoup in a BeeWare app gives `ModuleNotFoundError: No module named 'bs4' Question: I am trying to import beautifulsoup4in a BeeWare app (with its own virtual environment) using the command: from bs4 import BeautifulSoup But I get a ModuleNotFoundError: No module named ‘bs4’ even though I have installed beautifulsoup4 in my virtual environment and added …

Total answers: 1

Python can't import module

Python can't import module Question: I found a lot of similar questions, but no one gave any answer. Still doesn’t work. My current structure: Project: – exp: — main.py – mypac: – internal: — __init__.py — next_mod.py — __init__.py — file.py ../Project/mypac/__init__.py: from .internal.next_mod import print_smth ../Project/mypac/internal/next_mod.py: def print_smth(): print(f'{__name__} from another module’) ../Project/exp/main.py: from …

Total answers: 3

Create a python venv that works on systems with no python installed

Create a python venv that works on systems with no python installed Question: How do I setup a virtual environment in such a way that is can be used to call a python script, but doesn’t need a system wide python. My goal is it to have one folder with the python script in it …

Total answers: 2

Module's __getattr__ is called twice

Module's __getattr__ is called twice Question: PEP-562 introduced __getattr__ for modules. While testing I noticed this magic method is called twice when called in this form: from X import Y. file_b.py: def __getattr__(name): print("__getattr__ called:", name) file_a.py: from file_b import foo, bar output: __getattr__ called: __path__ __getattr__ called: foo __getattr__ called: bar __getattr__ called: foo …

Total answers: 1

Is there a difference between `import a as b` and `import a ; b = a`?

Is there a difference between `import a as b` and `import a ; b = a`? Question: It’s common for me to write in REPL, for example: from datetime import datetime as dt Is there a difference between this sentence and from datetime import datetime dt = datetime ? For now I can list two: …

Total answers: 1

reveal_type gives me a type, but it does not exist

reveal_type gives me a type, but it does not exist Question: So, I have a code that typechecks, but when I try to run it, it complains about the type not existing import pyrsistent a = pyrsistent.pset([1,2,3]) #reveal_type(a) #mypy file.py, gives type pyrsistent.typing.PSet[buildins.int] #b : pyrsistent.typing.PSet[int] = a #when running: AttributeError: module ‘pyrsistent’ has no …

Total answers: 1

How to call an imported module knowing its name as a string?

How to call an imported module knowing its name as a string? Question: I am writing an application that should test the solution of many students. I have structure like this app/ students/ A/ lab1/ solution.py lab2 solution.py B/ lab1/ solution.py C/ test.py I want to import the solution file in the testing module and …

Total answers: 1