Unable to import dependency installed from git in setup.py - python

I am trying to use setup.py to install a Python package that is kept in a git repository, which we'll call my_dependency. In my_package, I have a setup.py file with:
setup(
...
install_requires=[
...
'my_dependency=VERSION'
],
dependency_links=['git+https://...my_dependency.git#egg=my_dependency-VERSION',]
)
When I run my setup file (python setup.py develop), the dependency appears to install; it shows up as my_dependency==VERSION when I run pip freeze. However, when I start a python session and call import my_dependency, I get ImportError: No module named my_dependency.
I don't know if this is possibly the source of the problem, but when running setup.py, I get a warning:
Processing dependencies for my_package==0.1
Searching for my_dependency==VERSION
Doing git clone from https://.../my_dependency.git to /var/folders/.../.../T/easy_install-_rWjyp/my_dependency.git
Best match: my_dependency VERSION
Processing my_dependency.git
Writing /var/folders/.../my_dependency.git/setup.cfg
Running setup.py -q bdist_egg --dist-dir /var/folders/.../my_dependency.git/egg-dist-tmp-UMiNdL
warning: install_lib: 'build/lib' does not exist -- no Python modules to install
Copying my_dependency-VERSION-py2.7.egg to /.../my_package/venv/lib/python2.7/site-packages
Adding my_dependency VERSION to easy-install.pth file
However, I am able to use the package if I install it through pip, like this: pip install -e git+https://.../my_dependency.git#egg=my_dependency-VERSION
For reference, the dependency package structure looks like this:
my_dependency/
my_dependency/
__init__.py
setup.py
And its setup.py contains this:
from setuptools import setup
setup(
name='my_dependency',
version='VERSION',
description='...',
author='...',
url='https://...',
license='MIT',
install_requires=[
'numpy',
],
zip_safe=False,
)

The solution was (in retrospect) pretty silly. My dependency package was missing this line in its setup.py:
packages=['my_dependency'],
That meant the package was correctly building and installing, but it wasn't actually including the code in the package. This became apparent when I looked at the SOURCES.txt in the egg-info: it didn't include any of the Python source files in the package.

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

pip and setup.py install don't install actual modules, only egg-info

I've made two packages (pphp and xmlx) and distributed and uploaded them the standard way, using python setup.py sdist bdist_wheel and twine upload dist/*.
I then tried installing them using pip install, and it seemed to work fine... but then, in the interactive shell:
>>> import xmlx
Traceback (most recent call last):
File <module>, line 1:
import xmlx
ImportError: No module named xmlx
I then tried python setup.py install but same result (seemed fine but didn't work).
So what's going on?
This is the repository for xmlx, yes? Your setup.py declares the packages in your project with packages=find_packages(), but your project does not contain any import packages, only a single-file module, xmlx.py. This must be declared in your setup.py by instead writing:
py_modules=['xmlx']
(Also, dist/ and *.egg-info/ are build artifacts and should not be stored in version control; I recommend adding them to your .gitignore.)

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.

Custom Python Package Won't Properly Install via Pip In VirtualEnv

I've created a new python package for a project I'm working on.
It has a folder structure that resembles:
bin
docs
mypackage
license.md
readme.md
setup.py
Here are the contents of my setup.py:
try:
from setuptools import setup
except ImportError:
from distutils.core import setup
config = {
'description': 'A python client for foo',
'author': 'Me',
'url': 'https://github.com/account/mypackage',
'download_url': 'https://github.com/account/mypackage',
'author_email': 'foo#bar.com',
'version': '0.1',
'install_requires': ['nose'],
'name': 'MyPackage'
}
setup(**config)
I'm not ready to make this public so I install it directly from Git via:
pip install git+ssh://git#github.com/account/mypackage.git
Here's the output:
Downloading/unpacking git+ssh://git#github.com/account/mypackage.git
Cloning git+ssh://git#github.com/account/mypackage.git to /var/folders/7w/qsdf76s97sfsdf7sdf97sdf/T/pip-ovbMpR-build
Running setup.py egg_info for package from git+ssh://git#github.com/account/mypackage.git
Downloading/unpacking nose (from MyPackage==0.1)
Downloading nose-1.2.1.tar.gz (400kB): 400kB downloaded
Running setup.py egg_info for package nose
no previously-included directories found matching 'doc/.build'
Installing collected packages: nose, MyPackage
Running setup.py install for nose
no previously-included directories found matching 'doc/.build'
Installing nosetests script to /Users/user/sandbox/.pyvirtualenvs/project/bin
Installing nosetests-2.7 script to /Users/user/sandbox/.pyvirtualenvs/project/bin
Running setup.py install for MyPackage
Successfully installed nose MyPackage
Cleaning up...
It says it installed correctly, but when I check /Users/user/sandbox/.pyvirtualenvs/project/bin - I don't see my MyPackage.
I see that nose was installed correctly, and it created a MyPackage-0.1-py2.7.egg-info/ directory - but no mypackage folder with my library.
Consequently, when I try to use the package, it cannot be found.
Why? Is my setup.py configured incorrectly?
It doesn't appear you are actually instructing setup to install your package.
You'll need something like:
packages=['mypackage'],
in your setup() call. Checkout how py-bootstrap does it: https://github.com/splaice/py-bootstrap/blob/master/setup.py
For including bin scripts, you'll need to list your scripts with the scripts directive as well, for example:
scripts=['bin/myscript']

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?

Categories

Resources