Python Basemap/Matplotlib Install - python

I am trying to install the base map for use with matplotlib python v2.7 running on Mac OSX Mavericks. I have all the latest versions of all modules (matplotlib, etc) running using anaconda, but keep getting the following error:
Traceback (most recent call last):
File "simpletest.py", line 1, in <module>
from mpl_toolkits.basemap import Basemap
File "/Users/felishalawrence/anaconda/lib/python2.7/site-packages/mpl_toolkits/basemap/__init__.py", line 37, in <module>
import _geoslib.so
ImportError: dlopen(/Users/felishalawrence/anaconda/lib/python2.7/site-packages/_geoslib.so, 2): Library not loaded: libgeos_c.1.dylib
Referenced from: /Users/felishalawrence/anaconda/lib/python2.7/site-packages/_geoslib.so
Reason: no suitable image found. Did find:
/usr/local/bin/gcc-4.9/libgeos_c.1.dylib: stat() failed with errno=20
Can someone please give me an idea of what is wrong? Thanks!

Try installing the following packages with Homebrew:
brew install numpy
brew install proj
brew install geos
export GEOS_DIR="/usr/local/Cellar/geos/3.10.3/"

Related

Can't load ecCodes library using python

I have installed ecCodes library with
pip install eccodes
When I check it with 'pip list' it seems like it is installed as 0.9.7 ver but command:
python -m eccodes selfcheck
Returns error
RuntimeError: Could not load the ecCodes library!
The same error occurs when I try to import eccodes. I am using Windows 10 and Python 3.7.6
Any thougths what is wrong?
Full error:
import eccodes
Traceback (most recent call last):
File "<ipython-input-1-cfa7540a6bb2>", line 1, in <module>
import eccodes
File "C:\Users\admin1\anaconda3\lib\site-packages\eccodes\__init__.py", line 15, in <module>
from .eccodes import *
File "C:\Users\admin1\anaconda3\lib\site-packages\eccodes\eccodes.py", line 12, in <module>
from gribapi import __version__
File "C:\Users\admin1\anaconda3\lib\site-packages\gribapi\__init__.py", line 13, in <module>
from .gribapi import * # noqa
File "C:\Users\admin1\anaconda3\lib\site-packages\gribapi\gribapi.py", line 2217, in <module>
__version__ = grib_get_api_version()
File "C:\Users\admin1\anaconda3\lib\site-packages\gribapi\gribapi.py", line 2207, in grib_get_api_version
raise RuntimeError("Could not load the ecCodes library!")
RuntimeError: Could not load the ecCodes library!
The python package eccodes is only a binding to the C library eccodes made by ECMWF.
https://confluence.ecmwf.int/display/ECC/ecCodes+installation
As you can read on this website, they do not support Windows.
Advise from me: you won't get happy reading grib files (and working with meteorological data in general) on Windows. You could consider using Ubuntu or another Linux distro, maybe also just on a VM.
There is a conda package eccodes for the C library:
conda install -c conda-forge eccodes
Alternately, you can install those outside of your conda environment, for example, by compiling from source.
Then there is a pypi package eccodes that contains only the Python bindings:
pip install eccodes
You need both! From your error message, it seems that you have the Python bindings, but not the underlying C library.
For more (slightly dated) information, see the ECMWF Confluence wiki:
https://confluence.ecmwf.int/display/UDOC/How+to+install+ecCodes+with+Python+bindings+in+conda+-+ecCodes+FAQ

I am unable to import psycopg2 from Jupyter notebook or Jupyter Lab on Mac. I have a clean install of Catalina

