[x3d-public] x3d.py pip packake problems and potential solution

Andreas Plesch andreasplesch at gmail.com
Thu Apr 23 07:00:50 PDT 2020


Importing the x3d.py module from the x3d.py file works (if the x3d.py
file is in te python path).

For convenience, there is also x3d python package (pip) which is
available from the pip registry and can be installed by:

pip install x3d

to the system python modules.

However, this does not quite work:

$ pip install x3d
Collecting x3d
  Downloading https://files.pythonhosted.org/packages/3b/4b/2a7cb8f738e5bf03beb729989fc1c0f52a86ddf61ea3fb38c61c55afd41b/x3d-0.0.26-py3-none-any.whl
(204kB)
     |████████████████████████████████| 204kB 5.6MB/s
Installing collected packages: x3d
Successfully installed x3d-0.0.26
jovyan at jupyter-gesiscss-2dnotebo-2dgetting-5fstarted-2d7wbaxlkp:~$ python
Python 3.7.3 | packaged by conda-forge | (default, Jul  1 2019, 21:52:21)
[GCC 7.3.0] :: Anaconda, Inc. on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import x3d
>>> x3d.X3D()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: module 'x3d' has no attribute 'X3D'

I think what is needed is to actually import the module in the
__init__.py file for the pip package.

# __init__.py needed for properly configuring pypi distribution of
x3d.py package

# According to _Learning Python_ by Mark Lutz, fifth edition:
# - Empty __init.py__ no longer required as of Python 3.3.  p. 761
# - Using __init.py__ is performance advantage for loading, even when
empty.  p. 761
# - Using __all__ list to define exported values for import * is
allowed but not required.  p. 735 and 771-772.

# 6.4.1. Importing * From a Package
# https://docs.python.org/3/tutorial/modules.html#importing-from-a-package

# indicates that
#     from packagename import *
# "then imports whatever names are defined in the package" and
# "Although certain modules are designed to export only names that
follow certain patterns when you use import *,
#     it is still considered bad practice in production code."

# TODO testing continues to fix x3d.py package's class visibility
satisfactorily for end users

## import the x3d.py module
from x3d import *

__all__ = [
    # Field types

With that change in the __init__.py file, the pip package works for me:

$ python
Python 3.7.6 | packaged by conda-forge | (default, Jan  7 2020, 22:33:48)
[GCC 7.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import x3d
x3d.py package loaded, have fun with X3D Graphics!
>>> x3d.X3D
<class 'x3d.X3D'>
>>> x3d.Box().toXML()
'<Box/>\n'
>>>

Perhaps this change could be applied to the next release of the x3d
pip package. I could not find the __init__.py file on sourceforge.

Cheers,

-Andreas
-- 
Andreas Plesch
Waltham, MA 02453



More information about the x3d-public mailing list