How is it possible build multiple python modules sharing the same namespace compatible for Python 2.7+ and 3.3+?
Let's call the namespace test. Now I want to have two seperate modules called test.foo and another one called test.bar. However, I'm currently developing test.helloworld which depends on both, test.foo and test.bar. Both are listed in the requirements.txt file.
The modules test.foo and test.bar are currently using the Python 2 solution for namespace packages:
import pkg_resources pkg_resources.declare_namespace(__name__) Running the suggested pip-command for development mode pip install -e . turns into: ImportError: No module named 'test.helloworld' while importing test.foo or test.bar is working.
The Python 3 solution for namespace packages are Implicit Namespace Packages where the namespace package has no __init__.py file. This is sadly not working for Python 2 versions.
How can I design a solution for both Python 2 and 3 (which allows me to use pip install -e .)? The --egg solution does not work for me since it is already deprecated.
What is Python 2? Python 2 made code development process easier than earlier versions. It implemented technical details of Python Enhancement Proposal (PEP). Python 2.7 (last version in 2. x ) is no longer under development and in 2020 will be discontinued.
Python 3 is definitely more readable, easier to grasp, and popular than Python 2. Python 2 has definitely run out of steam and one should learn Python 2 if and only if some legacy code has been written in Python 2 or if a company needs the developer to migrate the Python 2 code into Python 3.
We have decided that January 1, 2020, was the day that we sunset Python 2. That means that we will not improve it anymore after that day, even if someone finds a security problem in it.
The final version of Python 2.0 is available for download now.
I recently had a similar issue, where I had to install a package for Python 2 and 3. I ended up having to download the code from GitHub, then ran the setup.py by calling
sudo python setup.py install
and
sudo python3 setup.py install
This results in the package being installed for both Python 2 and 3, even though the code itself was meant for Python 2. This allows me to work with the package whether I use Python 2 or 3, without any namespace conflicts.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With