Python Windows Installer with all dependencies? - python

I have a package in the PyPI repository. I include a Windows installer by running the following command to upload a new version, specifically the 'bdist_wininst':
python3 setup.py register sdist bdist_wininst upload
However, when a user runs the associated .exe file, it does not install Python 3 itself. Furthermore, even if Python 3 is installed, it will not install any associated dependencies.
What is the best way to create a windows installer that will install Python 3 if it is not installed, along with my package and its dependencies?
If that is not possible, what is the best way to create a windows installer that will install my package and its dependencies, assuming Python 3 is installed?
I'm on Ubuntu 12.04. If it's of any assistance, here is my setup.py:
from distutils.core import setup
import codecs
try:
codecs.lookup('mbcs')
except LookupError:
ascii = codecs.lookup('ascii')
func = lambda name, enc=ascii: {True: enc}.get(name=='mbcs')
codecs.register(func)
setup(
name='SIGACTor',
version='0.1.14dev',
description=open('README.txt').read(),
url='http://bitbucket.org/davidystephenson/sigactor',
author='David Y. Stephenson',
author_email='david#davidystephenson.com',
packages=['sigactor'],
license='Proprietary',
long_description=open('README.txt').read(),
install_requires=[
'beautifulsoup4',
'feedparser',
'python-dateutil',
'pyyaml'
],
)

You should definetely try out pynsist which can bundle Python with your packages and is based on well-established NSIS open-source installer:
https://pypi.python.org/pypi/pynsist
Anaconda team provides Constructor which is based on conda and NSIS again:
https://github.com/conda/constructor
Finally this approach using WinPython and most stable installer called InnoSetup:
http://cyrille.rossant.net/create-a-standalone-windows-installer-for-your-python-application/
But if your package is not a library but an application then you can bundle it (freeze) with Python and all dependencies, even compress it using pyinstaller:
http://www.pyinstaller.org
This is what I use for all of my apps even with crazy interop dependencies!
Bonus - auto update tool for pyinstaller:
https://github.com/JMSwag/PyUpdater

Related

Creating a Python module with its dependencies self contained

When creating a Python module, you can specify dependencies of your module by using the install_requires List.
Lets look at this basic example.
setup(name='some_module',
version='0.0.1',
packages=find_packages(),
install_requires=[
'requests==2.21.0'
])
I package my module python3 setup.py sdist and upload it to a package repository.
But when I go to install pip3 install some_module==0.0.1 it will install requests==2.21.0 globally in my python3 site-packages/.
To my question, how do I get similar functionality to npm, with nested node_modules/ where my Python module would have its own site-packages/ and it would reference its local version of requests instead of overwriting my global version.
Thanks!
I would consider using PyInstaller for this task!
Directly from the Pyinstaller's documentation:
PyInstaller bundles a Python application and all its dependencies into a single package. The user can run the packaged app without installing a Python interpreter or any modules. PyInstaller supports Python 2.7 and Python 3.4+, and correctly bundles the major Python packages such as numpy, PyQt, Django, wxPython, and others.
You can install it with a simple pip install:
pip install PyInstaller
For a more detailed tutorial check out this link
Hopefully that helps!

Install Python module paramiko on windows

