import

How do you import a nested package via string?

How do you import a nested package via string? Question: I’m trying to dynamically import a package which is a subdirectory of another package. Though there is no documentation about it, this doesn’t seem to be possible with importlib. Example: Start with pip install pytest then, import importlib mod = importlib.import_module("pytester", package="_pytest") fails with ModuleNotFoundError: …

Total answers: 1

My python module does not see other modules

My python module does not see other modules Question: I have a folder with 2 files. import_test.py main.py. Here is content of import_test.py: def some_function(): df = pd.DataFrame({‘col_1’: [1,2,3], ‘col_2’: [1,2,3]}) return df Here is content of main.py: import import_test import pandas as pd import importlib importlib.reload(import_test) import_test.some_function() When I execute import_test.some_function(), I get back …

Total answers: 2

How can I tell which module/script has just run this script in Python?

How can I tell which module/script has just run this script in Python? Question: I have a module called detector.py, and I want to import the module Vimba into it only if detector.py is being imported by experiment.py. Is this importer-specific conditional importing possible? If I import this module (detector.py) into a different module, say …

Total answers: 1

Why does importing from random in python give me back unused import statement?

Why does importing from random in python give me back unused import statement? Question: When I type for ex: from random import shuffle I get: Unused import statement ‘from random import shuffle’ in return and the letter go grey. Can anybody diagnose? I tried "from random import shuffle" and was expecting to be able to …

Total answers: 1

Python; Cant import module from other directory

Python; Cant import module from other directory Question: I am trying to decompose my program on python. I have read a lot of information and other answers about how import works, but still cant understand how exactly. I want to use my module Graph.Graph2D for implementation in InteractiveGraph2D. Before importing it, I add path to …

Total answers: 3

No module names 'src' when importing from parent folder in jupyter notebook

No module names 'src' when importing from parent folder in jupyter notebook Question: I have the following folder structure in my project my_project notebook |– some_notebook.ipynb src |– preprocess |– __init__.py |– some_processing.py __init__.py Now, inside some_notebook.ipynb I simply want to get the methods from some_processing.py. Now we I run from src.preprocess import some_processing from …

Total answers: 2

Calling pip package files from within pip package? (`No module named 'src.snnalgorithms'`)

Calling pip package files from within pip package? (`No module named 'src.snnalgorithms'`) Question: Whilst in some_other_package, I am importing files from the snnalgorithms pip package. I received the error: No module named ‘src.snnalgorithms’. This is a valid error because that src.snnalgorithms file does not exist in the some_other_package project from which I was calling the …

Total answers: 1

How do I use an instance of a class in another file in another class?

How do I use an instance of a class in another file in another class? Question: inside main.py file from Level_Class import Level from Player_Class import Player level = Level(level_map) inside Level_Class.py file class Level: def __init__(self, map): self.tile_list = [] for row_index, row in enumerate(map): for col_index, col in enumerate(row): # print(row_index, col_index, col) …

Total answers: 1