Relative imports – ModuleNotFoundError: No module named x
This is the first time I’ve really sat down and tried python 3, and seem to be failing miserably. I have the following two files:
This is the first time I’ve really sat down and tried python 3, and seem to be failing miserably. I have the following two files:
Sometimes I download the python source code from github and don’t know how to install all the dependencies. If there is no requirements.txt file I have to create it by hands.
The question is:
Given the python source code directory is it possible to create requirements.txt automatically from the import section?
How can I know if a Python module exists, without importing it?
If a large module is loaded by some submodule of your code, is there any benefit to referencing the module from that namespace instead of importing it again?
I want to inherit from a class in a file that lies in a directory above the current one.
Module A includes import B at its top. However under test conditions I’d like to mock B in A (mock A.B) and completely refrain from importing B.
I’m wondering about the preferred way to import packages in a Python application. I have a package structure like this:
Another developer and I disagree about whether PYTHONPATH or sys.path should be used to allow Python to find a Python package in a user (e.g., development) directory.
I have a module that conflicts with a built-in module. For example, a myapp.email module defined in myapp/email.py.
Is there a straightforward way to find all the modules that are part of a python package? I’ve found this old discussion, which is not really conclusive, but I’d love to have a definite answer before I roll out my own solution based on os.listdir().