OpenOpt install

Robert Kern robert.kern at gmail.com
Tue Dec 18 03:53:07 EST 2007


dmitrey wrote:
> When earlier OpenOpt versions had been installed there were no
> compiled pyc-files (in destination directory). I called to mailing
> list but no obvious receipt had been achieved. Matthieu had done some
> changes but it yielded other mistakes (no some py-files detected or
> kind of), so I had removed those changes and write my own, for to have
> OO py-files being compiled when installed, because next time when they
> will be run user may not have root permissions, so he will recompile
> source files each time OO starts.

Well, the problem there is that you have put code into subdirectories that
aren't packages. Then you manually add the directories to sys.path when you
import scikits.openopt.oo . This is a bad thing to do for several reasons; one
reason is that you don't get the correct .pyc files.

You need to make the directory structure match the package structure. For
example, you currently have the module scikits.openopt.LP in
scikits/openopt/Kernel/LP/LP.py . You have two options:

  * you can make the directory structure match the package structure by moving
the files to the correct location:

    $ mv scikits/openopt/Kernel/LP/LP.py scikits/openopt/LP.py

  * you can make the package structure match the directory structure by adding
__init__.py files to the subdirectories and changing the imports to match:

    $ touch scikits/openopt/Kernel/__init__.py
    $ touch scikits/openopt/Kernel/LP/__init__.py
    $ vim scikits/openopt/oo.py
      # 1. Delete the sys.path munging.
      # 2. Change "from LP import LP as CLP" to "from Kernel.LP import LP as CLP"

-- 
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless enigma
 that is made terrible by our own mad attempt to interpret it as though it had
 an underlying truth."
  -- Umberto Eco




More information about the Python-list mailing list