Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #48402

Re: Imports (in Py3), please help a novice

Newsgroups comp.lang.python
Date 2013-06-15 19:50 -0700
References <25416834-33d5-44ea-b70f-5dde80ad718f@googlegroups.com>
Message-ID <261a140a-d527-45b6-8ee4-eeb6695086a6@googlegroups.com> (permalink)
Subject Re: Imports (in Py3), please help a novice
From John Ladasky <john_ladasky@sbcglobal.net>

Show all headers | View raw


Followup to my own post:

I am sticking pretty closely to this example from Mike Driscoll which, admittedly, is based on Python 2.6:

http://www.blog.pythonlibrary.org/2012/07/08/python-201-creating-modules-and-packages/

I'm trying to do this one step at a time.  First try a local import, then install the module.

When I execute ./foo/__init__.py directly, from within its own directory, all the import statements work.  Suppose that one of those import statements reads, "from bar import baz".  And, suppose that there are others, which refer to other names we want to import from other files.

Next, I execute another program from the parent directory of foo which says "from foo import bar".  It finds ./foo/__init__.py.  But when it tries to execute "from bar import baz", an ImportError is raised.  That strikes me as odd.  Since the foo directory is clearly already found, why isn't foo (at least, temporarily) searched for modules?

Now, Mike suggests that, once you have built up the desired file hierarchy, "you can copy the folder into your Python’s site-packages folder."  Really?  The safe, recommended way to do this is to use distutils.  Five years ago, I did it the same way that Mike shows.  

http://www.gossamer-threads.com/lists/python/python/653838

Windows would let you cheat that way, if you had admin privileges.  Linux stopped you, and made you use sudo.  That red flag is what made me ask what the recommended method of installing to site-packages was, and got me started with distutils.

So, why don't I just do that now?  As my first post indicated, I have tried.  There must be something wrong with the setup.py files I have written.  I keep getting files installed in places I don't want them to be.

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Imports (in Py3), please help a novice John Ladasky <john_ladasky@sbcglobal.net> - 2013-06-15 17:53 -0700
  Re: Imports (in Py3), please help a novice John Ladasky <john_ladasky@sbcglobal.net> - 2013-06-15 19:50 -0700
  Re: Imports (in Py3), please help a novice Miki Tebeka <miki.tebeka@gmail.com> - 2013-06-16 07:50 -0700
    Re: Imports (in Py3), please help a novice John Ladasky <john_ladasky@sbcglobal.net> - 2013-06-16 11:46 -0700
      Re: Imports (in Py3), please help a novice Chris Angelico <rosuav@gmail.com> - 2013-06-17 11:56 +1000

csiph-web