[PYTHON] One solution when numpy can be entered via pip but not via poetry

TL;DR

Assumed situation

--If numpy is via system pip3, pip3 install numpy will work fine --I get an error when I do poetry add numpy via poetry

solution

  1. Hit poetry run pip install numpy and forcibly throw numpy via pip3 in the virtual environment created by poetry.
  2. Hit poetry add numpy to make poetry recognize numpy and update pyproject.toml and poetry.lock

NOTE: This step was performed in your environment on January 20, 2021.

environment

Path to solution

Failure: Try inserting numpy1.20.0rc

If you look at https://github.com/numpy/numpy/issues/17987#issuecomment-75202322

You can use the 1.20.0rc2 release candidate. python -m pip install -i https://pypi.anaconda.org/multibuild-wheels-staging/simple numpy==1.20.0rc2 This should become the 1.20.0 release in a few weeks.

Since there is a description, try poetry add numpy == 1.20.0rc2. However, I got an AssetionError during the build process during installation, so I decided to give up on this path.

Failure: Drop Python version to 3.8

According to https://numpy.org/news/, the numpy binaries for Python3.9 are still in preparation as of September 14, 2020. I expected this to be affecting it, and in the Python3.9 environment it was failing because I was trying to build from source code via poetry. I dropped the version to Python 3.8 and tried it.

PYTHON 3.9 IS COMING, WHEN WILL NUMPY RELEASE BINARY WHEELS? Sept 14, 2020 – Python 3.9 will be released in a few weeks. If you are an early adopter of Python versions, you may be dissapointed to find that NumPy (and other binary packages like SciPy) will not have binary wheels ready on the day of the release. It is a major effort to adapt the build infrastructure to a new Python version and it typically takes a few weeks for the packages to appear on PyPI and conda-forge. In preparation for this event, please make sure to

  • update your pip to version 20.1 at least to support manylinux2010 and manylinux2014
  • use --only-binary=numpy or --only-binary=:all: to prevent pip from trying to build from source.

In conclusion, this prediction was false, and as of January 20, 2021, numpy binaries for Python3.9 were distributed (https://pypi.org/project/numpy/#files).

Success (step1): Return to being able to install without problems via system pip3

I wrote the following preconditions at the beginning.

If numpy is via system pip3, pip3 install numpy will work fine

Through trial and error, I sometimes tried to install numpy via pip3 instead of poetry, but in my environment, numpy could be installed without any problem if it was via pip3 on the system. If so, I thought it would be impossible to pip numpy in poetry's virtual environment without using poetry. In other words

poetry run pip install numpy

This is what it is. I feel a little unpleasant, but I tried it as a trial.

Then, how can you enter without any problems!

Success (step2): Make poetry aware of the existence of numpy

In the above steps, numpy was half-forced into the virtual environment created by poetry. However, the method I just tried is different from the usual library installation method that poetry expects, so poetry does not recognize it as a numpy managed package. Specifically, pyproject.toml and poetry.lock have not been updated at all. So if you hit something like poetry update at this stage, the" unidentified "numpy will be removed from the virtual environment created by poetry.

So, run poetry add numpy to let poetry formally install numpy. Since numpy is already installed in the virtual environment created by poetry, the numpy installation will not actually be performed, it will only update the dependency management files.

Appendix: Similar articles

There was already an example of forcibly solving the situation as described in this article. https://qiita.com/Ryuichirou/items/f769e5072305802e18c5

In the above similar article, it seems that the following steps are taken.

  1. Install numpy on your system via pip
  2. Instead of creating a virtual environment in poetry, create it manually and install numpy there via pip
  3. Start poetry in the manually created virtual environment and let poetry recognize the virtual environment.
  4. Have poetry spit out the dependencies that should be entered during the poetry initialization stage as requirements.txt
  5. Have the contents of requirements.txt installed via pip

Authors of similar articles themselves

Somehow, the feeling of korejanai is amazing. I want to solve it better.

Is saying.

This article provided a simpler, better solution with fewer steps than similar articles.

Recommended Posts

One solution when numpy can be entered via pip but not via poetry
Can be used when aws-cli is available but jq is not available jp.py
"Temporary solution" when pip cannot be updated [Python]