Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Postpone importing numpy until compiling starts #27

Merged
merged 2 commits into from
Feb 3, 2017

Conversation

jkawamoto
Copy link
Contributor

This lazy evaluation enables CVXcanon to be pip installed even if numpy isn't
separately installed beforehand, because pip is able to interpret the
requirements from setup.py. Previously, since the setup file for CVXcanon began
by importing numpy, pip would error if numpy wasn't already installed.

For example, suppose your requirements.txt is like

numpy>=1.12.0             
scipy>=0.18.1             
CVXcanon>=0.1.1

and run pip install -r requirements.txt to install those packages,
pip checks dependencies written in install_requires in setup.py in order to
install those dependencies before compiling CVXcanon starts.
However, since setup.py imports numpy at the top, this checking step fails due
to an import error.

This pull request introduces a lazy import of numpy to postpone importing
it until actual compiling phase starts, and it allows pip to evaluate setup.py
and install dependencies first.

After numpy and scipy are installed, the compiling CVXcanon phase starts.
pip now evaluates the lazy import to obtain the include path of numpy.
At the time, since numpy has been installed, no import error raises.

You will also no longer need pip install numpy as a first step in the CVXcanon
installation instructions, if missing it will be installed when CVXcanon is pip
installed.

This lazy evaluation enables CVXcanon to be pip installed even if numpy isn't separately installed beforehand, because pip is able to interpret the requirements from setup.py. Previously, since the setup file for CVXcanon began by importing numpy, pip would error if numpy wasn't already installed.
@SteveDiamond
Copy link
Member

Excellent catch! Thanks!

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.

2 participants