Basemap cannot find basemap-data-hires - python

I need to draw maps in High resolution in python. Basemap and basemap-data-hires are both installed, but basemap does not find the basemap-data-hires.
Both are installed as you can see from this conda list:
packages in environment at /home/paloma/anaconda3/envs/PAG2019:
Name Version Build Channel
basemap 1.2.0 py36h705c2d8_0 anaconda
basemap-data-hires 1.2.0 0 conda-forge
gst-plugins-base 1.14.0 hbbd80ab_1 anaconda
Suspecting a conflicting/wrong installation, I tried to re-install basemap-data-hires from anaconda and conda-forge, but to no avail.
Here is the import I use:
from mpl_toolkits.basemap import Basemap
Here is the error message I get:
Traceback (most recent call last):
File "./MakeGraphs.py", line 89, in <module>
lat_ts=0.5*(lats[0,0]+lats[-1,-1]),lat_0=0.5*(lats[0,0]+lats[-1,-1]),lon_0=0.5*(lons[0,0]+lons[-1,-1]))
File "/home/paloma/anaconda3/lib/python3.7/site-packages/mpl_toolkits/basemap/__init__.py", line 1122, in __init__
self._readboundarydata('gshhs',as_polygons=True)
File "/home/paloma/anaconda3/lib/python3.7/site-packages/mpl_toolkits/basemap/__init__.py", line 1236, in _readboundarydata
raise IOError(msg)
OSError: Unable to open boundary dataset file. Only the 'crude' and 'low',
resolution datasets are installed by default.
If you are requesting an, 'intermediate', 'high' or 'full'
resolution dataset, you may need to download and install those
files separately with
`conda install basemap-data-hires`.
Any idea anyone??
On closer look, there's probably a conflict between the CONDA_PREFIX of the environment:
$CONDA_PREFIX=/home/paloma/anaconda3/envs/PAG2019
and the basemap_datadir of basemap:
basemap_datadir=/home/paloma/anaconda3/
Does some know how to solve that?

For installing 'intermediate', 'high' or 'full' use the following command:
conda install -c conda-forge basemap-data-hires
Otherwise you will have 'crude' and 'low' only, installed by default.

As basemap went to look for the files in the directory of the base environment, installing basemap-data-hires in the base worked for me.
Quick and dirty, but effective.

Related

AttributeError: module 'matplotlib' has no attribute 'get_data_path'

I am using xlwings for running a macro from Excel to plot histogram using python matplotlib but I get the following error when trying to run the python code to plot the histogram from excel:
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "c:\users\adel.moustafa\dashboard\main.py", line 7, in <module>
from Modules import Plotter
File "c:\users\adel.moustafa\dashboard\Modules\Plotter.py", line 6, in <module>
import matplotlib.pyplot as plt
File "C:\Users\adel.moustafa\AppData\Local\Programs\Python\Python311\Lib\site-packages\matplotlib\__init__.py", line 887, in <module>
cbook._get_data_path("matplotlibrc"),
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\adel.moustafa\AppData\Local\Programs\Python\Python311\Lib\site-packages\matplotlib\cbook\__init__.py", line 559, in _get_data_path
return Path(matplotlib.get_data_path(), *args)
^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: module 'matplotlib' has no attribute 'get_data_path'
This only happens when I try to run the python code from excel using macro, however if run the same code from Pycharm IDE it works fine and no error is produced.
I have looked for this error and what it means and reach the conclusion of that the error source may be due to conflict of matplotlib versions (one installed using conda and the other using pip). so I have completely removed install anaconda distribution using this guide after that I uninstall and reinstall matplotlib using pip but unfortunately that did not solve the problem. so, I continue to search and found similar posts to my case that advice by using a python virtual environment to solve the problem. so, I have done that but also with no result. finally I completely removed python from my system and reinstalled it but that did not solve the problem either. now, I really don't know what else to do or try!. so if any one could help it would much appreciated.
here is the list of packages installed on my machine
Package Version
--------------- --------
contourpy 1.0.7
cycler 0.11.0
fonttools 4.38.0
kiwisolver 1.4.4
matplotlib 3.6.3
numpy 1.24.1
packaging 23.0
pandas 1.5.3
Pillow 9.4.0
pip 22.3.1
pyparsing 3.0.9
python-dateutil 2.8.2
pytz 2022.7.1
pywin32 305
seaborn 0.12.2
setuptools 65.6.3
six 1.16.0
wheel 0.38.4
xlwings 0.28.9
and the python version
Python 3.11.1
finally here is the posts that I looked at.
post1
post2
post3
post4
post5

