esheldon / esutil

A variety of python utilities focusing on numerical, scientific, and astrophysical computing
GNU General Public License v2.0
35 stars 19 forks source link

Installation from pip on a clean system is broken #73

Closed karpov-sv closed 3 months ago

karpov-sv commented 2 years ago

When installing on a clean system using pip install esutil the installation goes fine, but the package cannot be imported. The error is:

root@836b9e6d53c4:/# python3 -c 'import esutil'
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/usr/local/lib/python3.10/dist-packages/esutil/__init__.py", line 104, in <module>
    from . import integrate
ImportError: cannot import name 'integrate' from partially initialized module 'esutil' (most likely due to a circular import) (/usr/local/lib/python3.10/dist-packages/esutil/__init__.py)

Steps to replicate (using Ubuntu docker image as an example, just to have a clean system - but it manifests on other distributions as well):

docker run -it ubuntu
> apt update
> apt install python3-pip
> pip3 install esutil
> python3 -c 'import esutil'
esheldon commented 2 years ago

I didn't try docker, but the following works

conda create -n test-esutil numpy pip
source activate test-esutil
pip install esutil
python -c 'import esutil'

Of course, if you are using conda you can just do conda install esutil which is better

esheldon commented 2 years ago

does this apt installed python include numpy?

esheldon commented 2 years ago

Note this also works, using the ubuntu system python3 rather than conda

python3 -m venv test-esutil
pip3 install numpy
pip3 install esutil
python3 -c 'import esutil'
karpov-sv commented 2 years ago

No, of course not. So most probably the reason is what esutil does not list numpy as its dependency (it is commented out in setup.py?..)

This really breaks things when installing esutil as a requirement for another package - it tries to pull everything including numpy (which my package also depends on), and then install esutil before (or in parallel?..) with numpy, and thus produces broken wheel - that's how I actually encountered it.

esheldon commented 2 years ago

Early on in the life of esutil, having numpy as a dependency for pip was a big problem. It often could not do the numpy install. And in certain situations it could not detect existing numpy correctly.

This was like 10 years ago.

So I kept the dependency out of the setup.py to avoid breaking existing setups.

It seems that the numpy pip install is pretty reliable now. I think it is probably safe to put in that dependency.

Would you be able to make a PR?

karpov-sv commented 2 years ago

It does not actually solve the problem completely - as the test for whether numpy is installed happens before setup.py actually installs it as a requirement. Probably it might be moved e.g. into the builder?..

esheldon commented 2 years ago

good point. Do you want to take a shot at a PR?

jobovy commented 1 year ago

I believe this was fixed by #77.

aboucaud commented 1 year ago

Hi, I just encountered this issue when installing esutil from pip

python -m pip install esutil

which installs a precompiled v0.6.10.

After reading this thread, I tried to install the development version instead

python -m pip install git+https://github.com/esheldon/esutil.git

and it solved the issue.

Since 0.6.10 is dated from Jan 8 and #77 was merged on Jan 10, I also believe this has been fixed in the current version. Perhaps a new release on PyPI would be useful.

esheldon commented 1 year ago

I'll release 0.6.11 today

esheldon commented 1 year ago

released