gatagat / lap

Linear Assignment Problem solver (LAPJV/LAPMOD).
BSD 2-Clause "Simplified" License
211 stars 66 forks source link

Fail to install using Poetry #30

Open fgmacedo opened 3 years ago

fgmacedo commented 3 years ago

I'm trying to install this lib using poetry.

My pyproject.yml has two direct dependencies:

numpy = "1.18.4"
lap = "0.4.0"

But since lap also needs numpy, there's no way to poetry to resolve dependencies without the lap mentioning that numpy is a install dependency.

I've found that this custom setup instructions is probably the issue, not compatible with the way poetry tries to install:

https://github.com/gatagat/lap/blob/ece5ee9d9876edfdcc770032fbdce66458c6b6a9/setup.py#L204-L222

Error:

❯ poetry add "lap[alldeps]"
Using version ^0.4.0 for lap

Updating dependencies
Resolving dependencies... (0.5s)

Package operations: 5 installs, 0 updates, 0 removals

  - Installing lap (0.4.0)

[EnvCommandError]
Command ['/home/fernando/.cache/pypoetry/virtualenvs/sM4e1v81-py3.7/bin/pip', 'install', '--no-deps', 'lap==0.4.0'] errored with the following return code 1, and output:
Collecting lap==0.4.0
  Using cached https://files.pythonhosted.org/packages/bf/64/d9fb6a75b15e783952b2fec6970f033462e67db32dc43dfbb404c14e91c2/lap-0.4.0.tar.gz
Installing collected packages: lap
  Running setup.py install for lap: started
    Running setup.py install for lap: finished with status 'error'
    ERROR: Command errored out with exit status 1:
     command: /home/fernando/.cache/pypoetry/virtualenvs/sM4e1v81-py3.7/bin/python3 -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-h0wwep35/lap/setup.py'"'"'; __file__='"'"'/tmp/pip-install-h0wwep35/lap/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record /tmp/pip-record-fls2s3js/install-record.txt --single-version-externally-managed --compile --install-headers /home/fernando/.cache/pypoetry/virtualenvs/sM4e1v81-py3.7/include/site/python3.7/lap
         cwd: /tmp/pip-install-h0wwep35/lap/
    Complete output (12 lines):
    Partial import of lap during the build process.
    Traceback (most recent call last):
      File "/tmp/pip-install-h0wwep35/lap/setup.py", line 127, in get_numpy_status
        import numpy
    ModuleNotFoundError: No module named 'numpy'
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/tmp/pip-install-h0wwep35/lap/setup.py", line 236, in <module>
        setup_package()
      File "/tmp/pip-install-h0wwep35/lap/setup.py", line 220, in setup_package
        raise ImportError('lap requires numpy, '
    ImportError: lap requires numpy, please "pip install numpy".
    ----------------------------------------
ERROR: Command errored out with exit status 1: /home/fernando/.cache/pypoetry/virtualenvs/sM4e1v81-py3.7/bin/python3 -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-h0wwep35/lap/setup.py'"'"'; __file__='"'"'/tmp/pip-install-h0wwep35/lap/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record /tmp/pip-record-fls2s3js/install-record.txt --single-version-externally-managed --compile --install-headers /home/fernando/.cache/pypoetry/virtualenvs/sM4e1v81-py3.7/include/site/python3.7/lap Check the logs for full command output.
gatagat commented 3 years ago

First, thanks for reporting.

I don't know much about poetry yet, but I was thinking about giving it a try. Unfortunately I will not have enough time to devote to this soon. In case you would, I am happy to discuss the details.

fgmacedo commented 3 years ago

Thanks @gatagat. I think that a quickly approach is to declare cython and numpy as explicit requirements using install_requires, I've forked the repo to not be blocked by this and it indeed solved the install issue. If you're ok with this I'll be glad to send a PR.

Let me know if you have any other suggestion.

Best regards!

lig commented 2 years ago

@fgmacedo do it :)

Almorisson commented 2 years ago

For people who are struggling to install lap with docker, you can try to use the other fork of the same project called lap05.

You can make a search on pypi for the version that most sweet to you. In your pyproject.toml:

lap05 = "0.5.1"
numpy = "1.23.2" # You have to add this line because `numpy` is a dependancy of lap

Just make sure, you also install the python3-dev lib in the section of your docker file where you install system deps.

Example:

# install system dependencies
RUN apt-get update && \
    apt-get install -y build-essential && \
    apt-get install -y python3-dev && \
    apt-get install -y telnet netcat && \
    apt-get install -y --no-install-recommends gcc && \
    apt-get install -y locales wkhtmltopdf jq && \
    apt-get install -y curl
lig commented 2 years ago

@Almorisson if numpy is a dependency it should be defined as such in lap05, isn't it?

41 solved the installation problem for me without the need to add numpy explicitly.

Unfortunately, there is no word from @gatagat regarding the PR.

AlanBlanchet commented 5 months ago

For anyone coming accross this. You can use lapx instead which will resolve to lap when importing. It worked for me when lauching the test scripts of mmdet

pip install lapx
import lap