Python package with pywin32 or pypiwin32 dependency - python

I'm building a python package which requires pywin32.
Adding pywin32 as a dependency doesn't work seamlessly, since it has a postinstall script which the user must run themselves.
Adding pypiwin32 as a dependency doesn't work because my package won't play nice with other packages which do require pywin32
I tried requiring both, but it turns out pywin32 and pypiwin32 can't coexist on the same python installation
Is there a way of specifying either pywin32 or pypiwin32 as a dependency? Or some other solution?

The adding pip install pywin32 as a post-install script works, but removes the install_requires command from setup. To fix this, add do_egg_install(self) rather than run in the classes
from setuptools import setup
from setuptools.command.develop import develop as _develop
from setuptools.command.install import install as _install
from subprocess import check_call
# PostDevelopCommand
class develop(_develop):
"""Post-installation for development mode."""
def run(self):
check_call("pip install pywin32")
develop.do_egg_install(self)
# PostInstallCommand
class install(_install):
"""Post-installation for installation mode."""
def run(self):
check_call("pip install pywin32")
develop.do_egg_install(self)
and insert cmdclass argument to setup() function in setup.py:
setup(
...
cmdclass={
'develop': develop,
'install': install,
},
...
)

Related

setup.py fails to install google-cloud-pubsub

I'm trying to prepare setup.py that will install all necessary dependencies, including google-cloud-pubsub. However, python setup.py install fails with
pkg_resources.UnknownExtra: googleapis-common-protos 1.6.0b6 has no such extra feature 'grpc'
The weird thing is that I can install those dependencies through pip install in my virtualenv.
How can I fix it or get around it? I use Python 2.7.15.
Here's minimal configuration to reproduce the problem:
setup.py
from setuptools import setup
setup(
name='example',
install_requires=['google-cloud-pubsub']
)
In your setup.py use the following:
from setuptools import setup
setup(
name='example',
install_requires=['google-cloud-pubsub', 'googleapis-common-protos==1.5.3']
)
That seems to get around it

ImportError while performing pip install

While in my virtual environment, i'm trying to perform 'pip install .' with a setup.py such as :
from setuptools import setup
import pbr
... some functions ...
setup(
name='example',
setup_requires=['pbr'],
py_modules=['example'],
entry_points='''
[console_scripts]
example=example:main
''',
)
The thing is that i get the following error ImportError: No module named pbr
This seems quite legit as i didn't install pbr in my virtual environment BUT i thought that specifying 'setup_requires' would do the trick ... :/
Does someone understand why this does not work and knows how to fix it ? :)
The script does import pbr before running setup() so setup() was not given a chance to install pbr.
The fix is to not import pbr before running setup(). See https://docs.openstack.org/pbr/latest/user/using.html:
#!/usr/bin/env python
from setuptools import setup
setup(
setup_requires=['pbr'],
pbr=True,
)

Python dependency resolution

I have previously created a python package and uploaded it to pypi. The package depends upon 2 other packages defined within the setup.py file:
from setuptools import setup
from dominos.version import Version
def readme():
with open('README.rst') as file:
return file.read()
setup(name='dominos',
version=Version('0.0.1').number,
author='Tomas Basham',
url='https://github.com/tomasbasham/dominos',
license='MIT',
packages=['dominos'],
install_requires=[
'ratelimit',
'requests'
],
include_package_data=True,
zip_safe=False)
As both of these were already installed within my virtualenv this package would run fine.
Now trying to consume this package within another python application (and within a separate virtualenv) I have defined the following requirements.txt file:
dominos==0.0.1
geocoder==1.13.0
For reference dominos is the package I uploaded to pypi. Now running pip install --no-cache-dir -r requirements.txt fails because dependencies of dominos are missing:
ImportError: No module named ratelimit
Surely pip should be resolving these dependencies since I have defined them in the setup.py file of dominos. Clarity on this would be great.

How to install py-yajl through setup.py?

I want to install py-yajl through setup.py like this.
from setuptools import setup, find_packages
here = os.path.abspath(os.path.dirname(__file__))
requires = [
'yajl',
]
setup(
...
install_requires=requires,
tests_require=requires,
...
)
But this setup.py has some errors.
>>> Creating a symlink for compilationg: includes/yajl -> yajl/src/api
error: SandboxViolation: symlink('../yajl/src/api', 'includes/yajl') {}
The package setup script has attempted to modify files on your system
that are not within the EasyInstall build area, and has been aborted.
This package cannot be safely installed by EasyInstall, and may not
support alternate installation locations even if you run its setup
script by hand. Please inform the package's author and the EasyInstall
maintainers to find out if a fix or workaround is available.
I know I can install yajl using pip.
If some config could be changed by setup.py to use pip, I will install yajl but I don't know how to do it.
Does someone have a good idea?

Conditionally installing importlib on python2.6

I have a python library that has a dependency on importlib. importlib is in the standard library in Python 2.7, but is a third-party package for older pythons. I typically keep my dependencies in a pip-style requirements.txt. Of course, if I put importlib in here, it will fail if installed on 2.7. How can I conditionally install importlib only if it's not available in the standard lib?
I don't think this is possible with pip and a single requirements file. I can think of two options I'd choose from:
Multiple requirements files
Create a base.txt file that contains most of your packages:
# base.txt
somelib1
somelib2
And create a requirements file for python 2.6:
# py26.txt
-r base.txt
importlib
and one for 2.7:
# py27.txt
-r base.txt
Requirements in setup.py
If your library has a setup.py file, you can check the version of python, or just check if the library already exists, like this:
# setup.py
from setuptools import setup
install_requires = ['somelib1', 'somelib2']
try:
import importlib
except ImportError:
install_requires.append('importlib')
setup(
...
install_requires=install_requires,
...
)

Categories

Resources