Home > Back-end >  Problem while installing geopandas with conda
Problem while installing geopandas with conda

Time:08-05

I wish to install geopandas with conda, as it is recommended by the manual.

https://geopandas.org/en/stable/getting_started/install.html

I am working on Linux Ubuntu 22.04 LTS with Python 3.7.4. I have tried to install geopandas with the following commands:

conda install geopandas
conda install --channel conda-forge geopandas
conda install python=3 geopandas

But it always end up with this error message:

Collecting package metadata (current_repodata.json): done Solving environment: failed with initial frozen solve. Retrying with flexible solve. 
Solving environment: failed with repodata from current_repodata.json, will retry with next repodata source. 
Collecting package metadata (repodata.json): done Solving environment: failed with initial frozen solve. Retrying with flexible solve. 
Solving environment: / failed

Another attempt has been made creating an environment:

conda create -n geo_env
conda activate geo_env
conda config  --env --add channels conda-forge
conda config --env --set channel_priority strict
conda install geopandas

And it seems to work. Unfortunately, when trying to import the package in Python, the following error show:

>>> import geopandas
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/usr/anaconda3/lib/python3.7/site-packages/geopandas/__init__.py", line 1, in <module>
    from geopandas._config import options  # noqa
  File "/home/usr/anaconda3/lib/python3.7/site-packages/geopandas/_config.py", line 109, in <module>
    default_value=_default_use_pygeos(),
  File "/home/usr/anaconda3/lib/python3.7/site-packages/geopandas/_config.py", line 95, in _default_use_pygeos
    import geopandas._compat as compat
  File "/home/usr/anaconda3/lib/python3.7/site-packages/geopandas/_compat.py", line 8, in <module>
    import pandas as pd
  File "/home/usr/anaconda3/lib/python3.7/site-packages/pandas/__init__.py", line 142, in <module>
    from pandas.io.api import (
  File "/home/usr/anaconda3/lib/python3.7/site-packages/pandas/io/api.py", line 8, in <module>
    from pandas.io.excel import ExcelFile, ExcelWriter, read_excel
  File "/home/usr/anaconda3/lib/python3.7/site-packages/pandas/io/excel/__init__.py", line 1, in <module>
    from pandas.io.excel._base import ExcelFile, ExcelWriter, read_excel
  File "/home/usr/anaconda3/lib/python3.7/site-packages/pandas/io/excel/_base.py", line 32, in <module>
    from pandas.io.parsers import TextParser
  File "/home/usr/anaconda3/lib/python3.7/site-packages/pandas/io/parsers/__init__.py", line 1, in <module>
    from pandas.io.parsers.readers import (
  File "/home/usr/anaconda3/lib/python3.7/site-packages/pandas/io/parsers/readers.py", line 17, in <module>
    from pandas._typing import (
ImportError: cannot import name 'DtypeArg' from 'pandas._typing' (/home/usr/anaconda3/lib/python3.7/site-packages/pandas/_typing.py)

Would anyone have an idea what is the problem installing geopandas on my device?

CodePudding user response:

This error your getting is due to dependencies conflict

Collecting package metadata (current_repodata.json): done Solving environment: failed with initial frozen solve. Retrying with flexible solve.

Try creating a new env and install geopandas first, then your other packages.

CodePudding user response:

You're using anaconda, which comes with a ton of packages installed into your base env from the defaults channel, which is incompatible with conda-forge. essentially have two options:

  1. never use conda-forge. Booooo.

  2. (my recommendation) delete anaconda. I'd recommend installing miniconda and then installing packages only into environments. The only things that should ever be installed in your base env are cross-environment utilities, such as jupyter or IDEs which can select from multiple environments, or something like mamba which works directly with conda environments.

anaconda is a starter kit for people who want to get set up with a data science environment out of the box, but polluting your base env leads to big problems down the road, especially if you want to use packages from channels other than defaults.

And if you do decide to start from scratch, if you want to rip off the guardrails and do this much, much more quickly but with harder crashes and worse error messages - use mamba! It's a clone of conda written to be lightning fast and run in parallel. Since it's a clone of conda, if you ever get an error message in mamba, just rerun the command in conda. It might just suddenly work, or it might error but give you a much more helpful error message.

  • Related