faq.rst 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. FAQs
  2. ====
  3. Building on other platforms
  4. ---------------------------
  5. NSIS can run on Linux, so you can build Windows installers without running
  6. Windows. However, if your package relies on compiled extension modules, like
  7. PyQt4, lxml or numpy, you'll need to ensure that the installer is built with
  8. Windows versions of these packages. There are two ways to do this:
  9. - Get the importable packages/modules, either from a Windows installation, or
  10. by extracting them from an installer. Copy them into a folder called
  11. ``pynsist_pkgs``, next to your ``installer.cfg`` file. pynsist will
  12. copy everything in this folder to the build directory.
  13. - Include exe/msi installers for those modules, and modify the ``.nsi`` template
  14. to extract and run these during installation. This can make your installer
  15. bigger and slower, and it may create unwanted start menu shortcuts
  16. (e.g. PyQt4 does), so the first option is usually better. However, if the
  17. installer sets up other things on the system, you may need to do this.
  18. When running on non-Windows systems, pynsis will bundle a 32-bit version of
  19. Python by default, though you can override this :ref:`in the config file <cfg_python>`.
  20. Whichever method you use, compiled libraries must have the same bit-ness as
  21. the version of Python that's installed.
  22. Using data files
  23. ----------------
  24. Applications often need data files along with their code. The easiest way to use
  25. data files with Pynsist is to store them in a Python package (a directory with
  26. a ``__init__.py`` file) you're creating for your application. They will be
  27. copied automatically, and modules in that package can locate them using
  28. ``__file__`` like this::
  29. data_file_path = os.path.join(os.path.dirname(__file__), 'file.dat')
  30. If you don't want to put data files inside a Python package, you will need to
  31. list them in the ``files`` key of the ``[Include]`` section of the config file.
  32. Your code can find them relative to the location of the launch script running your
  33. application (``sys.modules['__main__'].__file__``).
  34. .. note::
  35. The techniques above work for fixed data files which you ship with your
  36. application. For files which your app will *write*, you should use another
  37. location, because an app installed systemwide cannot write files in its
  38. install directory. Use the ``APPDATA`` or ``LOCALAPPDATA`` environment
  39. variables as locations to write hidden data files (`what's the difference?
  40. <https://superuser.com/a/21462/209976>`__)::
  41. writable_file = os.path.join(os.environ['LOCALAPPDATA'], 'MyApp', 'file.dat')
  42. Code signing
  43. ------------
  44. People trying to use your installer will see an 'Unknown publisher' warning.
  45. To avoid this, you can sign it with a digital certificate. See
  46. `Mozilla's instructions on signing executables using Mono
  47. <https://developer.mozilla.org/en-US/docs/Signing_an_executable_with_Authenticode>`__.
  48. Signing requires a certificate from a trusted provider. These typically cost
  49. hundreds of dollars, but Certum `offers a certificate
  50. <https://www.certum.eu/certum/cert,offer_en_open_source_cs.xml>`__ for open
  51. source projects for €14 at the time of writing. You will need documents to prove
  52. your identity. I haven't used a Certum certificate, and this isn't an
  53. endorsement.
  54. Alternatives
  55. ------------
  56. Other ways to distribute applications to users without Python installed include
  57. freeze tools, like `cx_Freeze <http://cx-freeze.sourceforge.net/>`_ and
  58. `PyInstaller <http://www.pyinstaller.org/>`_, and Python compilers like
  59. `Nuitka <http://nuitka.net/>`_.
  60. pynsist has some advantages:
  61. * Python code often does things—like using ``__file__`` to find its
  62. location on disk, or :data:`sys.executable` to launch Python processes—which
  63. don't work when it's run from a frozen exe. pynsist just installs Python files,
  64. so it avoids all these problems.
  65. * It's quite easy to make Windows installers on other platforms, which is
  66. difficult with other tools.
  67. * The tool itself is simpler to understand, and less likely to need updating for
  68. new Python versions.
  69. And some disadvantages:
  70. * Installers tend to be bigger because you're bundling the whole Python standard
  71. library.
  72. * You don't get an exe for your application, just a start menu shortcut to launch
  73. it.
  74. * pynsist only makes Windows installers.
  75. Popular freeze tools also try to automatically detect what packages you're using.
  76. Pynsist could do the same thing, but in my experience, this detection is complex and often
  77. misses things, so for now it expects an explicit list of the packages
  78. your application needs.
  79. Another alternative is `conda constructor <https://github.com/conda/constructor>`__,
  80. which builds an installer out of conda packages. Conda packages are more
  81. flexible than PyPI packages, and many libraries are already packaged, but you
  82. have to make a conda package of your own code as well before using conda
  83. constructor to make an installer.
  84. Conda constructor can also make Linux and Mac installers, but unlike Pynsist, it
  85. can't make a Windows installer from Linux or Mac.