3

I am making a project with tox testing and the use of the fasttext Python package. fasttext uses cython. I run into a cython error during the tox environment setup: ImportError: No module named Cython.Build.

I can get it to work if I let tox use sitepackages.

I have created a small test that yields the same error message:

tox.ini:

[tox]
envlist = py27

[testenv:py27]
# sitepackages=True
commands = 
    python -m pytest --doctest-modules testinstall.py
deps=
    pytest
    cython
    fasttext

setup.py:

from setuptools import setup
setup(
    setup_requires=['cython'],
    install_requires=['cython', 'fasttext'],
)

The error I get from tox reads:

Collecting pytest
  Using cached pytest-3.0.6-py2.py3-none-any.whl
Collecting cython
  Using cached Cython-0.25.2-cp27-cp27mu-manylinux1_x86_64.whl
Collecting fasttext
  Using cached fasttext-0.8.3.tar.gz
    Complete output from command python setup.py egg_info:
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/tmp/pip-build-8NfmOs/fasttext/setup.py", line 3, in <module>
        from Cython.Build import cythonize
    ImportError: No module named Cython.Build

I see that there there has been an issue with pip's order of installation of subdependencies, see, e.g., https://github.com/h5py/h5py/issues/535 but I am under the impression that this issue is solved.

I see a workaround at setup_requires with Cython? but I don't see my module can use that workaround.

Is this a fasttext issue? Or I am missing some setup?

Finn Årup Nielsen
  • 6,130
  • 1
  • 33
  • 43

1 Answers1

3

I could cheat tox to install cython first using indexserver. The idea is to pretend to install cython from a different indexserver. For your case it would be:

[tox]
envlist = py27
# trick to enable pre-installation of Cython
indexserver =
    preinstall = https://pypi.python.org/simple

[testenv:py27]
# sitepackages=True
commands = 
    python -m pytest --doctest-modules testinstall.py
deps=
    :preinstall: cython
    pytest
    fasttext

Credits: https://github.com/cggh/scikit-allel/blob/v1.1.10/tox.ini

Andre Miras
  • 3,580
  • 44
  • 47