basemap-data-hires not found despite being installed

I have the same problem as this post:
Declaring a var usable by another function using a import in a secondary script, but the answer does not work on my side.
For context: basemap and basemap-data-hires are installed, yet when using resolution = 'f' it triggers the following error:
OSError: Unable to open boundary dataset file. Only the 'crude' and 'low',
resolution datasets are installed by default.
If you are requesting an, 'intermediate', 'high' or 'full'
resolution dataset, you may need to download and install those
files separately with
conda install -c conda-forge basemap-data-hires.
Here is the conda list output:
C:\Users\AlxndrLhr>conda list
# packages in environment at C:\Users\AlxndrLhr\Anaconda3\envs\map:
#
# Name Version Build Channel
basemap 1.2.2 py39h689385a_5 conda-forge
basemap-data 1.3.2 pyhd8ed1ab_0 conda-forge
basemap-data-hires 1.3.2 pyhd8ed1ab_0 conda-forge
As you can see, basemap-data-hires is present. I tried installing it in the base environment of conda, didn't work either.
Before basemap 1.3.0, the library was packaged in conda-forge by splitting the heavy data files into a separate basemap-data-hires conda package (and whose files were installed in the share folder).
Since basemap 1.3.0, a complete reorganisation of the basemap package has been done upstream by splitting the library into basemap, basemap-data and basemap-data-hires. These three packages are Python packages and get installed in the corresponding Python site-packages folder. This new structuring is propagated to the conda-forge packages.
Your installation is mixing the old basemap conda package (pre-1.3.0) with the new basemap-data-hires conda package (post-1.3.0). You can solve the issue by pinning versions during installation, either the following to install the latest basemap:
conda install "basemap>=1.3.0" "basemap-data-hires>=1.3.0"
or the following to install the pre-1.3.0 version:
conda install "basemap==1.2.2" "basemap-data-hires==1.2.2"

ValueError: Duplicate plugins for name projector

