Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

setup.py with dependecies installed by conda (not pip)

I am working on an existing Python 3 code-base that provides a setup.py so the code is installed as a Python library. I am trying to get this internal library installed with its own dependencies (the usual data science ones e.g. pandas, pyodbc, sqlalchemy etc).

I would like to have this internal library to deal with these dependencies and assume that if that library is installed, then all the transitive dependencies are assumed to be installed. I also would like to have the Anaconda (conda) version of the package rather than the pip version.

I started with a requirements.txt, but moved quickly to this field in setup.py:

  install_requires=[
      "pyodbc>=4.0.27",
      "sqlalchemy>=1.3.8",
      "pandas>=0.25.1",
      "requests>=2.22.0",
      "assertpy>=0.14",
      "cycler>=0.10.0",
  ]

However when I run the installation process:

  • either with python setup.py install --record installed_files.txt
  • or with pip install .

I see that there is some gcc / C++ compilation going on that shows logs about Python wheels (I don't completely understand the implications of Python eggs and Python wheels, but AFAIK if conda is available then I should go with the conda version rather than eggs/wheels because then I don't have to take care of the C++ code underneath the Python code).

I really would prefer having conda to install these C++ blobs wrapped in some Python code as a libraries e.g. pandas.

  • is it possible at all to have conda driving the installation process described in setup.py so I am not dealing with gcc?
  • how can I make sure that other Python code depending on this internal library (installed via setup.py) is using the same (transitive) dependencies defined in that setup.py?

Regardless the installation method, how can I make sure that the dependencies for e.g. pandas are installed as well? Sometimes I see that numpy as a dependency of pandas is not installed when running setup.py, but I would like to avoid doing this manually (e.g. with some requirements.txt file).

like image 596
TPPZ Avatar asked Sep 06 '19 12:09

TPPZ


People also ask

Can I use conda instead of pip?

Conda creates language-agnostic environments natively whereas pip relies on virtualenv to manage only Python environments Though it is recommended to always use conda packages, conda also includes pip, so you don't have to choose between the two.

Does conda use setup py?

The `setup.py` is used to install a package into a development environment (with `python setup.py develop`) or into a Conda build environment for packaging. If the development environment and build environment both provide the same dependencies, then none need to be specified in `setup.py`.

Does conda install dependencies?

Conda analyzes each package for compatible dependencies, and how to install them without conflict.

How do I use setup py in Anaconda?

Open Anaconda Command prompt as administrator. Use cd C:\Users\… to locate the downloaded site. Then run pip install setup.py.


1 Answers

pip doesn't know about conda, so you cannot build a pip-installable package that pulls in its dependencies from conda channels.

conda doesn't care about setup.py, it uses a different format for recording dependencies.

To install your code with conda, you should create a conda package, and specify your dependencies in a meta.yaml file. Refer to the documentation of "conda build" for details.

https://docs.conda.io/projects/conda-build/en/latest/resources/define-metadata.html

like image 92
Roland Weber Avatar answered Oct 27 '22 04:10

Roland Weber