popgenmethods / momi2

Infer demographic history with the Moran model
GNU General Public License v3.0
47 stars 11 forks source link

Improve build robustness to missing numpy #51

Open jackkamm opened 2 years ago

jackkamm commented 2 years ago

Sometimes pip install momi fails because import numpy is invoked in the build process before numpy is installed.

A 2nd invocation of pip install momi generally works because numpy is present at that point.

The error can be prevented by installing numpy before momi.

The build process uses some tricks to try and prevent early import of numpy, but these are fragile and seem to have partially stopped working. Switching the build process to use pyproject.toml may fix this. See also:

Relevant error messages below:

  Building wheel for momi (setup.py) ... error
  ERROR: Command errored out with exit status 1:
   command: /home/jack/miniconda3/envs/momi2-py3.10/bin/python -u -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-t1fd9myk/momi_33681db3a0dc49ffa4013d727374a331/setup.py'"'"'; __file__='"'"'/tmp/pip-install-t1fd9myk/momi_33681db3a0dc49ffa4013d727374a331/setup.py'"'"';f = getattr(tokenize, '"'"'open'"'"', open)(__file__) if os.path.exists(__file__) else io.StringIO('"'"'from setuptools import setup; setup()'"'"');code = f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' bdist_wheel -d /tmp/pip-wheel-nb2wp3bh
       cwd: /tmp/pip-install-t1fd9myk/momi_33681db3a0dc49ffa4013d727374a331/
  Complete output (81 lines):
  running bdist_wheel
  running build
  running build_py
  creating build
  creating build/lib.linux-x86_64-3.10
  creating build/lib.linux-x86_64-3.10/momi
  copying momi/util.py -> build/lib.linux-x86_64-3.10/momi
  copying momi/size_history.py -> build/lib.linux-x86_64-3.10/momi
...
  running build_ext
  building 'momi.convolution' extension
  Traceback (most recent call last):
    File "<string>", line 1, in <module>
    File "/tmp/pip-install-t1fd9myk/momi_33681db3a0dc49ffa4013d727374a331/setup.py", line 56, in <module>
      setup(name='momi',
...
    File "/home/jack/miniconda3/envs/momi2-py3.10/lib/python3.10/distutils/ccompiler.py", line 565, in compile
      self._setup_compile(output_dir, macros, include_dirs, sources,
    File "/home/jack/miniconda3/envs/momi2-py3.10/lib/python3.10/distutils/ccompiler.py", line 341, in _setup_compile
      pp_opts = gen_preprocess_options(macros, incdirs)
    File "/home/jack/miniconda3/envs/momi2-py3.10/lib/python3.10/distutils/ccompiler.py", line 1076, in gen_preprocess_options
      pp_opts.append("-I%s" % dir)
    File "/tmp/pip-install-t1fd9myk/momi_33681db3a0dc49ffa4013d727374a331/setup.py", line 19, in __str__
      import numpy
  ModuleNotFoundError: No module named 'numpy'
  ----------------------------------------
  ERROR: Failed building wheel for momi
  Running setup.py clean for momi
  Building wheel for autograd (setup.py) ... done
  Created wheel for autograd: filename=autograd-1.3-py3-none-any.whl size=47989 sha256=888bf19e3d0f1a70b1d2f9e5b600874c525436c467f6a78c41edba26d4ba67ad
  Stored in directory: /home/jack/.cache/pip/wheels/ff/2d/38/602bb8b53d05bc9862d72e865a70a4bbaa8f70159e0d3833b1
  Building wheel for future (setup.py) ... done
  Created wheel for future: filename=future-0.18.2-py3-none-any.whl size=491070 sha256=31a21e2ef425f904b77e46b2132a2908e4878d33da043544aa4e67b7931c169e
  Stored in directory: /home/jack/.cache/pip/wheels/22/73/06/557dc4f4ef68179b9d763930d6eec26b88ed7c389b19588a1c
  Building wheel for msprime (PEP 517) ... done
  Created wheel for msprime: filename=msprime-1.1.0-cp310-cp310-linux_x86_64.whl size=879181 sha256=6f0743df6c77e8ac1d5abed50d197f445281bb3f623fad44e946d2b98023f2dc
  Stored in directory: /home/jack/.cache/pip/wheels/33/31/1a/72811dd3c6db34f2e41f192665e06c91d990fc9ff1ca2926c7
  Building wheel for pyrsistent (PEP 517) ... done
  Created wheel for pyrsistent: filename=pyrsistent-0.18.0-cp310-cp310-linux_x86_64.whl size=104092 sha256=46df697d5a1aa9c52fd5263a1eb2e11cba78cac75b7b43a378a8fdbe0bd6281f
  Stored in directory: /home/jack/.cache/pip/wheels/bf/ee/17/b548a960bb9e20daf7987f316c326e8a368603809ace3b2374
Successfully built autograd future msprime pyrsistent
Failed to build momi
Installing collected packages: six, ruamel.yaml.clib, pyrsistent, pyparsing, attrs, svgwrite, ruamel.yaml, pytz, python-dateutil, pillow, packaging, numpy, kiwisolver, jsonschema, fonttools, cycler, tskit, scipy, pandas, newick, matplotlib, future, demes, seaborn, pysam, networkx, msprime, cached-property, autograd, momi
    Running setup.py install for momi ... done
  DEPRECATION: momi was installed using the legacy 'setup.py install' method, because a wheel could not be built for it. A possible replacement is to fix the wheel build issue reported above. You can find discussion regarding this at https://github.com/pypa/pip/issues/8368.
Successfully installed attrs-21.4.0 autograd-1.3 cached-property-1.5.2 cycler-0.11.0 demes-0.2.1 fonttools-4.28.5 future-0.18.2 jsonschema-4.3.2 kiwisolver-1.3.2 matplotlib-3.5.1 momi-2.1.19 msprime-1.1.0 networkx-2.6.3 newick-1.3.2 numpy-1.21.5 packaging-21.3 pandas-1.3.5 pillow-8.4.0 pyparsing-3.0.6 pyrsistent-0.18.0 pysam-0.18.0 python-dateutil-2.8.2 pytz-2021.3 ruamel.yaml-0.17.19 ruamel.yaml.clib-0.2.6 scipy-1.7.3 seaborn-0.11.2 six-1.16.0 svgwrite-1.4.1 tskit-0.4.0