Running tensorboard --logdir log_dir I get an error:
Traceback (most recent call last):
File "/home/user/.local/bin/tensorboard", line 11, in <module>
sys.exit(run_main())
File "/home/user/.local/lib/python3.6/site-packages/tensorboard/main.py", line 64, in run_main
app.run(tensorboard.main, flags_parser=tensorboard.configure)
File "/home/user/.local/lib/python3.6/site-packages/absl/app.py", line 300, in run
_run_main(main, args)
File "/home/user/.local/lib/python3.6/site-packages/absl/app.py", line 251, in _run_main
sys.exit(main(argv))
File "/home/user/.local/lib/python3.6/site-packages/tensorboard/program.py", line 228, in main
server = self._make_server()
File "/home/user/.local/lib/python3.6/site-packages/tensorboard/program.py", line 309, in _make_server
self.assets_zip_provider)
File "/home/user/.local/lib/python3.6/site-packages/tensorboard/backend/application.py", line 161, in standard_tensorboard_wsgi
reload_task)
File "/home/user/.local/lib/python3.6/site-packages/tensorboard/backend/application.py", line 194, in TensorBoardWSGIApp
return TensorBoardWSGI(plugins, path_prefix)
File "/home/user/.local/lib/python3.6/site-packages/tensorboard/backend/application.py", line 245, in __init__
raise ValueError('Duplicate plugins for name %s' % plugin.plugin_name)
ValueError: Duplicate plugins for name projector
What can be a reason of this problem?
If you have two versions of tensorboard installed in your system,you need to uninstall one of them.
I was stuck this for hours but I finally fixed it using:
Worked like a charm:
https://github.com/pytorch/pytorch/issues/22676
pip uninstall tb-nightly tensorboardX tensorboard
pip install tensorboard
I ran into the same issue after installing tensorflow==2.0.0-rc2. Uninstalling tensorboard did not help.
The culprit in my case was tb-nightly package:
#python3.7 -m pip list | grep tb
tb-nightly 1.15.0a20190806
After removing the package and reinstalling TensorFlow, tensorboard started to work properly.
I got same error, when I had two versions of tensorboard. In my Tensorflow 2.0 environmnet, except core Tensorflow lib, I could see other libs where installed from TF 1.14 version.
Do a pip list and see what versions of tensorflow libs are there. In my system I had
...
tensorboard 1.14.0
tensorflow-estimator 1.14.0
tensorflow-gpu 2.0.0rc0
tensorflow-serving-api 1.14.0
termcolor 1.1.0
tf-estimator-nightly 1.14.0.dev2019080601
...
Here is what I did:
pip uninstall tensorboard
pip install --force-reinstall tf-nightly-2.0-preview
Run the following code if it shows two tensorboard installed on your system remove one.
import pkg_resources
for entry_point in pkg_resources.iter_entry_points('tensorboard_plugins'):
print(entry_point.dist)
It took me a day to figure it out finally.
In my case there were two folders for tensorboard at
** C:\ProgramData\Anaconda3\Lib\site-packages\ **
Keep the tensorboard folder for your preferred version and delete the other.
For Ubuntu users, go to: /home/$USERNAME/.local/lib/python3.8/site-packages/ or whatever path is displayed in the error.
There you will see 2 folders with names something like this tensorboard and tensorboad-2.5.0.dist-info. Remove the second one.
One easy workaround for these sorts of issues is to call tensorboard via python -m tensorboard.main. For example, replace tensorboard --logdir ./model --port 6006 with python -m tensorboard.main --logdir ./model --port 6006. Much easier!
For me what worked was to uninstall the nightly build which is usually installed with pip since tf is usually installed with pip:
pip uninstall tb-nightly
then I installed tensorboard with conda
conda install -y -c conda-forge tensorboard
note I am using pytorch with tensorboard: https://pytorch.org/tutorials/recipes/recipes/tensorboard_with_pytorch.html
I did not need to install tensorflow but I did it in a second test since it was complaining about not having full features:
pip install tensorflow
since for some reason conda doesn't instlal tensorflow well (I tried it with conda-forge -c channel and it took to long to do anything).
Note you might need to uninstall more stuff as the answer https://stackoverflow.com/a/59408145/1601580:
pip uninstall tb-nightly tensorboardX tensorboard
suggested
I have faced the same problem. I found the problem creator was tb-nightly.
I had installed it to resolve "Cannot start tensorboard in Jupyter Notebook"
problem but after one day it arises "duplicate plugins for name projector" error.
I have tried pip uninstall tb-nightly but unfortunately it didn't work for me. The jupyter notebook was stacked in running.
Finally,I went to my site-packages folderC:\Users\User\anaconda3\Lib\site-packages and delete the tb-nightly folder,as well as from RecycleBin and it worked.
In short: You are very likely to have both tb-nightly and tensorboard installed. Nightly dependencies can easily mess thing sup.
Uninstall BOTH:
pip uninstall tb-nightly tensorboard
And install one that is compatible with your TF version (either tensorboard or tb-nightly):
pip install tensorboard # or tb-nightly

'ImportError: cannot import name cbook' when using PyCharm's Profiler

