basemap
basemap copied to clipboard
Pip is broken after installing Basemap "AttributeError: '_NamespacePath' object has no attribute 'sort'"
For some reason, https://github.com/matplotlib/basemap/commit/decfa95124dab76499734145d03b002b9db27477 breaks pip.
Running any pip command after installing Basemap from source returns this error. This can be reproduced with this Anaconda Dockerfile:
FROM continuumio/anaconda3:5.0.1
RUN apt-get update && \
apt-get install -y build-essential && \
conda update -y conda && \
conda update -y python && \
apt-get -y install libgeos-dev && \
pip install pyshp && \
pip install pyproj && \
cd /usr/local/src && \
export GEOS_DIR=/usr/local && \
git clone https://github.com/matplotlib/basemap.git && \
cd basemap && \
python setup.py install && \
pip -V
Finished processing dependencies for basemap==1.1.0
Traceback (most recent call last):
File "/opt/conda/bin/pip", line 7, in <module>
from pip import main
File "/opt/conda/lib/python3.6/site-packages/pip/__init__.py", line 26, in <module>
from pip.utils import get_installed_distributions, get_prog
File "/opt/conda/lib/python3.6/site-packages/pip/utils/__init__.py", line 27, in <module>
from pip._vendor import pkg_resources
File "/opt/conda/lib/python3.6/site-packages/pip/_vendor/pkg_resources/__init__.py", line 3018, in <module>
@_call_aside
File "/opt/conda/lib/python3.6/site-packages/pip/_vendor/pkg_resources/__init__.py", line 3004, in _call_aside
f(*args, **kwargs)
File "/opt/conda/lib/python3.6/site-packages/pip/_vendor/pkg_resources/__init__.py", line 3046, in _initialize_master_working_set
dist.activate(replace=False)
File "/opt/conda/lib/python3.6/site-packages/pip/_vendor/pkg_resources/__init__.py", line 2578, in activate
declare_namespace(pkg)
File "/opt/conda/lib/python3.6/site-packages/pip/_vendor/pkg_resources/__init__.py", line 2152, in declare_namespace
_handle_ns(packageName, path_item)
File "/opt/conda/lib/python3.6/site-packages/pip/_vendor/pkg_resources/__init__.py", line 2092, in _handle_ns
_rebuild_mod_path(path, packageName, module)
File "/opt/conda/lib/python3.6/site-packages/pip/_vendor/pkg_resources/__init__.py", line 2121, in _rebuild_mod_path
orig_path.sort(key=position_in_sys_path)
AttributeError: '_NamespacePath' object has no attribute 'sort'
The command '/bin/sh -c apt-get update && apt-get install -y build-essential && conda update -y conda && conda update -y python && apt-get -y install libgeos-dev && pip install pyshp && pip install pyproj && cd /usr/local/src && export GEOS_DIR=/usr/local && git clone https://github.com/matplotlib/basemap.git && cd basemap && python setup.py install && pip -V' returned anon-zero code: 1
On 2018/05/09 2:08 PM, crawforc3 wrote:
|AttributeError: '_NamespacePath' object has no attribute 'sort'|
First Google hit indicates that it is a setuptools/pip version problem:
https://github.com/pypa/setuptools/issues/885
if you add 'pip install pip --upgrade' after python install it works:
# pip -V
pip 10.0.1 from /opt/conda/lib/python3.6/site-packages/pip (python 3.6)
I modified the Dockerfile to upgrade pip and install GEOS from source (https://matplotlib.org/basemap/users/installing.html)
I now get a "ModuleNotFoundError" error when importing Basemap
Traceback (most recent call last):
File "<string>", line 1, in <module>
ModuleNotFoundError: No module named 'mpl_toolkits.basemap'
Installing basemap with conda works, so maybe I'm installing to the wrong path?
Updated Dockerfile:
RUN apt-get update && \
#apt-get -y install libgeos-dev && \
pip install matplotlib && \
pip install pyshp && \
pip install pyproj && \
cd /usr/local/src && git clone https://github.com/matplotlib/basemap.git && \
cd basemap/geos-3.3.3 && \
export GEOS_DIR=/usr/local && \
./configure --prefix=$GEOS_DIR && \
make && make install && \
cd .. && python setup.py install && \
# Pillow (PIL)
apt-get -y install zlib1g-dev liblcms2-dev libwebp-dev && \
pip install Pillow && \
python -c "from mpl_toolkits.basemap import Basemap"
@crawforc3 Could you check if the problem persists? I cannot reproduce it with the latest version of basemap (note that you can install it now directly with pip because PyPI stores manylinux wheels):
RUN apt-get update && \
conda update -y conda && \
conda update -y python && \
pip install --upgrade pip && \
pip install --upgrade matplotlib && \
pip install basemap && \
python -c "from mpl_toolkits.basemap import Basemap"
In particular, after this Docker RUN line, I am getting the following libraries installed:
- Python 3.6.3 :: Anaconda, Inc.
- pip 21.3.1 from /opt/conda/lib/python3.6/site-packages/pip (python 3.6)
- numpy: 1.19.5
- matplotlib: 3.3.4
- pyproj: 3.0.1
- pyshp: 2.1.3
- basemap: 1.3.1
The last command importing Basemap returns no error. I can also import the basemap package and print its version and it works:
root@fab3dd71c0cb:/# python -c "from mpl_toolkits import basemap; print(basemap.__version__)"
1.3.1
I am closing this issue due to lack of feedback and because it is not possible to reproduce with any recent version of basemap and its dependencies.