Changing script's search path at install time

Ben Finney ben+python at benfinney.id.au
Fri Dec 19 23:30:57 EST 2014


Dave Angel <davea at davea.name> writes:

> On 12/19/2014 05:51 PM, Mitko Haralanov wrote:
> > However, when the app gets installed, I would like to install the
> > modules to /usr/lib64/pythonX.Y/site-packages/myapp. I know that I
> > can do this by using the "package_dir" argument to the "setup()"
> > function in distutils.core.
> >
> > To make development easier I would like to be able to run the
> > myapp.py script from the development directory,
>
> Nonsense. It should have the same structure on your machine as your
> customer will have. So move the modules to where they're really going
> to be installed, and correct the imports until it tests correct.

To clarify: the application should install its files into a directory
tree, with the same *relative* structure on your machine as on the
customer's machine.

(More complex setups are reasonable, too; operating systems can manage
where executable versus documentation versus library versus static data
files etc. should go, meaning the locations will be different on
different machines. But that's probably not needed in this case.)

> > The issue is that when the script is installed, the import
> > statements will not work anymore since the directory name has been
> > changed from "modules" to "myapp".

In that case, ensure the deployment (whether for testing on your own
machine, or onto a production machine) goes to a directory with the same
top-level Python package name.

> > Does anyone have any useful hints?
>
> Yes, develop in the same environment as the customer is going to run.

One point to note: there's no issue having the *development* working
tree different for convenience of editing and VCS management, etc.

But for running the program &-N even for testing &-N you should set up
an automated one-command deployment that compiles, builds, copies,
deployed, etc. anything it needs to, to run whatever it is you've just
edited.

Just because Python code can be runn immediately, that doesn't remove
the need for a separate build step to go from “tree of files I'm editing
and managing in VCS”, to “tree of files in a different location ready to
run”.

-- 
 \       “Some people have a problem, and they think “I know, I'll use |
  `\     Perl!”. Now they have some number of problems but they're not |
_o__)     sure whether it's a string or an integer.” —Benno Rice, 2011 |
Ben Finney




More information about the Python-list mailing list