A similar report was posted, but the suggested solutions do not work.
---- from Jupyter ----
Import psycopg2
ModuleNotFoundError Traceback (most recent call last)
<ipython-input-2-7d2da0a5d979> in <module>
----> 1 import psycopg2
ModuleNotFoundError: No module named 'psycopg2'
If I run python3 from Mac terminal and then import psycopg2 that works.
If I run python3 from Jupyterlab terminal this does not work. I get the following error after running import pyscopg2
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/psycopg2/__init__.py", line 50, in <module>
from psycopg2._psycopg import ( # noqa
ImportError: dlopen(/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/psycopg2/_psycopg.cpython-38-darwin.so, 2): Library not loaded: #rpath/libssl.1.1.dylib
Referenced from: /Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/psycopg2/_psycopg.cpython-38-darwin.so
Reason: image not found
echo $PATH from Mac terminal is
/Users/greg/opt/miniconda3/bin:/Users/greg/opt/anaconda3/condabin:/Library/Frameworks/Python.framework/Versions/3.8/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin
echo $PATH from Jupyterlab terminal is
/Library/Frameworks/Python.framework/Versions/3.8/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Users/greg/opt/miniconda3/bin:/Users/greg/opt/anaconda3/condabin
These look the same, just in a different order.
I have tried pip install psycopg2 both with and without the binary option.Either way, it says already satisfied.
I have tried
conda install -c anaconda psycopg2
Also tried installing postgresql both from the postgresql.org, and brew install psycopg2. Both worked, but no luck with Jupyterlab.
try installing the package using: pip install psycopg2-binary. This should work.
For more information, visit: https://www.psycopg.org/docs/install.html

python3 openCV install error: Symbol not found: _clock_gettime

Can anyone help me fixing an error when importing opencv in python3?
when I import cv2 in python3, I get something like
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-
packages/cv2/__init__.py", line 4, in <module>
from .cv2 import *
ImportError: dlopen(/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/cv2/cv2.cpython-36m-darwin.so, 2):
Symbol not found: _clock_gettime
Referenced from: /Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/cv2/.dylibs/libavutil.55.78.100.dylib
(which was built for Mac OS X 10.12)
Expected in: /usr/lib/libSystem.B.dylib
in /Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/cv2/.dylibs/libavutil.55.78.100.dylib
Also, I'm using python version 3.6.3
If you don't want to upgrade your OS, you can install an earlier version of opencv:
pip install opencv-python==3.3.0.10
clock_gettime() was added in macOS 10.12. It says so in the error message.
From what I understand it may be possible to build against an earlier Xcode SDK, but the easiest is probably to upgrade to Mac's latest OS.

Numpy and OpenCV

I'm tired to import cv and numpy and get errors. I started importing cv and I got this error:
ImportError: numpy.core.multiarray failed to import
Traceback (most recent call last):
File "", line 1, in <module>
File "/usr/lib/pymodules/python2.7/cv.py", line 1, in <module>
from cv2.cv import *
ImportError: numpy.core.multiarray failed to import
So I installed numpy on Ubuntu using:
apt-get install python-numpy
So when I import numpy I get:
Traceback (most recent call last):
File "", line 1, in <module>
File "numpy/init.py", line 127, in <module>
raise ImportError(msg)
ImportError: Error importing numpy: you should not try to import numpy from
its source directory; please exit the numpy source tree, and relaunch
your python intepreter from there.
I really need help. I'm using Python 2.7.3 on Ubuntu.
There is nothing wrong with installing common dependencies using your operating system's package manager, remember using pip means your synaptic updates won't update your Python libraries and pip won't leverage the dependencies already taken care of by aptitude. For python packages with C extensions like numpy and opencv its probably better to use apt-get.
In Ubuntu you can install both dependencies with
sudo apt-get install python-numpy python-opencv
The actual Python error you are getting indicates what is wrong, namely that you are executing from within the numpy source directory, or have a file named numpy.py in your current directory which is confusing things at import time. Try change into an empty directory, start Python import your libraries:
import numpy
import cv
Hope that helps.
It's better that use some package management tool such like pip to install numpy.
For example,
pip install numpy

Gdal will not import after several installs (Mac OSX)

Using Macports,
I've tried to install: gdal, py27gdal, and gdal-grass. All so I can import gdal into python 2.7.2.
Neither have been successful.
When I type:
port list installed
I see the installed modules:
gdal-grass #1.4.3 gis/gdal-grass
gdbm #1.8.3 databases/gdbm
py27-gdal #1.7.1 python/py27-gdal
And when I run python to import the module:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named gdal
What am I doing wrong?
Are you using the MacPorts python2.7? Try launching Python this way:
/opt/local/bin/python2.7
I'm not 100% sure if this solves your problem, but gdal is in the osgeo namespace. So you should try importing gdal like this:
from osgeo import gdal
The gdal namespace itself is deprecated.

Categories