0

I've been learning python over the past couple of days from Head First Python.

I've reached a point where I have to build a distribution package of a module I've made, called nester, and install it on my system. After installing the module I have to import it into a script and use a function from the imported module.

When trying to import the module from any folder other than the one where I saved the original nester.py, I get the following error (which suggests to me the module wasn't installed correctly):

james@james-Inspiron-1764:~$ python3.3
Python 3.3.0 (default, Sep 29 2012, 17:14:58) 
[GCC 4.7.2] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import nester
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named 'nester'
Error in sys.excepthook:
Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/apport_python_hook.py", line 64, in apport_excepthook
    from apport.fileutils import likely_packaged, get_recent_crashes
  File "/usr/lib/python3/dist-packages/apport/__init__.py", line 4, in <module>
    from apport.report import Report
  File "/usr/lib/python3/dist-packages/apport/report.py", line 30, in <module>
    import apport.fileutils
  File "/usr/lib/python3/dist-packages/apport/fileutils.py", line 23, in <module>
    from apport.packaging_impl import impl as packaging
  File "/usr/lib/python3/dist-packages/apport/packaging_impl.py", line 20, in <module>
    import apt
  File "/usr/lib/python3/dist-packages/apt/__init__.py", line 21, in <module>
    import apt_pkg
ImportError: No module named 'apt_pkg'

Original exception was:
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named 'nester'
>>> 

This is how I've built and installed the module:

james@james-Inspiron-1764:~/python/headfirst/chapter2/nester$ python3.3 setup.py sdist
/usr/lib/python3.3/distutils/dist.py:257: UserWarning: Unknown distribution option: 'pymodules'
  warnings.warn(msg)
running sdist
running check
warning: sdist: manifest template 'MANIFEST.in' does not exist (using default file list)

warning: sdist: standard file not found: should have one of README, README.txt

writing manifest file 'MANIFEST'
creating nester_jc-1.4.0
making hard links in nester_jc-1.4.0...
hard linking setup.py -> nester_jc-1.4.0
Creating tar archive
removing 'nester_jc-1.4.0' (and everything under it)
james@james-Inspiron-1764:~/python/headfirst/chapter2/nester$ sudo python3.3 setup.py install
[sudo] password for james: 
/usr/lib/python3.3/distutils/dist.py:257: UserWarning: Unknown distribution option: 'pymodules'
  warnings.warn(msg)
running install
running build
running install_egg_info
Removing /usr/local/lib/python3.3/dist-packages/nester_jc-1.4.0.egg-info
Writing /usr/local/lib/python3.3/dist-packages/nester_jc-1.4.0.egg-info

I can successfully import nester if python is started from inside ~/python/headfirst/chapter2/nester, but not if I start from any other location. Is this a problem with the way I'm installing the module, or is it a problem with my python installation?

Erresen
  • 1,923
  • 1
  • 22
  • 41
  • does it help if you add something to sys.path? – User Apr 02 '13 at 11:12
  • Do you have your module in `/usr/local/lib/python3.3/dist-packages/`? – wRAR Apr 02 '13 at 12:02
  • the module itself isn't in `/usr/local/lib/python3.3/dist-packages/` but a file called nester_jc-1.4.0.egg-info. should the file nester.py be in here also? – Erresen Apr 02 '13 at 19:30

0 Answers0