I am trying to run the PyCharm profiler but I get the following error message:
Traceback (most recent call last):
File "/home/b3053674/ProgramFiles/pycharm-2017.1.4/helpers/profiler/run_profiler.py", line 164, in <module>
profiler.run(file)
File "/home/b3053674/ProgramFiles/pycharm-2017.1.4/helpers/profiler/run_profiler.py", line 89, in run
execfile(file, globals, globals) # execute the script
File "/home/b3053674/Documents/pycotools/pycotools/tasks.py", line 38, in <module>
import viz,errors, misc, _base, model
File "/home/b3053674/Documents/pycotools/pycotools/viz.py", line 53, in <module>
import matplotlib.pyplot as plt
File "/home/b3053674/anaconda2/envs/pycotools/lib/python2.7/site-packages/matplotlib/__init__.py", line 124, in <module>
from . import cbook
ImportError: cannot import name cbook
Snapshot saved to /home/b3053674/.PyCharm2017.1/system/snapshots/pycotools30.pstat
Process finished with exit code 1
I am using a conda environment which I have switched to in the terminal:
$ source activate <env>
then updated matplotlib
$pip install matplotlib --upgrade
and six just for good measure
$pip install six --upgrade
(note that I've also manually deleted these packages from site-directory of my environment and reinstalled just incase --upgrade wasn't behaving)
I've looked here and here and neither solutions solved my problem.
I've also switched the PyCharm Run configurations to use each of my conda environments in turn all of which produce the same error.
Note that the profiler has worked before in the past and the code works fine when I use the normal way of executing the code. Does anybody have any idea of what is going on?
Thanks
I encountered the same error today, although probably for a different reason - the packages for matplotlib and/or six appear to be broken.
Resolved it by downgrading to the previous versions:
conda install six=1.10.0
conda install matplotlib=2.0.2
I had the same issue.
Downgrading to matplotlib 2.0.2 seems to fix it.
pip uninstall matplotlib
pip install matplotlib==2.0.2
I had this error in jupyter but not IPython. Fixed with $ conda install matplotlib=2.0.2 as above but six not downgraded. Don't forget (as I did) to restart the kernel.

Unable to import python modules (numpy, scipy, matplotlib)

I've used the following tutorial to install Python, numpy, scipy and matplotlib:
https://penandpants.com/2012/03/01/install-python-2/
I downloaded each and installed by double-clicking. I'm using a Mac with OS X Yosemite Version 10.10.5
When I try to import numpy, scipy and matplotlib in IDLE I get the follow error message:
`>>> import numpy
Traceback (most recent call last):
File "<pyshell#2>", line 1, in <module>
import numpy
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/numpy/__init__.py", line 137, in <module>
import add_newdocs
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/numpy/add_newdocs.py", line 9, in <module>
from numpy.lib import add_newdoc
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/numpy/lib/__init__.py", line 4, in <module>
from type_check import *
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/numpy/lib/type_check.py", line 8, in <module>
import numpy.core.numeric as _nx
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/numpy/core/__init__.py", line 5, in <module>
import multiarray
ImportError: dlopen(/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/numpy/core/multiarray.so, 2): no suitable image found. Did find:
/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/numpy/core/multiarray.so: no matching architecture in universal wrapper`
Can anyone please explain to me how to resolve this?
Thanks
use terminal and type
sudo pip install numpy
sudo pip install matplotlib
sudo pip install scipy
for python3+ use pip3
I can't say for sure what's wrong with your installation, but I suspect it's due to a some PATH-conusion... Python 2.7 and Numpy should be installed on your Mac by default.
If you run the command which python, you'll see which executable the python-commands invokes... is it the same as the one you installed?
If you write python in the terminal, and press tab twice, do you see multiple options of installed python versions?
Alternative method of installation
I prefer the Anaconda Python Distribution, which you can download like the full version or minimal version, which is the one I prefer.
If you install this, you should consider uninstalling the one you just installed.
Here's how to install the mini version:
Download the installer, and run it by opening a terminal in the folder with the installer, and running the command bash Miniconda2-latest-MacOSX-x86_64.sh. This will start the text-based installer, and if you read the instructions on screen, you'll be fine.
Notice that you have to scroll to the end of the licence agreement, before you can write yes when asked to accept the terms stated.
Say yes when it asked you if you'd like it to add Anaconda Python to your path.
Anaconda Python is different from other python distributions in the regard that it comes with it's own package and environment manager conda. With conda you can have multiple versions of Python installed at the same time (or several environments of the same Python version, but with different packages or versions of packages).
To create a new environment with the name py27, which is using Python 2.7, write conda create -n py27 python=2.7 --yes. Once created, activate the environment by source activate py27.
With the new environment now active, install the packages you need by using conda: conda install scipy matplotlib --yes.
I'd also recommend installing Ipython, which is an improved shell, and possibly the Jupyter notebook: conda install ipython --yes and conda install notebook --yes.
Hope it helps.

Categories

Resources