Skip to main content
-1 votes
0 answers
31 views

Convert importlib.resources Anchor to Path only when no temporary directory is needed

importlib.resources.path allows to convert an Anchor to a Path. Sometimes, this path is just some existing path on the file system (e.g. when a module is loaded from a folder), sometimes, a temporary ...
502E532E's user avatar
  • 561
0 votes
1 answer
77 views

Use importlib.resources for files inside the top level parent module

I want to load a file from my python module using importlib.resources (see also this question). If the file is inside a submodule, this is straight forward (run using python -m, see here): import ...
502E532E's user avatar
  • 561
0 votes
1 answer
59 views

Why does inspect fail to get source file for classes in a dynamically-imported module?

inspect.getsource() and inspect.getsourcefile() can access source info for a function, but not for a class, when they are in a module that is imported dynamically with importlib. Here are two files, ...
Jason S's user avatar
  • 190k
1 vote
0 answers
78 views

importlib resources files -> not a package, empty module

I tend to alwasy run the testers from inside the module folder, but this breaks the "resources.files" functionality, as it seems not to be able to find the module any more module folder ...
hewi's user avatar
  • 1,416
0 votes
0 answers
99 views

How to properly import python module from another python file using importlib.import_module?

I'm working on Alembic migration github action and need to import base metadata class inside python migration script which locates in another directory. I can't import it directly inside python ...
andrey's user avatar
  • 1,197
2 votes
1 answer
63 views

What's `_distutils_hack.DistutilsMetaFinder` in `sys.meta_path`?

The document of Python's import system tells that there are 3 default finders/importers (built-in, frozen, and the import path one). But when trying to get the repr of sys.meta_path, I got another ...
Phuturesh's user avatar
0 votes
0 answers
46 views

Use importlib.resources.files with no argument

I want to use importlib.resources.files to access a file from a module. According to the docs, If the anchor is omitted, the caller’s module is used. So I would assume something like import ...
502E532E's user avatar
  • 561
0 votes
1 answer
83 views

Check if a python module exists with specific venv path

If I have a venv path, how can I find out if a Python module is installed inside that venv? I normally use importlib.util.find_spec. But this only works for the current venv that is active and does ...
ArianNa's user avatar
  • 53
0 votes
1 answer
99 views

How to manually create a namesapce package import from a list of paths?

According to PEP420, namespace packages have the lowest precedence. For example, import xxx will not create a namespace package xxx if there are any xxx/__init__.pys or xxx.{py,pyc,so,pyd}s in any ...
John Ao's user avatar
  • 169
0 votes
1 answer
56 views

Why does importlib.resources read_text raise UnicodeDecodeError on Windows but not mac and RPi?

I am writing a small web app (https://github.com/r-owen/base_loom_server) and it runs on macOS and Raspberry Pi, but a Windows user reports an exception when Python reads a UTF-8-encoded resource file ...
Russell Owen's user avatar
0 votes
1 answer
52 views

python importlib from subdirectory, module not found

I'v been struggling with importing a sub module. In main.py two modules are imported located under 220_04_070. I'm using importlib since the directory name only consist of numbers. common.py just ...
hzcodec's user avatar
  • 57
0 votes
2 answers
166 views

How to dynamically import functions from a file in a subdirectory? [duplicate]

I am trying to dynamically import functions from a file in a subdirectory. For example: workspace --|main.py ----|subfolder1 ------|subfolder2 --------|file1.py --------|file2.py The file main.py ...
GalaxyGamerYT's user avatar
1 vote
0 answers
47 views

Overriding pip package

I am trying to setup Octoprint on a new orangepi 3b board. It has been a bit problematic. One problem is about access to gpio for all the existing plugins. The standard RPi.GPIO python library does ...
Lars's user avatar
  • 11
5 votes
2 answers
705 views

Django autoreload raises: TypeError: unhashable type: 'types.SimpleNamespace'

When I upgrade importlib_meta from version 8.4.0 to 8.5.0 (released just yesterday, Sep 11 2024), I get the following error when I start running the development server with python manage.py runserver: ...
Paul's user avatar
  • 116
1 vote
0 answers
946 views

Reloading torch triggers RuntimeError

When trying to reload the torch library in Python, by running the following lines of code, I encountered the error below: import torch import importlib importlib.reload(torch) ------------------------...
jmpion's user avatar
  • 11

15 30 50 per page
1
2 3 4 5
28