Python 3.4 crashes when creating some - but not all - card cards with a segmentation error of 11

I installed the Python Cartopy mapping tool on a Mac running El Capitan 10.11.6 with Python 3.4. I can use Cartopy to successfully build some maps, but in some cases the Python core dies with a segmentation error of 11.

I need an installation that I could easily remove from my computer if the need arises. So I installed Python 3.4 and the necessary dependencies using fink:

$ fink install python34
$ fink install gdal2
$ fink install gdal2-dev
$ fink install proj
$ fink install libproj9

Then I created a virtual environment using pyvenv (but also tried virtualenv and venv) and activated it.

In an activated virtual environment, I used pip to install:

$ pip install cython        # Successfully installed cython-0.25.2
$ pip install numpy         # Successfully installed numpy-1.12.1
$ pip install shapely       # Successfully installed shapely-1.5.17.post1
$ pip install pyshp         # Successfully installed pyshp-1.2.10
$ pip install pandas        # Successfully installed pandas-0.19.2 python-dateutil-2.6.0 pytz-2017.2 six-1.10.0
$ pip install matplotlib    # Successfully installed cycler-0.10.0 matplotlib-2.0.0 pyparsing-2.2.0
$ pip install pillow        # Successfully installed olefile-0.44 pillow-4.1.0
$ pip install pyepsg        # Successfully installed pyepsg-0.3.1
$ pip install scipy         # Successfully installed scipy-0.19.0
$ pip install OWSLib        # Successfully installed OWSLib-0.14.0 pyproj-1.9.5.1 requests-2.13.0
$ pip install mock          # Successfully installed mock-2.0.0 pbr-3.0.0
$ pip install nose          # Successfully installed nose-1.3.7
$ pip install pep8          # Successfully installed pep8-1.7.0
$ pip install jupyter       # Successfully installed MarkupSafe-1.0 appnope-0.1.0 backports-abc-0.5 bleach-2.0.0 decorator-4.0.11 entrypoints-0.2.2 html5lib-0.999999999 ipykernel-4.6.1 ipython-6.0.0 ipython-genutils-0.2.0 ipywidgets-6.0.0 jedi-0.10.2 jinja2-2.9.6 jsonschema-2.6.0 jupyter-1.0.0 jupyter-client-5.0.1 jupyter-console-5.1.0 jupyter-core-4.3.0 mistune-0.7.4 nbconvert-5.1.1 nbformat-4.3.0 notebook-5.0.0 pandocfilters-1.4.1 pexpect-4.2.1 pickleshare-0.7.4 prompt-toolkit-1.0.14 ptyprocess-0.5.1 pygments-2.2.0 pyzmq-16.0.2 qtconsole-4.3.0 simplegeneric-0.8.1 terminado-0.6 testpath-0.3 tornado-4.5.1 traitlets-4.3.2 typing-3.6.1 wcwidth-0.1.7 webencodings-0.5.1 widgetsnbextension-2.0.0

, , Cartopy, : http://scitools.org.uk/cartopy/docs/v0.15/installing.html

Cartopy, ( ) geos, fink:

pip install --global-option=build_ext --global-option="-I/sw/opt/libgeos3.5.0/include" --global-option="-L/sw/opt/libgeos3.5.0/lib"  cartopy
                             # Successfully installed cartopy-0.14.2

Python Jupyter, , Cartopy . - Cartopy, .

:

import matplotlib
matplotlib.use("TkAgg")
cartopy.crs as ccrs
import matplotlib.pyplot as plt
ax = plt.axes(projection=ccrs.Mollweide())
ax.stock_img()
plt.show()

:

import os
import matplotlib
matplotlib.use("TkAgg")
import matplotlib.pyplot as plt

from cartopy import config
import cartopy.crs as ccrs

fig = plt.figure(figsize=(8, 12))

# get the path of the file. It can be found in the repo data directory.
fname = os.path.join(config["repo_data_dir"],
                     'raster', 'sample', 'Miriam.A2012270.2050.2km.jpg'
                     )
img_extent = (-120.67660000000001, -106.32104523100001, 13.2301484511245, 30.766899999999502)
img = plt.imread(fname)

ax = plt.axes(projection=ccrs.PlateCarree())
plt.title('Hurricane Miriam from the Aqua/MODIS satellite\n'
          '2012 09/26/2012 20:50 UTC')

# set a margin around the data
ax.set_xmargin(0.05)
ax.set_ymargin(0.10)

# add the image. Because this image was a tif, the "origin" of the image is in the
# upper left corner
ax.imshow(img, origin='upper', extent=img_extent, transform=ccrs.PlateCarree())
ax.coastlines(resolution='50m', color='black', linewidth=1)

# mark a known place to help us geo-locate ourselves
ax.plot(-117.1625, 32.715, 'bo', markersize=7, transform=ccrs.Geodetic())
ax.text(-117, 33, 'San Diego', transform=ccrs.Geodetic())

plt.show()

:

import matplotlib
matplotlib.use("TkAgg")
import matplotlib.pyplot as plt
import cartopy

ax = plt.axes(projection=cartopy.crs.PlateCarree())

ax.add_feature(cartopy.feature.LAND)
ax.add_feature(cartopy.feature.OCEAN)
ax.add_feature(cartopy.feature.COASTLINE)
ax.add_feature(cartopy.feature.BORDERS, linestyle=':')
ax.add_feature(cartopy.feature.LAKES, alpha=0.5)
ax.add_feature(cartopy.feature.RIVERS)

