faq.rst 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. FAQs
  2. ====
  3. Building on other platforms
  4. ---------------------------
  5. You can use Pynsist to build Windows installers from a Linux or Mac system.
  6. You'll need to install NSIS so that the ``makensis`` command is available.
  7. Here's how to do that on some common platforms:
  8. * Debian/Ubuntu: ``sudo apt-get install nsis``
  9. * Fedora: ``sudo dnf install mingw32-nsis``
  10. * Mac with `Homebrew <https://brew.sh/>`__: ``brew install makensis``
  11. Installing Pynsist itself is the same on all platforms::
  12. pip install pynsist
  13. If your package relies on compiled extension modules, like
  14. PyQt4, lxml or numpy, you'll need to ensure that the installer is built with
  15. Windows versions of these packages. There are a few options for this:
  16. - List them under ``pypi_wheels`` in the :ref:`Include section <cfg_include>`
  17. of your config file. Pynsist will download Windows-compatible wheels from
  18. PyPI. This is the easiest option if the dependency publishes wheels.
  19. - Get the importable packages/modules, either from a Windows installation, or
  20. by extracting them from an installer. Copy them into a folder called
  21. ``pynsist_pkgs``, next to your ``installer.cfg`` file. Pynsist will
  22. copy everything in this folder to the build directory.
  23. - Include exe/msi installers for those modules, and modify the ``.nsi`` template
  24. to extract and run these during installation. This can make your installer
  25. bigger and slower, and it may create unwanted start menu shortcuts
  26. (e.g. PyQt4 does), so it's a last resort. However, if the
  27. installer sets up other things on the system, you may need to do this.
  28. When running on non-Windows systems, Pynsist will bundle a 32-bit version of
  29. Python by default, though you can override this :ref:`in the config file <cfg_python>`.
  30. Whichever method you use, compiled libraries must have the same bit-ness as
  31. the version of Python that's installed.
  32. Using data files
  33. ----------------
  34. Applications often need data files along with their code. The easiest way to use
  35. data files with Pynsist is to store them in a Python package (a directory with
  36. a ``__init__.py`` file) you're creating for your application. They will be
  37. copied automatically, and modules in that package can locate them using
  38. ``__file__`` like this::
  39. data_file_path = os.path.join(os.path.dirname(__file__), 'file.dat')
  40. If you don't want to put data files inside a Python package, you will need to
  41. list them in the ``files`` key of the ``[Include]`` section of the config file.
  42. Your code can find them relative to the location of the launch script running your
  43. application (``sys.modules['__main__'].__file__``).
  44. .. note::
  45. The techniques above work for fixed data files which you ship with your
  46. application. For files which your app will *write*, you should use another
  47. location, because an app installed systemwide cannot write files in its
  48. install directory. Use the ``APPDATA`` or ``LOCALAPPDATA`` environment
  49. variables as locations to write hidden data files (`what's the difference?
  50. <https://superuser.com/a/21462/209976>`__)::
  51. writable_file = os.path.join(os.environ['LOCALAPPDATA'], 'MyApp', 'file.dat')
  52. Code signing
  53. ------------
  54. People trying to use your installer will see an 'Unknown publisher' warning.
  55. To avoid this, you can sign it with a digital certificate. See
  56. `Mozilla's instructions on signing executables using Mono
  57. <https://developer.mozilla.org/en-US/docs/Mozilla/Developer_guide/Build_Instructions/Signing_an_executable_with_Authenticode>`__.
  58. Signing requires a certificate from a provider trusted by Microsoft.
  59. As of summer 2017, these are the cheapest options I can find:
  60. * Certum's `open source code signing certificate <https://www.certum.eu/certum/cert,offer_en_open_source_cs.xml>`__:
  61. €86 for a certificate with a smart card and reader, €28 for a new certificate
  62. if you have the hardware. Each certificate is valid for one year.
  63. This is only for open source software.
  64. * Many companies resell Comodo code signing certificates at prices lower than
  65. Comodo themselves, especially if you pay for 3–4 years up front.
  66. `CodeSignCert <https://codesigncert.com/comodocodesigning>`__ ($59–75 per year),
  67. `K Software <http://codesigning.ksoftware.net/>`__ ($67–$84 per year) and
  68. `Cheap SSL Security <https://cheapsslsecurity.co.uk/comodo/codesigningcertificate.html>`__ (UK, £54–£64 per year)
  69. are a few examples; a search will turn up many more like them.
  70. I haven't used any of these companies, so I'm not making a recommendation.
  71. Please do your own research before buying from them.
  72. If you find another good way to get a code signing certificate, please make a
  73. pull request to add it!
  74. Alternatives
  75. ------------
  76. Other ways to distribute applications to users without Python installed include
  77. freeze tools, like `cx_Freeze <http://cx-freeze.sourceforge.net/>`_ and
  78. `PyInstaller <http://www.pyinstaller.org/>`_, and Python compilers like
  79. `Nuitka <http://nuitka.net/>`_.
  80. pynsist has some advantages:
  81. * Python code often does things—like using ``__file__`` to find its
  82. location on disk, or :data:`sys.executable` to launch Python processes—which
  83. don't work when it's run from a frozen exe. pynsist just installs Python files,
  84. so it avoids all these problems.
  85. * It's quite easy to make Windows installers on other platforms, which is
  86. difficult with other tools.
  87. * The tool itself is simpler to understand, and less likely to need updating for
  88. new Python versions.
  89. And some disadvantages:
  90. * Installers tend to be bigger because you're bundling the whole Python standard
  91. library.
  92. * You don't get an exe for your application, just a start menu shortcut to launch
  93. it.
  94. * pynsist only makes Windows installers.
  95. Popular freeze tools also try to automatically detect what packages you're using.
  96. Pynsist could do the same thing, but in my experience, this detection is complex and often
  97. misses things, so for now it expects an explicit list of the packages
  98. your application needs.
  99. Another alternative is `conda constructor <https://github.com/conda/constructor>`__,
  100. which builds an installer out of conda packages. Conda packages are more
  101. flexible than PyPI packages, and many libraries are already packaged, but you
  102. have to make a conda package of your own code as well before using conda
  103. constructor to make an installer.
  104. Conda constructor can also make Linux and Mac installers, but unlike Pynsist, it
  105. can't make a Windows installer from Linux or Mac.