Skip to content
Advertisement

Tag: import

Django Standalone Script in Django 4.1

I am trying to run a standalone script in django 4.1. I have the setup as suggested in this post at the top of my file: Django Standalone Script However, on the 4th line, I get the following error: ModuleNotFoundError: No module named ‘sport_api’ This is my INSTALLED_APPS in settings.py How do I get around this error? Update: Answer You

Is it possible to import a folder as a module?

I have a library I’m working on that is intended to be imported like import raycekar as rk and have its individual files referenced as rk.unit.whatever. This is the directory structure: From within main.py, if I from raycekar import ui, I can access ui. If I want to import raycekar as rk, rk.ui raises an AttributeError unless the from a

Resource punkt not found. Please use the NLTK Downloader to obtain the resource: >>> import nltk >>> nltk.download(‘punkt’)

I have NLTK installed and it is going me error Resource punkt not found. Please use the NLTK Downloader to obtain the resource: import nltk nltk.download(‘punkt’) For more information see: https://www.nltk.org/data.html Attempted to load tokenizers/punkt/PY3/english.pickle Searched in: – ‘/Users/divyanshundley/nltk_data’ – ‘/Library/Frameworks/Python.framework/Versions/3.10/nltk_data’ – ‘/Library/Frameworks/Python.framework/Versions/3.10/share/nltk_data’ – ‘/Library/Frameworks/Python.framework/Versions/3.10/lib/nltk_data’ – ‘/usr/share/nltk_data’ – ‘/usr/local/share/nltk_data’ – ‘/usr/lib/nltk_data’ – ‘/usr/local/lib/nltk_data’ – ” and my code is Answer

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

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

Import a single file from another directory

I’m kind of new with python and there is something troubling me. I’m using pandas to read an excel file. All works well if I have the excel in the same directory as my .py file. What I want to know is what is the best way to get a file that is in a completely different path. I’ve searched

Advertisement