SciTools / cartopy

Cartopy - a cartographic python library with matplotlib support
https://scitools.org.uk/cartopy/docs/latest
BSD 3-Clause "New" or "Revised" License
1.41k stars 359 forks source link

Pip not installing the latest version of Cartopy #2053

Closed Quba1 closed 2 years ago

Quba1 commented 2 years ago

Description

When trying to install Cartopy with pip, it fails to install the latest version because there is a mismatch between cartopy and metadata version. Because of that, pip fails to install the latest cartopy version and falls back to version 18, which installation fails because of incompatible proj version (as described in #2047).

The installation messages look like this:

$ pip install --user --upgrade cartopy
Collecting cartopy
  Using cached Cartopy-0.20.2.tar.gz (10.8 MB)
  Installing build dependencies ... done
  Getting requirements to build wheel ... done
  Preparing metadata (pyproject.toml) ... done
Discarding https://files.pythonhosted.org/packages/f6/55/1e1c737dc9436b320deead73d1c455ddbb74b8b6992081863492f6f6378a/Cartopy-0.20.2.tar.gz#sha256=4d08c198ecaa50a6a6b109d0f14c070e813defc046a83ac5d7ab494f85599e35 (from https://pypi.org/simple/cartopy/) (requires-python:>=3.7): Requested cartopy from https://files.pythonhosted.org/packages/f6/55/1e1c737dc9436b320deead73d1c455ddbb74b8b6992081863492f6f6378a/Cartopy-0.20.2.tar.gz#sha256=4d08c198ecaa50a6a6b109d0f14c070e813defc046a83ac5d7ab494f85599e35 has inconsistent version: filename has '0.20.2', but metadata has '0.0'
  Using cached Cartopy-0.20.1.tar.gz (10.8 MB)
  Installing build dependencies ... done
  Getting requirements to build wheel ... done
  Preparing metadata (pyproject.toml) ... done
Discarding https://files.pythonhosted.org/packages/fc/59/aa52698e3838f4cd0e7eaa75bd86837e9e0b05041dbdaee3cda2fffced06/Cartopy-0.20.1.tar.gz#sha256=91f87b130e2574547a20cd634498df97d797abd12dcfd0235bc0cdbcec8b05e3 (from https://pypi.org/simple/cartopy/) (requires-python:>=3.7): Requested cartopy from https://files.pythonhosted.org/packages/fc/59/aa52698e3838f4cd0e7eaa75bd86837e9e0b05041dbdaee3cda2fffced06/Cartopy-0.20.1.tar.gz#sha256=91f87b130e2574547a20cd634498df97d797abd12dcfd0235bc0cdbcec8b05e3 has inconsistent version: filename has '0.20.1', but metadata has '0.0'
  Using cached Cartopy-0.20.0.tar.gz (10.8 MB)
  Installing build dependencies ... done
  Getting requirements to build wheel ... done
  Preparing metadata (pyproject.toml) ... done
Discarding https://files.pythonhosted.org/packages/0f/c0/58453b036e79046d211f083880d58dcce787e7e07647ac25dc46c6555099/Cartopy-0.20.0.tar.gz#sha256=eae58aff26806e63cf115b2bce9477cedc4aa9f578c5e477b2c25cfa404f2b7a (from https://pypi.org/simple/cartopy/) (requires-python:>=3.7): Requested cartopy from https://files.pythonhosted.org/packages/0f/c0/58453b036e79046d211f083880d58dcce787e7e07647ac25dc46c6555099/Cartopy-0.20.0.tar.gz#sha256=eae58aff26806e63cf115b2bce9477cedc4aa9f578c5e477b2c25cfa404f2b7a has inconsistent version: filename has '0.20.0', but metadata has '0.0'
  Using cached Cartopy-0.19.0.post1.tar.gz (12.1 MB)
  Installing build dependencies ... done
  Getting requirements to build wheel ... done
  Preparing metadata (pyproject.toml) ... done
Discarding https://files.pythonhosted.org/packages/ed/ca/524ce33692df3faeaa56852fb6a33b0b410be94cc288417565b96fef3f64/Cartopy-0.19.0.post1.tar.gz#sha256=4b8b4773a98ed7009fe17d9b6ec87ac3ac62b7d14634d7768c190eadc647d576 (from https://pypi.org/simple/cartopy/) (requires-python:>=3.5): Requested cartopy from https://files.pythonhosted.org/packages/ed/ca/524ce33692df3faeaa56852fb6a33b0b410be94cc288417565b96fef3f64/Cartopy-0.19.0.post1.tar.gz#sha256=4b8b4773a98ed7009fe17d9b6ec87ac3ac62b7d14634d7768c190eadc647d576 has inconsistent version: filename has '0.19.0.post1', but metadata has '0.0'
  Using cached Cartopy-0.18.0.tar.gz (14.4 MB)
  Preparing metadata (setup.py) ... done
Requirement already satisfied: numpy>=1.10 in /usr/lib/python3/dist-packages (from cartopy) (1.21.5)
Requirement already satisfied: pyshp>=1.1.4 in ./.local/lib/python3.10/site-packages (from cartopy) (2.3.0)
Requirement already satisfied: setuptools>=0.7.2 in /usr/lib/python3/dist-packages (from cartopy) (59.6.0)
Requirement already satisfied: shapely>=1.5.6 in ./.local/lib/python3.10/site-packages (from cartopy) (1.8.2)
Requirement already satisfied: six>=1.3.0 in /usr/lib/python3/dist-packages (from cartopy) (1.16.0)
Building wheels for collected packages: cartopy
  Building wheel for cartopy (setup.py) ... error

I finally managed to install the latest version as suggested by this SO post. with

pip install --upgrade --no-cache-dir --use-deprecated=legacy-resolver --user cartopy

But obviously this is just a workaround.

System configuration

Ubuntu 22.04 Python 3.10.5 pip 22.0.2

jules-ch commented 2 years ago

I'm having this issue aswell

janpieter-vanparys commented 2 years ago

I think I have the same error

Step 11/28 : RUN venv/bin/python -m pip install pykdtree scipy cartopy==0.19.0.post1
 ---> Running in 1fc52fdeb493
Collecting pykdtree
  Downloading pykdtree-1.3.5-cp39-cp39-manylinux_2_12_x86_64.manylinux2010_x86_64.whl (264 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 264.8/264.8 kB 1.8 MB/s eta 0:00:00
Collecting scipy
  Downloading scipy-1.8.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (42.2 MB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 42.2/42.2 MB 2.2 MB/s eta 0:00:00
Collecting cartopy==0.19.0.post1
  Downloading Cartopy-0.19.0.post1.tar.gz (12.1 MB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 12.1/12.1 MB 29.3 MB/s eta 0:00:00
  Installing build dependencies: started
  Installing build dependencies: finished with status 'done'
  Getting requirements to build wheel: started
  Getting requirements to build wheel: finished with status 'done'
  Preparing metadata (pyproject.toml): started
  Preparing metadata (pyproject.toml): finished with status 'done'
  WARNING: Requested cartopy==0.19.0.post1 from https://files.pythonhosted.org/packages/ed/ca/524ce33692df3faeaa56852fb6a33b0b410be94cc288417565b96fef3f64/Cartopy-0.19.0.post1.tar.gz#sha256=4b8b4773a98ed7009fe17d9b6ec87ac3ac62b7d14634d7768c190eadc647d576, but installing version 0.0
Discarding https://files.pythonhosted.org/packages/ed/ca/524ce33692df3faeaa56852fb6a33b0b410be94cc288417565b96fef3f64/Cartopy-0.19.0.post1.tar.gz#sha256=4b8b4773a98ed7009fe17d9b6ec87ac3ac62b7d14634d7768c190eadc647d576 (from https://pypi.org/simple/cartopy/) (requires-python:>=3.5): Requested cartopy==0.19.0.post1 from https://files.pythonhosted.org/packages/ed/ca/524ce33692df3faeaa56852fb6a33b0b410be94cc288417565b96fef3f64/Cartopy-0.19.0.post1.tar.gz#sha256=4b8b4773a98ed7009fe17d9b6ec87ac3ac62b7d14634d7768c190eadc647d576 has inconsistent version: filename has '0.19.0.post1', but metadata has '0.0'
ERROR: Could not find a version that satisfies the requirement cartopy==0.19.0.post1 (from versions: 0.11.0, 0.12.0.4, 0.12.0.5, 0.13.0, 0.13.1, 0.14.0, 0.14.2, 0.15.1, 0.16.0, 0.17.0, 0.18.0b1, 0.18.0b2, 0.18.0rc1, 0.18.0, 0.19.0rc1, 0.19.0.post1, 0.20.0, 0.20.1, 0.20.2)
ERROR: No matching distribution found for cartopy==0.19.0.post1
ERROR: Service 'quick-frontend' failed to build: The command '/bin/sh -c venv/bin/python -m pip install pykdtree scipy cartopy==0.19.0.post1' returned a non-zero code: 1
zachsa commented 2 years ago

Hi - following on from the linked thread (pypa/pipenv), is there a reason that updating the pip version would result in this?

Quba1 commented 2 years ago

@zachsa from what I read the issue is that the new resolver is more strict, and I suspect cartopy developers just missed setting a correct version somewhere.

89erik commented 2 years ago

This happened to me as well for cartopy==0.19.0.post1 and pip==21.0.1

matteius commented 2 years ago

I am not sure on the time-frame when this became an issue for you, but I notice some recent setuptools releases that may have affected things, because pip will pull in the latest setuptools. https://pypi.org/project/setuptools/#history From what I can tell, there is no version specified in the cartopy setup.py or setup.cfg or anywhere I thought to look in the project space, and that too seems like related to the issue.

pffijt commented 2 years ago

This is also happening to my team with cartopy==0.19.0.post1 and latest stable pip version. We used --use-deprecated=legacy-resolver as a temporary work around.

greglucas commented 2 years ago

I think this has something to do with the git folder not being present and setuptools_scm not being able to get the tagged version to replace somewhere along the line, yet it is present in other places of the build system, so some sort of miscommunication. Another workaround when installing from the downloaded sdist: SETUPTOOLS_SCM_PRETEND_VERSION="$(python3 setup.py --version)" pip install .

My guess is this is an "easy" fix for someone with knowledge of setuptools_scm / build machinery here.

jules-ch commented 2 years ago

I suspect we need to add "setuptools_scm[toml]>=6.2" with toml support since it fails after adding support for PEP517/518.

jules-ch commented 2 years ago

after running setuptools_scm getting this warning:

ERROR: setuptools==44.0.0 is used in combination with setuptools_scm>=6.x

Your build configuration is incomplete and previously worked by accident!
setuptools_scm requires setuptools>=45

This happens as setuptools is unable to replace itself when a activated build dependency
requires a more recent setuptools version
(it does not respect "setuptools>X" in setup_requires).

setuptools>=31 is required for setup.cfg metadata support
setuptools>=42 is required for pyproject.toml configuration support

Suggested workarounds if applicable:
 - preinstalling build dependencies like setuptools_scm before running setup.py
 - installing setuptools_scm using the system package manager to ensure consistency
 - migrating from the deprecated setup_requires mechanism to pep517/518
   and using a pyproject.toml to declare build dependencies
   which are reliably pre-installed before running the build tools

  warnings.warn(
Warning: could not use pyproject.toml, using default configuration.
 Reason: /home/jules/Code/cartopy/pyproject.toml does not contain a tool.setuptools_scm section.
0.20.1.dev132+g0af61639

IMO we need to update minimum setuptools requirements to properly support pyproject.toml installation. And add toml support and update setuptools_scm version + adding tool.setuptools_scm to pyproject.toml

jules-ch commented 2 years ago

After going down the rabbithole of pypi version resolution with setuptools_scm.

I can say with certitude the problem comes from having .git_archival.txt in the sdist.

FROM ubuntu:22.04

RUN apt-get update &&\
    apt-get install -y python3 python3-pip libproj-dev python3-venv

RUN apt-get install -y git libgeos-dev proj-bin gcc build-essential libgeos++-dev
RUN apt-get install wget

RUN pip3 install -U setuptools 
RUN pip3 install wheel
RUN python3 -m pip install -U pip

RUN wget -O /tmp/cartopy.tar.gz "https://files.pythonhosted.org/packages/f6/55/1e1c737dc9436b320deead73d1c455ddbb74b8b6992081863492f6f6378a/Cartopy-0.20.2.tar.gz"
RUN tar -xzvf /tmp/cartopy.tar.gz -C /tmp

RUN pip --version
RUN rm /tmp/Cartopy-0.20.2/.git_archival.txt
RUN pip install /tmp/Cartopy-0.20.2 -v

With .git_archival.txt, setuptools_scm retrieve the version as this:

version <Version('0.0')>
 version 0.0 -> 0.0
EntryPoint(name='.git_archival.txt', value='setuptools_scm.git:parse_archival', group='setuptools_scm.parse_scm_fallback') <ScmVersion 0.0 dist=None node=None dirty=False branch=None>

Without:

  found ep EntryPoint(name='PKG-INFO', value='setuptools_scm.hacks:parse_pkginfo', group='setuptools_scm.parse_scm_fallback') in /tmp/Cartopy-0.20.2
pkginfo /tmp/Cartopy-0.20.2/PKG-INFO
content 'Metadata-Version: 2.1\nName: Cartopy\nVersion: 0.20.2\nSummary: A cartographic python library with Matplotlib support for visualisation\nHome-page: https://scitools.org.uk/cartopy/docs/latest/\nAuthor: UK Met Office\nLicense: LGPLv3\nDownload-URL: https://github.com/SciTools/cartopy\nKeywords: cartography map transform projection proj proj.4 geos shapely shapefile\nPlatform: UNKNOWN\nClassifier: Development Status :: 4 - Beta\nClassifier: Framework :: Matplotlib\nClassifier: License :: OSI Approved :: GNU Lesser General Public License v3 or later (LGPLv3+)\nClassifier: Operating System :: MacOS :: MacOS X\nClassifier: Operating System :: Microsoft :: Windows\nClassifier: Operating System :: POSIX\nClassifier: Operating System :: POSIX :: AIX\nClassifier: Operating System :: POSIX :: Linux\nClassifier: Programming Language :: C++\nClassifier: Programming Language :: Python\nClassifier: Programming Language :: Python :: 3\nClassifier: Programming Language :: Python :: 3.7\nClassifier: Programming Language :: Python :: 3.8\nClassifier: Programming Language :: Python :: 3.9\nClassifier: Programming Language :: Python :: 3 :: Only\nClassifier: Topic :: Scientific/Engineering\nClassifier: Topic :: Scientific/Engineering :: GIS\nClassifier: Topic :: Scientific/Engineering :: Visualization\nRequires-Python: >=3.7\nDescription-Content-Type: text/markdown\nProvides-Extra: ows\nProvides-Extra: tests\nProvides-Extra: plotting\nLicense-File: COPYING\nLicense-File: COPYING.LESSER\n\n<h1 align="center" style="margin:1em;">\n  <a href="https://scitools.org.uk/cartopy/docs/latest/">\n    <img src="https://scitools.org.uk/cartopy/docs/latest/_static/cartopy.png"\n         alt="Cartopy"></a>\n</h1>\n\n<h4 align="center">\n    Cartopy is a Python package designed to make drawing maps for\n    data analysis and visualisation easy.\n</h4>\n\n<p align="center">\n<!-- https://shields.io/ is a good source of these -->\n<a href="https://anaconda.org/conda-forge/cartopy">\n<img src="https://img.shields.io/conda/dn/conda-forge/cartopy.svg"\n alt="conda-forge downloads" /></a>\n<a href="https://github.com/SciTools/cartopy/releases">\n<img src="https://img.shields.io/github/tag/SciTools/cartopy.svg"\n alt="Latest version" /></a>\n<a href="https://github.com/SciTools/cartopy/commits/master">\n<img src="https://img.shields.io/github/commits-since/SciTools/cartopy/latest.svg"\n alt="Commits since last release" /></a>\n<a href="https://github.com/SciTools/cartopy/graphs/contributors">\n<img src="https://img.shields.io/github/contributors/SciTools/cartopy.svg"\n alt="# contributors" /></a>\n<a href="https://travis-ci.org/SciTools/cartopy/branches">\n<img src="https://api.travis-ci.org/repositories/SciTools/cartopy.svg?branch=master"\n alt="Travis-CI" /></a>\n<a href="https://zenodo.org/badge/latestdoi/5282596">\n<img src="https://zenodo.org/badge/5282596.svg"\n alt="zenodo" /></a>\n<a href="https://gitter.im/SciTools/cartopy?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge">\n<img src="https://badges.gitter.im/SciTools/cartopy.svg" alt="Gitter Chat" /></a>\n</p>\n<br>\n\n# Table of contents\n\n<!--\nNOTE: toc auto-generated with https://github.com/jonschlinkert/markdown-toc\n    $> markdown-toc -i --bullets=\'-\' README.md\n\nNOTE: This entire README can be markdown linted with\n    https://github.com/igorshubovych/markdownlint-cli\n    $ echo \'{"no-inline-html": false}\' > .markdownrc\n    $ markdownlint README.md\n-->\n\n<!-- toc -->\n\n- [Overview](#overview)\n- [Get in touch](#get-in-touch)\n- [License and copyright](#license-and-copyright)\n\n<!-- tocstop -->\n\n## Overview\n\nCartopy is a Python package designed to make drawing maps for data\nanalysis and visualisation easy.\n\nIt features:\n\n- object oriented projection definitions\n- point, line, polygon and image transformations between projections\n- integration to expose advanced mapping in Matplotlib with a simple and\n  intuitive interface\n- powerful vector data handling by integrating shapefile reading with Shapely\n  capabilities\n\nDocumentation can be found at <https://scitools.org.uk/cartopy/docs/latest/>.\n\n## Get in touch\n\n- Ask usage questions on\n  [StackOverflow](https://stackoverflow.com/questions/tagged/cartopy).\n- For less well defined questions, ideas, general discussion or announcements\n  of related projects use the\n  [Google Group](https://groups.google.com/forum/#!forum/scitools-iris).\n- Report bugs, suggest features or view the source code on\n  [GitHub](https://github.com/SciTools/cartopy).\n- To chat with developers and other users you can use the\n  [Gitter Chat](https://gitter.im/SciTools/cartopy)\n\n\n## Credits, copyright and license\n\nCartopy is developed collaboratively under the SciTools umberella.\n\nA full list of codecontributors ("Cartopy contributors") can be found at\nhttps://github.com/SciTools/cartopy/graphs/contributors.\n\nCode is just one of many ways of positively contributing to Cartopy, please see\nour [contributing guide](.github/CONTRIBUTING.md) for more details on how\nyou can get involved.\n\nCartopy is released under a LGPL license with a shared copyright model.\nSee [COPYING](COPYING) and [COPYING.LESSER](COPYING.LESSER) for full terms.\n\nThe [Met Office](https://metoffice.gov.uk) has made a significant\ncontribution to the development, maintenance and support of this library.\nAll Met Office contributions are copyright on behalf of the British Crown.\n\n\n'
 data {'Metadata-Version': '2.1', 'Name': 'Cartopy', 'Version': '0.20.2', 'Summary': 'A cartographic python library with Matplotlib support for visualisation', 'Home-page': 'https://scitools.org.uk/cartopy/docs/latest/', 'Author': 'UK Met Office', 'License': 'LGPLv3', 'Download-URL': 'https://github.com/SciTools/cartopy', 'Keywords': 'cartography map transform projection proj proj.4 geos shapely shapefile', 'Platform': 'UNKNOWN', 'Classifier': 'Topic :: Scientific/Engineering :: Visualization', 'Requires-Python': '>=3.7', 'Description-Content-Type': 'text/markdown', 'Provides-Extra': 'plotting', 'License-File': 'COPYING.LESSER', 'NOTE': 'This entire README can be markdown linted with', '    $ echo \'{"no-inline-html"': "false}' > .markdownrc"}
version 0.20.2 -> 0.20.2
EntryPoint(name='PKG-INFO', value='setuptools_scm.hacks:parse_pkginfo', group='setuptools_scm.parse_scm_fallback') <ScmVersion 0.20.2 dist=None node=None dirty=False branch=None>
scm version <ScmVersion 0.20.2 dist=None node=None dirty=False branch=None>
greglucas commented 2 years ago

Thanks @jules-ch, are you willing to open up a PR removing that and updating the pins? It does look like the git-archival.txt and that dependency should be removed because it is natively supported by setuptools_scm: https://github.com/Changaco/setuptools_scm_git_archive

dopplershift commented 2 years ago

We should be able to make a 0.20.2.post1 if we get that in.

dopplershift commented 2 years ago

I went ahead and made #2057 with @jules-ch' s fix so we can try to get this out there ASAP. Thanks for identifying @jules-ch!

greglucas commented 2 years ago

I was able to pip install --upgrade cartopy and get v0.20.3 now. Thanks, @jules-ch and @dopplershift for figuring out the fix and getting a release out so quickly.

rbaard1 commented 1 year ago

Unfortunately I am still getting the same error with Cartopy v0.21.0: expected '0.21.0', but metadata has '0.0.0'. Should I open a new issue for this?

macOS 12.6 pip v22.3.1 Python 3.10.8

dopplershift commented 1 year ago

@rbaard1 Please open a new issue and include the full command you're using to install Cartopy as well as the full output from running that command.