stefmolin / Hands-On-Data-Analysis-with-Pandas-2nd-edition

Materials for following along with Hands-On Data Analysis with Pandas – Second Edition
https://www.amazon.com/Hands-Data-Analysis-Pandas-visualization/dp/1800563450
MIT License
577 stars 1.38k forks source link

chapter 1 - Introduction_to_data_analysis notebook import error #26

Closed Tinnguy closed 1 year ago

Tinnguy commented 1 year ago

Hi,

I have a mac book pro m1 and follow the installation for Apple Silicon User. I have tried several times and still get error from running this statement:

from visual_aids import stats_viz

ImportError Traceback (most recent call last) Cell In[1], line 1 ----> 1 from visual_aids import stats_viz

File /opt/homebrew/Caskroom/miniforge/base/envs/book_env/lib/python3.8/site-packages/visual_aids/stats_viz.py:9 7 import numpy as np 8 import pandas as pd ----> 9 from scipy.stats import bernoulli, binom, expon, poisson, norm, skewnorm 10 import seaborn as sns 11 from sklearn.metrics import r2_score

File /opt/homebrew/Caskroom/miniforge/base/envs/book_env/lib/python3.8/site-packages/scipy/stats/init.py:391 1 """ 2 .. _statsrefmanual: 3 (...) 389 390 """ --> 391 from .stats import 392 from .distributions import 393 from .morestats import *

File /opt/homebrew/Caskroom/miniforge/base/envs/book_env/lib/python3.8/site-packages/scipy/stats/stats.py:174 171 import numpy as np 172 from numpy import array, asarray, ma --> 174 from scipy.spatial.distance import cdist 175 from scipy.ndimage import measurements 176 from scipy._lib._util import (_lazywhere, check_random_state, MapWrapper, 177 rng_integers, float_factorial)

File /opt/homebrew/Caskroom/miniforge/base/envs/book_env/lib/python3.8/site-packages/scipy/spatial/init.py:102 100 from ._plotutils import * 101 from ._procrustes import procrustes --> 102 from ._geometric_slerp import geometricslerp 104 all = [s for s in dir() if not s.startswith('')] 105 all += ['distance', 'transform']

File /opt/homebrew/Caskroom/miniforge/base/envs/book_env/lib/python3.8/site-packages/scipy/spatial/_geometric_slerp.py:8 5 import warnings 7 import numpy as np ----> 8 from scipy.spatial.distance import euclidean 11 def _geometric_slerp(start, end, t): 12 # create an orthogonal basis using QR decomposition 13 basis = np.vstack([start, end])

File /opt/homebrew/Caskroom/miniforge/base/envs/book_env/lib/python3.8/site-packages/scipy/spatial/distance.py:122 120 from . import _hausdorff 121 from ..linalg import norm --> 122 from ..special import rel_entr 125 def _args_to_kwargs_xdist(args, kwargs, metric, func_name): 126 """ 127 Convert legacy positional arguments to keyword arguments for pdist/cdist. 128 """

File /opt/homebrew/Caskroom/miniforge/base/envs/book_env/lib/python3.8/site-packages/scipy/special/init.py:633 1 """ 2 ======================================== 3 Special functions (:mod:scipy.special) (...) 628 629 """ 631 from .sf_error import SpecialFunctionWarning, SpecialFunctionError --> 633 from . import _ufuncs 634 from ._ufuncs import * 636 from . import _basic

