我正在制作一个带有 tox
测试和使用 fasttext
Python 包的项目。 fasttext
使用 cython。我在 tox 环境设置期间遇到了 cython 错误: ImportError: No module named Cython.Build
。
如果我让 tox 使用站点包,我可以让它工作。
我创建了一个产生相同错误消息的小测试: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'],
)
我从 tox 得到的错误是:
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
我看到
pip
的子依赖项的安装顺序存在问题,请参见例如 https://github.com/h5py/h5py/issues/535 但我的印象是这个问题已解决。我在 setup_requires with Cython? 看到了一个解决方法,但我没有看到我的模块可以使用该解决方法。
这是
fasttext
问题吗?或者我缺少一些设置? 最佳答案
我可以先使用 indexserver
欺骗 tox 来安装 cython。这个想法是假装从不同的索引服务器安装 cython。
对于您的情况,它将是:
[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
学分:
https://github.com/cggh/scikit-allel/blob/v1.1.10/tox.ini
关于python - tox、cython 和 fasttext,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/42375012/