6,048 questions
-4
votes
0
answers
117
views
How to force re-import of `from X import Y` statement in python? [duplicate]
How can I force python to execute the following
from X import Y
There is a package X that has some init code just orphaned in the file (not wrapped in a function). It's a black box that I cannot ...
-1
votes
0
answers
102
views
Resolving a circular import problem with a specific module layout
I have a module foo set up like this:
└── modules
├── some_other_class
│ └── ...
└── foo
├── __init__.py
├── base.py
├── data_fields.py
└── ...
3
votes
2
answers
117
views
Why does a missing but unnecessary parent cause a dynamic module reload to fail?
I am getting an error when I use importlib.reload on a dynamic import. The dynamic import succeeds, but an immediately subsequent importlib.reload() fails, complaining there's no parent module. What ...
1
vote
1
answer
129
views
Changes to --editable Python libraries require a reset of ipython to be seen [duplicate]
I develop Python libraries (like this one) inside a (mini)conda environment using:
a text editor (VS Code for that matter, but purely as text editor); and
a separate zsh terminal (currently on macOS ...
3
votes
1
answer
171
views
How to make tables with relationships in SQLAlchemy in different files
I have many-to-many connection in my database and trying to make tables with ORM. Now I have 3 tables (one is secondary)
class TableA(Base):
__tablename__ = "tablea"
id: Mapped[int] =...
Advice
3
votes
2
replies
42
views
Missing symbol auto import functionality in Jupyter Notebook
When writing python code in a jupyter notebook, I often have to remember the exact imports for the libraries I'm using or copy pasting them. When using an IDE, you will usually get a red squiggly line ...
1
vote
2
answers
83
views
Django startproject fails after I manually created the project files/folders (name conflict?)
I’m setting up a Django + Channels project and I think I messed up the order.
I ran these commands:
cd ~
mkdir social_mvp
cd social_mvp
mkdir socialsite
mkdir core
mkdir -p core/templates/core
mkdir -...
0
votes
1
answer
115
views
"No module named " error on raspi and not Windows
The module I am trying to import is part of a project with the structure
VIS/
├── __init__.py
└── Objects/
├── __init__.py
└── _Root.py
I am trying to import Root from \_Root.py with from VIS....
0
votes
1
answer
314
views
AttributeError: module 'typing_extensions' has no attribute 'Generic' during import dash
I'm running python 3.11.2 in a venv (/home/pi/myenv) on a Raspberry Pi Zero. I installed dash in the venv using pip. When running import dash I get the following error:
>>> import dash
...
Advice
1
vote
4
replies
178
views
mypy complains about a missing optional module
I have a module (let's name it optional_module) that I want to be imported optionally, as it can be either present or absent. Now I do it this simple way:
try:
import optional_module
except ...
4
votes
2
answers
154
views
How does Python decide whether the last part of an imported name is a module or a function?
My first question is whether the code in main.py is valid?
This is main.py:
import foo.bar as fb
fb()
This is foo/__init__.py:
from .bar import * # DELETE THIS
bar = lambda: print('lambda bar')
foo/...
2
votes
0
answers
217
views
What is the documented behaviour (if any) when someone imports `pkg.__init__[ as pkg]` instead of `import pkg`?
To be clear, I'm not suggesting anyone actually should import pkg.__init__ directly. This is to understand potential pitfalls if someone decides to convert a module-only distribution into a package, ...
1
vote
2
answers
81
views
Python catch ImportError without catching transitive errors raised by the module
In Python, when an import fails, how can I differentiate between:
The module doesn't exist.
The module exists, but it tried importing another module that didn't exist.
Example
# ./first.py
try:
...
-2
votes
1
answer
114
views
Is it possible to install submodules of a python package dynamically?
I have a very complex Python library that is used by several people/projects for different purposes.
The structure is basically the same as many Python libraries, but I would like to give the ability ...
0
votes
0
answers
116
views
Setuptools : why editable mode does not work outside of my project directory?
I don't manage to make the editable mode pip install -e . for a local installation of my project. After the installation, when I import a constructor from a module of my package within in python shell ...