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

Use of numpy.distutils in setup.py causes errors if installing in clean virtualenv #143

Closed
jcohen02 opened this issue Oct 15, 2020 · 7 comments

Comments

@jcohen02
Copy link
Contributor

Describe the bug
When attempting to install Solcore in a clean virtualenv (or any Python environment that does not currently have numpy installed) using python setup.py install results in an error since there is an attempt to import the version of distutils from wihtin numpy prior to numpy being installed!

To Reproduce
Clone solcore, create and activate a virtualenv and then attempt to run the install using setup.py. This example is based on a Mac/Linux platform with Python >=3.7 and the virtualenv Python package installed:

git clone git@github.com:qpv-research-group/solcore5.git
cd solcore5
virtualenv env
source env/bin/activate
python setup.py install

This immediately results in the error:

  File "setup.py", line 2, in <module>
    from numpy.distutils.core import Extension, setup
ModuleNotFoundError: No module named 'numpy'

Expected behavior
The install should proceed and complete successfully.

Additional context
This is a result of attempting to use the enhanced distutils from within numpy prior to numpy being installed.
It looks like this version of distutils is required to support the building of the native PDD library from the Fortran source when using the --with_pdd option.

A simple workaround would be to import only setup from distutils.core and then import Extension from numpy.distutils.core within the if "--with_pdd" in sys.argv: block. This would still require someone wanting to use the PDD module to install numpy manually first but it would at least prevent an error when trying to run the basic install.
I assume there's a better solution to this which would presumably involve installing numpy inside the if "--with_pdd" in sys.argv: block if it's required.

@jcohen02 jcohen02 added the bug label Oct 15, 2020
@dalonsoa
Copy link
Collaborator

This is not a bug, but actually the expected behaviour. numpy is a pre-requisite for installing Solcore, as indicated in the documentation.

@jcohen02
Copy link
Contributor Author

Thanks for highlighting this @dalonsoa. I wonder if it should still be possible to do an install from scratch in a clean environment using python setup.py install but, as you point out, installing numpy manually first will avoid the problem and since that's clear in the documentation, I'll close this issue.

@dalonsoa
Copy link
Collaborator

I wish it could be avoided, to be honest, but I think that the possible solutions are more convoluted than simply asking for numpy to be installed first. I wonder if, when having binary wheels, this could be avoided when installing Solcore from PyPI...

@jcohen02
Copy link
Contributor Author

jcohen02 commented Oct 15, 2020

It seems this is a common issue that has been addressed (to some extent at least) in various repos, including scipy. See the discussion in the following for further info (not linking issues directly to avoid spamming these issues with reverse references):

Issue 4164 in scikit-learn: can't setup.py install without numpy
Issue 174 in scikit-hep: Bootstrap installation of numpy in setup.py if it is not already installed
How to Bootstrap numpy installation in setup.py

It looks like this could be addressed fairly straightforwardly using the approach taken in PR 292 in scikit-hep/root_numpy, however, if I understand correctly, the downside of this (as highlighted in one of the above links) is that then even running python setup.py --help results in numpy being installed if it isn't already. The solution to this is then a more substantial set of implementation to check the provided parameters and handle them individually where necessary as done in parse_setuppy_commands in setup.py of scipy.

I appreciate that this probably not classed as a critical requirement but might be something worth considering addressing going forward. Happy to look into resolving this if that would be helpful.

@Abelarm
Copy link
Contributor

Abelarm commented Oct 15, 2021

What about I take care of this?

@dalonsoa
Copy link
Collaborator

Absolutely! This has been bothering many people for a long time. If you can sort this out, it will be a great help!

@dalonsoa
Copy link
Collaborator

dalonsoa commented Nov 7, 2021

Solved by #202

@dalonsoa dalonsoa closed this as completed Nov 7, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants