Skip to content
Advertisement

Tag: module

How to resolve mutual dependencies between a main script and submodules needing access to a global variable from the script?

I’m building a Typer app with lots of commands. I want to categorize the commands into subfiles but am unsure how to resolve the dependencies. main.py is the parent. It looks like this: So, we make a new Typer app and import everything from the submodules. Simple enough. Each of the submodules contains Typer commands, like booklist: Here’s the problem:

What is the correct way to import this class?

I have the following repository structure: In moduleB.py I need to import MyClass, I use the following command: When I run the main() function in moduleB.py I have the following error: ModuleNotFoundError: No module named ‘directoryA’ I run the moduleB.py from directoryB in the following way: How could I fix this problem? Answer The best you can do to organizing

How to install NetCDF4 module in Spyder?

I don’t know why this is causing me so much headache. I know how to use pip, and have the latest version, but still when running a script in Spyder that requires netCDF4 (import netCDF4) Spyder always returns: I opened cmd, pip install netCDF4, confirmed it installed OK. Shouldn’t this be enough? I manually copied a downloaded version of netCDF4,

Imported package searches for modules in my code

Can someone explain me what is going on here and how to prevent this? I have a main.py with the following code: I outsourced some functions into a module named utils.py: When I run this I get the following output: So it seems like the torch package I imported has also a utils resource (package) and searches for a module

Importing module on python / jupyter

I made very simple test.py -file and I want to use it as module: When I run another notebook and try to import it, the import is “succesful”. However, when I run my code it comes back: I can by-pass this by editing my code: and then it will work. I do not quite understand why I can’t run the

Jupyter notebook cannot find module

I’m trying to load a module called folium into my Jupyter Notebook environment. When I attempt to load this module, a ModuleNotFoundError is returned. When I run !pip list in the same Jupyter Notebook environment, folium is listed amongst my installed modules. How do I successfully load this module? Answer Could it be that you expect a certain Python installation

Scrapy can’t find items

I am currently still learning Scrapy and trying to work with pipelines and ItemLoader. However, I currently have the problem that the spider shows that Item.py does not exist. What exactly am I doing wrong and why am I not getting any data from the spider into my pipeline? Running the Spider without importing the items works fine. The Pipeline

Advertisement