Skip to main content
Advice
1 vote
4 replies
77 views

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 ...
Phant's user avatar
  • 43
4 votes
2 answers
142 views

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/...
Andrei's user avatar
  • 46
1 vote
0 answers
162 views

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, ...
dROOOze's user avatar
  • 4,194
1 vote
2 answers
63 views

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: ...
kviLL's user avatar
  • 443
-2 votes
1 answer
87 views

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 ...
jcfaracco's user avatar
  • 880
0 votes
0 answers
97 views

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 ...
kouign amann's user avatar
0 votes
2 answers
161 views

I am trying to put in my Bash script a one-liner that would print my python's path python -c 'import sys; for p in sys.path: print(p)' the for keyword is flagged as an invalid syntax I was expecting ...
Paweł Wójcik's user avatar
1 vote
2 answers
115 views

I want to generate a schema based on a class defined in another file, so i need to know the return type of these functions. However, the annotation might be based on some imports under TYPE_CHECKING. ...
XXXHHHH's user avatar
  • 130
-3 votes
1 answer
82 views

I've got the following project tree: SomeDir |- script.py |- TestDir | |- test.py script.py is designed to be called in CLI and contains several classes: notably one that does the actual job and one ...
Oersted's user avatar
  • 3,834
6 votes
1 answer
219 views

I find myself mixing both import x and from x import y forms for the same module, depending how often a particular object is used and whether it is clear which modules it comes from. For example I ...
Dominik Kaszewski's user avatar
2 votes
1 answer
108 views

I'm implementing my own Python module package, called jbpy. I'm using setuptools with a pyproject.toml file as the build system. I'm working on Ubuntu 24.04, but I also get the error under WSL on a ...
Jens Bang's user avatar
1 vote
0 answers
77 views

Since os is a module instead of a package, import os.path should fail. For comparison: >>> import os.sys Traceback (most recent call last): File "<python-input-0>", line 1, ...
Aemyl's user avatar
  • 2,447
0 votes
1 answer
105 views

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
  • 581
1 vote
2 answers
95 views

I'm currently working on a modular python framework. The current dilemma is, that one module has a set of submodules that have vastly different dependencies, and a user usually would only use one of ...
Oliver's user avatar
  • 84
0 votes
1 answer
138 views

How to build a python project into a single executable if it has files split in multiple directories? This is my project structure: ├── main.py ├── main.spec ├── src/ │ ├── GUI/ │ │ ├── ...
HappyLemon's user avatar

15 30 50 per page
1
2 3 4 5
404