Top "Python-import" questions

For questions about importing modules in Python

Relative imports in Python 3

I want to import a function from another file in the same directory. Sometimes it works for me with from .…

python python-3.x python-import
How to fix "Attempted relative import in non-package" even with __init__.py

I'm trying to follow PEP 328, with the following directory structure: pkg/ __init__.py components/ core.py __init__.py tests/ core_…

python package python-import importerror init
Import a file from a subdirectory?

I have a file called tester.py, located on /project. /project has a subdirectory called lib, with a file called …

python module subdirectory python-import
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 …

python python-3.x package python-import relative-import
`from ... import` vs `import .`

I'm wondering if there's any difference between the code fragment from urllib import request and the fragment import urllib.request …

python import syntax module python-import
How to do relative imports in Python?

Imagine this directory structure: app/ __init__.py sub1/ __init__.py mod1.py sub2/ __init__.py mod2.py I'm coding mod1, …

python python-import python-module
How to import a module given its name as string?

I'm writing a Python application that takes as a command as an argument, for example: $ python myapp.py command1 I …

python python-import
django import error - No module named core.management

Ok, I see plenty of these errors around. I have tried everything I know to do and have yet to …

python django python-import pythonpath
adding directory to sys.path /PYTHONPATH

I am trying to import a module from a particular directory. The problem is that if I use sys.path.…

python mechanize python-import pythonpath
How to load all modules in a folder?

Could someone provide me with a good way of importing a whole directory of modules? I have a structure like …

python python-import