ImportError: dlopen(/opt/homebrew/Caskroom/miniforge/base/envs/book_env/lib/python3.8/site-packages/scipy/special/_ufuncs.cpython-38-darwin.so, 0x0002): Library not loaded: @rpath/libgcc_s.2.dylib Referenced from: /opt/homebrew/Caskroom/miniforge/base/envs/book_env/lib/python3.8/site-packages/scipy/special/_ufuncs.cpython-38-darwin.so Reason: tried: '/Users/runner/miniforge3/conda-bld/scipy_1609457863341/_build_env/lib/libgcc_s.2.dylib' (no such file), '/System/Volumes/Preboot/Cryptexes/OS/Users/runner/miniforge3/conda-bld/scipy_1609457863341/_build_env/lib/libgcc_s.2.dylib' (no such file), '/opt/homebrew/Caskroom/miniforge/base/envs/book_env/lib/python3.8/site-packages/scipy/special/../../../../libgcc_s.2.dylib' (no such file), '/Users/runner/miniforge3/conda-bld/scipy_1609457863341/_build_env/lib/libgcc_s.2.dylib' (no such file), '/System/Volumes/Preboot/Cryptexes/OS/Users/runner/miniforge3/conda-bld/scipy_1609457863341/_build_env/lib/libgcc_s.2.dylib' (no such file), '/opt/homebrew/Caskroom/miniforge/base/envs/book_env/lib/python3.8/site-packages/scipy/special/../../../../libgcc_s.2.dylib' (no such file), '/opt/homebrew/Caskroom/miniforge/base/envs/book_env/bin/../lib/libgcc_s.2.dylib' (no such file), '/opt/homebrew/Caskroom/miniforge/base/envs/book_env/bin/../lib/libgcc_s.2.dylib' (no such file), '/System/Volumes/Preboot/Cryptexes/OS@rpath/libgcc_s.2.dylib' (no such file), '/Users/runner/miniforge3/conda-bld/scipy_1609457863341/_build_env/lib/libgcc_s.2.dylib' (no such file), '/System/Volumes/Preboot/Cryptexes/OS/Users/runner/miniforge3/conda-bld/scipy_1609457863341/_build_env/lib/libgcc_s.2.dylib' (no such file), '/opt/homebrew/Caskroom/miniforge/base/envs/book_env/lib/python3.8/site-packages/scipy/special/../../../../libgcc_s.2.dylib' (no such file), '/Users/runner/miniforge3/conda-bld/scipy_1609457863341/_build_env/lib/libgcc_s.2.dylib' (no such file), '/System/Volumes/Preboot/Cryptexes/OS/Users/runner/miniforge3/conda-bld/scipy_1609457863341/_build_env/lib/libgcc_s.2.dylib' (no such file), '/opt/homebrew/Caskroom/miniforge/base/envs/book_env/lib/python3.8/site-packages/scipy/special/../../../../libgcc_s.2.dylib' (no such file), '/opt/homebrew/Caskroom/miniforge/base/envs/book_env/bin/../lib/libgcc_s.2.dylib' (no such file), '/opt/homebrew/Caskroom/miniforge/base/envs/book_env/bin/../lib/libgcc_s.2.dylib' (no such file), '/usr/local/lib/libgcc_s.2.dylib' (no such file), '/usr/lib/libgcc_s.2.dylib' (no such file, not in dyld cache)

stefmolin commented 1 year ago

Hi there. There appears to be an issue with your scipy installation. What version do you have installed?

Please also include a screenshot of your output after running the check your environment notebook (ch_01/checking_your_setup.ipynb).

Tinnguy commented 1 year ago

Hello Stefanie,

Thanks for quick response.

I think what I did was to modified the environment.yml, change seaborn version to 0.11.1 because 0.11.0 no longer support by conda.

$ mamba env create --file environment.yml conda-forge/osx-arm64 4.8MB @ 1.7MB/s 3.0s conda-forge/noarch 10.8MB @ 3.3MB/s 3.6s

Looking for: ['python=3.8', 'imbalanced-learn=0.7.0', 'ipympl=0.6.2', 'jupyterlab=3.0.4', 'matplotlib=3.3.2', "numpy[version='>=1.19.2,<=1.19.4']", 'pandas=1.2.0', 'requests=2.24.0', 'pip', 'python-graphviz=0.14.1', 'scikit-learn=0.23.2', "scipy[version='>=1.5.0,<=1.7.3']", 'seaborn=0.11.0', "sqlalchemy[version='=1.3.19|1.3.20']", "statsmodels[version='>=0.11.1,<=0.12.1']"]

Could not solve for environment specs Encountered problems while solving:

The environment can't be solved, aborting the operation

Search conda for seaborn

$ conda search seaborn Loading channels: done

Name Version Build Channel

seaborn 0.8.1 py_1 conda-forge
seaborn 0.9.0 py_0 conda-forge
seaborn 0.9.0 py_1 conda-forge
seaborn 0.9.0 py_2 conda-forge
seaborn 0.10.0 py_0 conda-forge
seaborn 0.10.0 py_1 conda-forge
seaborn 0.10.1 py_0 conda-forge
seaborn 0.11.1 hd8ed1ab_1 conda-forge
seaborn 0.11.2 hd8ed1ab_0 conda-forge
seaborn 0.12.0 hd8ed1ab_0 conda-forge
seaborn 0.12.1 hd8ed1ab_0 conda-forge
seaborn 0.12.2 hd8ed1ab_0 conda-forge

Screenshot checking your setup

Screenshot 2023-01-04 at 8 59 41 PM

Conda env export (book_env.txt)

book_dev.txt

stefmolin commented 1 year ago

I was able to reproduce your problem on my machine. There is a missing Fortran dependency just like in https://github.com/conda/conda/issues/11735 (packaging issue upstream). Try these changes in your environment.yml (change the Python version and add the second line):

    - python=3.9
    - libgfortran=5.0.0.dev0

I'm able to install the version of seaborn without issue. It's also listed as available on their website.

Tinnguy commented 1 year ago

Hello Stefanie,

I can confirm the following: 1) seaborn 0.11.0 is not available. So I go ahead and use 0.11.1 2) These two lines solve the problem enven with seaborn 0.11.0 3) I can run chapter one Introduction to Data Analysis just fine

You can close this issue.

Thank you very much for your help.

Tinnguy commented 1 year ago

I meant these two lines does solve the issue that I have on mac M1 chip: