Using modules from Debian "python3-..." packages with locally compiled Python 3.3

Edward C. Jones edcjones at comcast.net
Tue May 8 15:13:03 EDT 2012


I use up-to-date Debian testing (wheezy), amd64 architecture.  I downloaded,
compiled and installed Python 3.3.0 alpha 3 (from python.org) using
"altinstall".  Debian wheezy comes with python3.2 (and 2.6 and 2.7).  I
installed the Debian package "python3-bs4" (BeautifulSoup4 for Python3).
Note: Debian uses eggs.

Python3.3a3 cannot find module bs4. Python3.2 can find the module.  Here is
a session with Python 3.3:

 > python3.3
Python 3.3.0a3 (default, May  5 2012, 11:30:48)
[GCC 4.6.3] on linux
Type "help", "copyright", "credits" or "license" for more information.
 >>> import bs4
Traceback (most recent call last):
   File "<stdin>", line 1, in <module>
   File "<frozen importlib._bootstrap>", line 1012, in _find_and_load
ImportError: No module named 'bs4'
 >>>

Here is what I have tried:

1. Put bs4.pth in /usr/local/lib/python3.3/site-packages.  This file should
contain the line:
   /usr/lib/python3/dist-packages
This works.

2. At the start of each Python program using bs4:
      import sys
      sys.path.append('/usr/lib/python3/dist-packages')
      import bs4
This works.

3. In the Python 3.3 source code, do ".configure" then edit Modules/Setup to
contain
     SITEPATH=:/usr/lib/python3/dist-packages
Finish compiling and altinstalling python.  "import bs4" works.

The last is the best because I only have to do it once.

Next I tried numpy.  It is installed from Debian package "python3-numpy".
If I compile Python 3.3 _without_ the change in (3) above, I get:

 > python3.3
Python 3.3.0a3 (default, May  8 2012, 14:30:18)
[GCC 4.6.3] on linux
Type "help", "copyright", "credits" or "license" for more information.
 >>> import numpy
Traceback (most recent call last):
   File "<stdin>", line 1, in <module>
   File "<frozen importlib._bootstrap>", line 1012, in _find_and_load
ImportError: No module named 'numpy'
 >>>

which is not a surprise. If I compile and install Python 3.3 _with_ the
change in (3) above, I get:

 > python3.3
Python 3.3.0a3 (default, May  8 2012, 14:43:28)
[GCC 4.6.3] on linux
Type "help", "copyright", "credits" or "license" for more information.
 >>> import numpy
Traceback (most recent call last):
   File "<stdin>", line 1, in <module>
   File "<frozen importlib._bootstrap>", line 1015, in _find_and_load
   File "<frozen importlib._bootstrap>", line 634, in load_module
   File "<frozen importlib._bootstrap>", line 294, in
   module_for_loader_wrapper
   File "<frozen importlib._bootstrap>", line 522, in _load_module
   File "/usr/lib/python3/dist-packages/numpy/__init__.py", line 137, in
<module>
     from . import add_newdocs
ImportError: cannot import name add_newdocs
 >>>

"add_newdocs.py" is present in the numpy directory.

The "import numpy" works for the Debian python 3.2.

What is the problem?




More information about the Python-list mailing list