- Trending Categories
- Data Structure
- Operating System
- C Programming
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to create python namespace packages in Python 3?
In Python, a namespace package allows you to spread Python code among several projects. This is useful when you want to release related libraries as separate downloads. For example, with the directories Package-1 and Package-2 in PYTHONPATH,
Package-1/namespace/__init__.py Package-1/namespace/module1/__init__.py Package-2/namespace/__init__.py Package-2/namespace/module2/__init__.py the end-user can import namespace.module1 and import namespace.module2.
On Python 3.3, you don't have to do anything, just don't put any __init__.py in your namespace package directories and it will just work. This is because Python 3.3 introduces implicit namespace packages.
On older versions, there's a standard module, called pkgutil, with which you can 'append' modules to a given namespace. You should put those two lines in both Packages.
1/namespace/__init__.py and Package-2/namespace/__init__.py: from pkgutil import extend_path __path__ = extend_path(__path__, __name__)
This will add to the package's __path__ all subdirectories of directories on sys.path named after the package. After this you can distribute the 2 packages separately.
- How do I create a Python namespace?
- How do I create a namespace package in Python?
- Packages in Python
- Difference between namespace in C# and packages in Java
- How to develop programs with Python Namespaced Packages?
- What is a namespace in Python?
- Add packages to Anaconda environment in Python
- How to import everything from a python namespace / package?
- How to create a borderless fullscreen application using Python-3 Tkinter?
- What are the packages in Python?
- How to organize Python classes in modules and/or packages
- Capacity To Ship Packages Within D Days in Python
- How can Matplotlib be used to create 3 dimensional contour plot using Python?
- Base 3 to integer in Python
- How does == operator works in Python 3?