ax.set_extent([-20, 60, -40, 40])

plt.show()

, , .

, :

Segmentation fault: 11

- ?

+5
2

- , . , .

Cartopy GitHub (https://github.com/SciTools/cartopy/issues/879), QuLogic , :

pip uninstall shapely; pip install --no-binary :all: shapely

11, "" , , geos_c , . :

OSError: Could not find lib geos_c or load any of its variants ['/Library/Frameworks/GEOS.framework/Versions/Current/GEOS', '/opt/local/lib/libgeos_c.dylib'].

, , fink , .bash_profile. , , Fink. , . (. Jace Browning OSError geos_c Shapely).

, , - . .

  • ( ) Mac OS 10.11.6 (El Capitan), iMac. .

  • Python 3.6 , python.org

  • admin, fink gdal2, gdal2-dev, libproj9, libgeos3.6.1. ( fink python3.6, gdal-py36, freetype, freetype219, cairo, gsl, sqlite3 libspatialite7, , .)

  • Python 3.6 /Library/Frameworks/Python.framework/Versions/3.6/bin/python3.6. ( venv36) -m venv :

:

$ mkdir <name_of_directory_for_virtual_env>
$ cd <name_of_directory_for_virtual_env>
$ /Library/Frameworks/Python.framework/Versions/3.6/bin/python3.6 -m venv venv36
  1. nano .bash_profile, , fink libgeos3.6.1:

:

$ cd
$ nano .bash_profile

.bash_profile (ctrl-O):

GEOS_CONFIG="/sw/opt/libgeos3.6.1/bin/geos-config"; export GEOS_CONFIG
GEOS_DIR="/sw/opt/libgeos3.6.1"; export GEOS_DIR
  1. . pandas jupyter , ?

:

$ cd <path_to_virtual_environment>
$ source venv36/bin/activate

(venv36) $ pip install cython
(venv36) $ pip install numpy
(venv36) $ pip install --no-binary :all: shapely
(venv36) $ pip install pyshp
(venv36) $ pip install pyproj
(venv36) $ pip install six
(venv36) $ pip install matplotlib

(venv36) $ export CPLUS_INCLUDE_PATH=/sw/include/gdal2/
(venv36) $ export C_INCLUDE_PATH=/sw/include/gdal2/
(venv36) $ pip install gdal
(venv36) $ pip install pillow
(venv36) $ pip install pyepsg
(venv36) $ pip install scipy
(venv36) $ pip install OWSLib
(venv36) $ pip install mock nose pep8
(venv36) $ pip install pandas
(venv36) $ pip install jupyter

(venv36) $ pip install --global-option=build_ext --global-option="-I/sw/opt/libgeos3.6.1/include" --global-option="-L/sw/opt/libgeos3.6.1/lib"  cartopy
  1. , ​​ /opt/local/lib/( cartopy - - libgeos), libgeos, fink ( libgeos_c.1.dylib). , /opt/local/lib ( ), .

:

$ cd /opt/local/lib
$ sudo ln -s /sw/opt/libgeos3.6.1/lib/libgeos_c.1.dylib libgeos_c.dylib

. jupyter-notebook. , , , :

%matplotlib inline

:

import cartopy
import matplotlib.pyplot as plt

ax = plt.axes(projection=cartopy.crs.PlateCarree())

ax.add_feature(cartopy.feature.LAND)
ax.add_feature(cartopy.feature.OCEAN)
ax.add_feature(cartopy.feature.COASTLINE)
ax.add_feature(cartopy.feature.BORDERS, linestyle=':')
ax.add_feature(cartopy.feature.LAKES, alpha=0.5)
ax.add_feature(cartopy.feature.RIVERS)

ax.set_extent([-20, 60, -40, 40])

plt.show()

, , , (Failed CDLL(/Library/Frameworks/GEOS.framework/Versions/Current/GEOS)), , , :

Map created using cartographic code

, . , . .

+3

, , - .

Cartopy MacOS:

MacOS 10.12.6, virtualenv Python 3.7.0 ( conda).

  1. , Python, :

    pip install numpy  
    pip install Cython  
    pip install --no-binary :all: shapely  
    pip install pyshp  
    pip install six  
    

    :

    numpy==1.15.3
    Cython==0.29
    Shapely==1.6.4.post2
    pyshp==2.0.1
    six==1.11.0
    
  2. brew :

    brew install proj  
    brew install geos
    

    :

    proj --> Rel. 5.2.0, September 15th, 2018
    geos-config --version --> 3.7.0
    

    export GEOS_DIR=/usr/local/Cellar/geos/3.7.0/ ~/.bash_profile.

  3. , pip install Cartopy:

    pip install Cartopy
    Cartopy==0.17.0
    

, , geos brew ( - Kyng Chaos, ). ,

pip install --no-binary :all: shapely

?

Shapely Shapely:

Shapely , GEOS (, cartopy osgeo.ogr), GEOS, , , GEOS, Cython Numpy ( apt, yum, brew ), pip, .

: , - Cartopy Mac.


1718097, Cartopy GitHub .

0

Source: https://habr.com/ru/post/1675764/


All Articles