Forums

WSGI application error while importing seaborn - fails at "from scipy import linalg"

I installed seaborn using "pip3.6 install --user seaborn". I am able to import seaborn successfully and use it in a python console. However, when i run my webApp I get an error "cannot import name 'linalg'" for the exact same file that I used successfully to create seaborn plots in the python console. I tried upgrading scipy but that did not fix the issue. Any suggestions to fix appreciated!

See Trace below:

File "/home/myusername/repos/dev/iplots.py", line 15, in <module> import seaborn as sns

File "/home/myusername/.virtualenvs/djangoenv/lib/python3.6/site-packages/seaborn/init.py", line 6, in <module> from .rcmod import *

File "/home/myusername/.virtualenvs/djangoenv/lib/python3.6/site-packages/seaborn/rcmod.py", line 8, in <module> from . import palettes, _orig_rc_params

File "/home/myusername/.virtualenvs/djangoenv/lib/python3.6/site-packages/seaborn/palettes.py", line 12, in <module> from .utils import desaturate, set_hls_values, get_color_cycle

File "/home/myusername/.virtualenvs/djangoenv/lib/python3.6/site-packages/seaborn/utils.py", line 7, in <module> from scipy import stats

File "/home/myusername/.virtualenvs/djangoenv/lib/python3.6/site-packages/scipy/stats/init.py", line 345, in <module> from .stats import *

File "/home/myusername/.virtualenvs/djangoenv/lib/python3.6/site-packages/scipy/stats/stats.py", line 169, in <module> import scipy.special as special File "/home/myusername/.virtualenvs/djangoenv/lib/python3.6/site-packages/scipy/special/init.py", line 642, in <module> from .basic import *

File "/home/myusername/.virtualenvs/djangoenv/lib/python3.6/site-packages/scipy/special/basic.py", line 19, in <module> from . import orthogonal

File "/home/myusername/.virtualenvs/djangoenv/lib/python3.6/site-packages/scipy/special/orthogonal.py", line 83, in <module> from scipy import linalg

ImportError: cannot import name 'linalg'

2018-06-30 21:20:03,941 [9] ERROR root: Error running WSGI application

2018-06-30 21:20:03,949 [9] ERROR root: ImportError: cannot import name 'linalg'

That user install did not install seaborn into the virtualenv that you're using for your web app. Install it into the virtualenv that you're using.

I forgot to mention that I did that as well. Checked again in the virtualenv to be sure (see below):

(djangoenv) 12:16 ~ $ pip3.6 install seaborn Requirement already satisfied: seaborn in ./.virtualenvs/djangoenv/lib/python3.6/site-packages Requirement already satisfied: scipy in ./.virtualenvs/djangoenv/lib/python3.6/site-packages (from seaborn) Requirement already satisfied: numpy>=1.8.2 in ./.virtualenvs/djangoenv/lib/python3.6/site-packages (from scipy->seaborn)

However, your response reminded me that I may not have upgraded scipy in the virtualenv - I will try that and see if it helps.

I confirmed that I did update scipy in the virtualenv as well:

(djangoenv) 12:23 ~ $ pip3.6 install --upgrade scipy Requirement already up-to-date: scipy in ./.virtualenvs/djangoenv/lib/python3.6/site-packages Requirement already up-to-date: numpy>=1.8.2 in ./.virtualenvs/djangoenv/lib/python3.6/site-packages (from scipy) (djangoenv) 12:23 ~ $

So to summarize, I confirmed that I had installed seaborn and upgraded scipy in my virtualenv and I still see the same error as in my first post.

< Duplicate post deleted - accidental double click>

Then the version of scipy/seaborn that you have installed doesn't have linalg. Make sure the versions are the same.

The version of scipy installed is 1.1.0 on both virtualenv and user environment (virtualenv deactivated).

I verified that scipy 1.1.0 has linalg per reference documentation for 1.1.0 at https://docs.scipy.org/doc/scipy-1.1.0/reference/tutorial/linalg.html

The odd thing is with the same scipy and seaborn versions installed I am able to import seaborn in python console but not in the webApp - seems like I must be missing something obvious but cannot figure out why.

I fixed the issue - while the scipy version was correct, linalg (and some other files and folders) were missing in the virtualenv scipy folder. I uninstalled scipy and reinstalled it and that resolved it.