I have been trying to install paramiko module on windows without success. I have been getting errors related to Visual C++ compiler missing. Is it possible to install paramiko without having to go through compile process.
Based on the method from this question this is what I would suggest (assuming you already have >=python-2.7.9 installed, if not, upgrade, 2.7.9 comes with pip, pre 2.7.9 doesn't):
Get the appropriate pycrypto whl file (based on python version and win32/win_amd64). I've found some available here (can't vouch for the site as I don't use python on windows much).
Run pip install pycrypto-stuff.whl (in a command prompt window in the directory where you've saved the pycrypto whl file).
Run pip install paramiko (in a command prompt, but can be in w/e folder you like).
That should do the trick. In general a simple pip install package_name would work, but pycrypto does not provide a wheel file (binary package), therefore you have to build it. By the sound of it you don't have Visual C++ installed (or not the right version, it only works for one, I don't recall which), pycrypto needs an extension package built to use the system crypto libraries, which is why the source package isn't working.
I was able to get it working by installing the following packages using pip.
pip install bcrypt cryptography pynacl paramiko
These were the packages my Linux install used as prerequisites, so they should work on windows as well.

Windows installer for Python module which includes dependencies

I have a python module with an entry point in its setup.py which points to __ main__.py. I want to be able to distribute this module to my coworkers in such a way that they can install it using a windows installer, and execute the entry point from the command line. They already have Python installed on their computer.
The built-in python setup.py bdist_wininst functionality looked perfect, except that my module has a third party module dependency, and for some reason, bdist_wininst does not install dependencies even if they are specified in the setup's install_requires.
All-in-one windows exe solutions such as py2exe or pyinstaller are not suitable since the entry point requires input, and I want the user to be able to specify the input via the command line.
Of course, I could distribute the module source files and have my coworkers run python setup.py install, but they will be too afraid - they are not programmers.
Yes, it would be possible to use an application like Nullsoft NSIS to build an installer that would install your python package, but it will require more code and an extra build step.
Do your coworkers have pip and setuptools installed? Are you able to distribute your package on pypi? If so, it would be really simple for your coworkers to just do pip install mypackage. It has the added benefit of handling dependencies and if you use python wheels, your users don't require a build environment to install your package.

Use Python without installing

I have an installer which uses a Python script to install several components. I do not want to install Python on the users computer if they do not already have it and I also do not want having Python installed to be a prerequisite for using my installer. Is there a way of downloading Python without using the installer and just running it from a directory which can be easily removed after the installation is complete?
Portable Python is an easy tool to use on Windows. If you want to create .exe programs use PyInstaller to compile them. They can both work on top of each other, you can compile (make .exes) using Portable Python, Portable Python 3 is also available.
If the installer is for OS X or Linux, Python shall be there usually. Otherwise
Lazy way: Detect if Python is existed. If not, ask user to install it as dependency. e.g. A link for python download page.
Rewrite your script. If the logic is not complicated, use some other build-in shell script is a good idea.
Static linking Python. Yes, static linking is evil. However, it's still an option.
Found some project maybe helpful on github and google-code
(In addition to Owens points). Use py2exe or one of the other exe builder utils for python on windows. On other platforms just use the python script.
Try cx_Freeze
This program can freeze your python code into a .exe file and some other pyd files, it can be run without installing python.
NOTE: You will need to install python to freeze, but you don't need python to run the program.
You can download from here.
https://anthony-tuininga.github.io/cx_Freeze/index.html
TO FREEZE:
make a file setup.py
type
from cx_Freeze import setup, Executable
setup (name='NEW_EXE_FILE_NAME',
executables = [Executable("xx.py")])
xx.py will be the python code you want to freeze.
command line: python setup.py build
You can use python's embeddable package, available here:
Python Windows Releases
Once you download the package all you need to do is extract it into a folder. That's it... Installed.
You also might want to install pip to manage packages by running the pip install script pip install script and add pip.exe's relative path to python3xx._pth file.
PatriTech made a nice summary of the process on YouTube: Embedded Python Installation

Including Bash autocompletion with setuptools

I've got a couple packages in PyPI, and I'd like to include autocompletion features with both of them. How would you check that Bash autocompletion should be installed at all (check for /etc/bash_completion, maybe?), and how would you install it with setup.py (preferably using setuptools)?
If you're going to require OS-level packages (i.e. bash-completion), then you should distribute your library as an OS-level package. That is, in .deb, .rpm, etc. Some tips here:
Debian New Maintainer's Guide
Fedora Packaging Guidelines
As part of the package generation, you can call your setuptools script to install the Python code. To ensure bash-completion is installed, you can specify it is a required package.
You can use data_files options:
from setuptools import setup
setup(
...
data_files=[
('/etc/bash_completion.d/', ['extra/some_completion_script']),
]
)

Categories

Resources