Skip to main content
Filter by
Sorted by
Tagged with
Advice
1 vote
4 replies
67 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
141 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
0 votes
0 answers
30 views

Detail of the Problem: My simple project structure is as follows: └─mris ├─mris.egg-info ├─seggms │ ├─training │ │ └─run_training.py ├─utilities │ └─config.py (contains ...
Natsuki Ruan's user avatar
0 votes
0 answers
87 views

I'm working on a Pycord bot project, and I'm using Nuitka to compile it. My goal is to compile the main script as a single file (--onefile) for distribution, but still be able to dynamically load ...
Kh4lid MD's user avatar
  • 135
2 votes
1 answer
80 views

I have two files. file1 and file2. file1: color = (0, 0, 0) class drawing: def changeColor(newColor): global color color = (newColor) def drawCircle(x, y, r, c=color) #...
YouEatTomatoes's user avatar
0 votes
0 answers
46 views

I created a folder named collections, inside I defined some collections-related modules. When I went to used them, I got an ModuleNotFoundError. Changing the name of collections to my_collections ...
DrStein's user avatar
  • 85
-3 votes
2 answers
110 views

I'm curious as to why this doesn't work, resulting in: ModuleNotFoundError: No module named 'maths' import math as maths from maths import factorial
peedurrr's user avatar
  • 191
1 vote
0 answers
228 views

With VSCode Pylance, many import suggestions are missing when working under these conditions: Package installed in editable mode I'm working in a separate directory Original package does not contain ...
conjuncts's user avatar
0 votes
0 answers
52 views

This question may have a simple answer. I have a near-trivial module0.py: a = 1 b = a + 3 I import this module into a script and redefine module0's global constant a: import module0 as m0 m0.a = 2 ...
SapereAude's user avatar
2 votes
1 answer
68 views

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
-2 votes
1 answer
187 views

I have a project structured like this: project+ |-folder1+ | |-__init__.py | |-script | |-folder2+ | |-__init__.py | |-...
Chompy's user avatar
  • 21
1 vote
0 answers
76 views

I created a test project with the root directory named test_import to reproduce the problem. When I ran the following code to print the sys.path list: import sys for path in sys.path: print(path) ...
zhaomo zhu's user avatar
0 votes
0 answers
79 views

Here is my code: import clr clr.AddReference("PixelPilot.Core") from PixelPilot.Core import * I have already tried renaming the DLL and also trying different names to import it. (EX. ...
Tycho10101's user avatar
0 votes
0 answers
70 views

I am making a React app. I am using some Python code to automate a few things. But currently I am duplicating some Python code across separate components. I would like to avoid this, and place all my ...
nbofni's user avatar
  • 47
0 votes
1 answer
106 views

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
-2 votes
1 answer
129 views

Is it possible to declare a global variable that is invisible to the importing script? For example, in script a.py I have a variable var_a that is accessible to any function in a.py. However, in ...
ysap's user avatar
  • 8,241
-4 votes
2 answers
143 views

I really need to solve my problem because one of the scripts I built, there are hundreds of variables; and in the other script, I don't want to import all variables but only specific variables using ...
luisito_36's user avatar
0 votes
0 answers
33 views

I have a git repo, core, which I would like to use as a submodule within other git repos, e.g. example. core contains python files within which are classes that I would like to import into example. I ...
Jenny's user avatar
  • 1
0 votes
1 answer
108 views

I have two Jupyter notebook files named Test1.ipynb and Test2.ipynb. I would like to be able to import Test2.ipynb from Test1.ipynb in such a way that any changes to Test2.ipynb will take effect ...
Leonidas's user avatar
  • 783
0 votes
3 answers
165 views

I understand that in Python, relative imports are only allowed inside of packages. Personally, I find this functionality great; it makes it very easy to import stuff from other modules. However, for ...
Frotaur's user avatar
  • 131
1 vote
1 answer
111 views

I noticed unexpected behavior when importing a submodule with an alias in my package's __init__.py file. In short, using an alias in __init__.py still exposes the original submodule name in the ...
Amess's user avatar
  • 13
0 votes
1 answer
97 views

I want to incorporate an instabot in my code. I downloaded Instabot and installed it through the Windows' command prompt pip install -U instabot as Spyder didn't recognize my user: C:\Users\(My Name) ...
lynou-cats's user avatar
-1 votes
1 answer
79 views

I recently came to know that modules like os are imported way before a user python program starts running and therfore we cannot import a custom file named os even though it's not in the sys....
Dhruv's user avatar
  • 597
1 vote
1 answer
116 views

I was reading through the python docs for how import is resolved and found this ... the interpreter first searches for a built-in module with that name. These module names are listed in sys....
Dhruv's user avatar
  • 597
2 votes
2 answers
83 views

I am trying to create an executable from a Python file using auto-py-to-exe. My code is set up as two .py files. I have a top level code which I will call main.py, and a secondary code with my ...
Kenton Supplee's user avatar
0 votes
0 answers
56 views

I'm writing a resource mining game at the moment, and I want players to be able to easily add "expansions" to the game which add on more resources or mechanics. I have a structure that looks ...
DeadlySloth's user avatar
2 votes
2 answers
87 views

I need to test that specific imports of my library don't import along some other heavy modules (e.g. tensorflow - we'll use it in this question). Here's a detailed description: The test should run ...
noamgot's user avatar
  • 4,161
1 vote
2 answers
117 views

I am writing a QGIS plugin. During early development, I wrote and tested the Qt GUI application independently of QGIS. I made use of absolute imports, and everything worked fine. Then, I had to adapt ...
skytwosea's user avatar
  • 409
0 votes
0 answers
42 views

I have a Python package with a directory that looks like this: -root | |-src | | | -app | | | |-__init__.py | |-__main__.py | |-file1.py | |-file2.py | |-tests | |-__init__....
RoyalSwish's user avatar
  • 1,583
-1 votes
1 answer
82 views

I have this entry point: # main.py from 022 import * print("Hello from main.py") I have 022.py also. It is: print("Hello World") When I run main.py I get this error: File &...
nicomp's user avatar
  • 4,741
-3 votes
1 answer
109 views

Here is my error: although I installed pytwain and it is located in C:\Users\User\Documents\systhen\myenv310\Lib, I tried working with several Python versions (3.13, 3.12, 3.10, 3.9), but the same ...
the bignner's user avatar
0 votes
1 answer
195 views

I have the following folder structure in python: my_project/ ├── Dockerfile ├── Makefile ├── run.py ├── data/ │ ├── raw/ │ └── processed/ └── src/ ├── __init__.py ├── config.py ├── ...
vossi's user avatar
  • 143
1 vote
1 answer
62 views

I have David Eppstein's PADS library of Python Algorithms and Data Structures in a subdirectory next to my Python script: - my-script.py - PADS - __init__.py - Automata.py - Util.py - ....
user200783's user avatar
  • 14.5k
0 votes
1 answer
40 views

I have a Python project with the following structure: ├── main.py ├── pack1 │ ├── __init__.py │ ├── mod1 │ │ ├── __init__.py │ │ └── request.py │ ├── mod1.py │ └── mod2.py The content ...
Wayne Hong's user avatar
5 votes
1 answer
6k views

I entered the command: $ mypy mypycode.py Then I run the following code in mypycode.py: from mypyc.build import mypycify from setuptools import setup from timeit import timeit import math setup( ...
Mr. W's user avatar
  • 275
4 votes
0 answers
38 views

I'm trying to get GridDB working on my WSL/Ubuntu environment. I have followed https://pypi.org/project/griddb-python/ to install griddb and was successful but when trying to import the module I'm ...
Luke Summerville's user avatar
17 votes
4 answers
47k views

I'm trying to work with VideoFileClip and vfx functions from the Moviepy library but my interpreter keeps throwing a 'ModuleNotFoundError: No module named 'moviepy.editor''. I've installed and ...
Arushi Sachan's user avatar

1
2 3 4 5
122