Skip to content

Postpone numpy import until extensions are being built#229

Open
edrogers wants to merge 4 commits intopystruct:masterfrom
edrogers:bug/numpy_in_setup
Open

Postpone numpy import until extensions are being built#229
edrogers wants to merge 4 commits intopystruct:masterfrom
edrogers:bug/numpy_in_setup

Conversation

@edrogers
Copy link

Fixes #228.

Summary:

Postpone numpy import until extensions are being built

Currently, numpy must be installed before pystruct can be installed. Using pip install pystruct in a clean environment is likely to fail. This is because of #228, and this PR aims to address the issue.

Following the structure of this workaround, this PR moves the import of numpy into a method of an overridden version of distutils.command.build.

Current behavior (requiring fix):

> virtualenv pystruct --python=python3.6
> cd pystruct
> source bin/activate
> pip install pystruct

produces the following:

Collecting pystruct
  Using cached https://files.pythonhosted.org/packages/65/42/763411d5025534699b84f596df89f79b3f044b362bf299e3f649900710f2/pystruct-0.3.2.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-install-4h70uagl/pystruct/setup.py", line 3, in <module>
        import numpy as np
    ModuleNotFoundError: No module named 'numpy'

Desired behavior (demonstrating fix):

> git clone [email protected]:edrogers/pystruct.git
> virtualenv pystruct --python=python3.6
> cd pystruct
> git checkout bug/numpy_in_setup
> source bin/activate
> pip install .

produces the following:

Collecting ad3 (from pystruct==0.3.2)
  Using cached https://files.pythonhosted.org/packages/5a/5c/0ac91c3ac9af74030c38461df521aaf8c4f2f1da59af11093f63716664da/ad3-2.2.1-cp36-cp36m-manylinux1_x86_64.whl
Collecting numpy (from pystruct==0.3.2)
  Using cached https://files.pythonhosted.org/packages/35/d5/4f8410ac303e690144f0a0603c4b8fd3b986feb2749c435f7cdbb288f17e/numpy-1.16.2-cp36-cp36m-manylinux1_x86_64.whl
Building wheels for collected packages: pystruct
  Building wheel for pystruct (setup.py) ... done
  Stored in directory: /tmp/pip-ephem-wheel-cache-316lrmdn/wheels/b4/c5/60/2502b8596676501648bc1a8ff217bbad0db907be973d84d96d
Successfully built pystruct
Installing collected packages: ad3, numpy, pystruct
Successfully installed ad3-2.2.1 numpy-1.16.2 pystruct-0.3.2

Interested in hearing thoughts and feedback.

@edrogers
Copy link
Author

edrogers commented Mar 1, 2019

Unfortunately, one of the tests has become unstable. Perhaps there's been a change to an upstream dependency? The Travis CI build history here shows that different build environments fail for repeated runs of the same test.

For the time-being, I've commented out the unstable portion of the test, and opened an issue (#230).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Importing numpy during setup causes install issues

2 participants