question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ImportError: cannot import name 'multiarray' with Apache/mod_wsgi

See original GitHub issue

I’m trying to deploy a Flask-based application (Python 3) in AWS EC2 using Apache and mod_wsgi with all the necessary packages being installed in a miniconda environment.

Bellow you can find my app.wsgi file:

import sys
import logging
import site
    
site.addsitedir('/home/ubuntu/miniconda3/envs/app_env/lib/python3.6/site-packages/')
logging.basicConfig(stream=sys.stderr)
sys.path.insert(0,"/var/www/html/flaskapp/")
sys.stdout = sys.stderr
    
from app import app as application

Also, here’s my Apache config file:

ServerAdmin webmaster@localhost
DocumentRoot /var/www/html

WSGIDaemonProcess flaskapp threads=5 python-home=/home/ubuntu/miniconda3/envs/app_env
WSGIScriptAlias / /var/www/html/flaskapp/app.wsgi

<Directory flaskapp>
        WSGIProcessGroup flaskapp
        WSGIApplicationGroup %{GLOBAL}
        Order deny,allow
        Allow from all
</Directory>

ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined

However, when I reload my server, I keep getting the same error:

[Wed Jul 18 12:24:12.897534 2018] [wsgi:error] [pid 10224:tid 140691482736384] [client 89.115.58.201:23351] mod_wsgi (pid=10224): Target WSGI script '/var/www/html/flaskapp/app.wsgi' cannot be loaded as Python module., referer: http://ec2-52-47-138-159.eu-west-3.compute.amazonaws.com/
[Wed Jul 18 12:24:12.897592 2018] [wsgi:error] [pid 10224:tid 140691482736384] [client 89.115.58.201:23351] mod_wsgi (pid=10224): Exception occurred processing WSGI script '/var/www/html/flaskapp/app.wsgi'., referer: http://ec2-52-47-138-159.eu-west-3.compute.amazonaws.com/
[Wed Jul 18 12:24:12.900007 2018] [wsgi:error] [pid 10224:tid 140691482736384] [client 89.115.58.201:23351] Traceback (most recent call last):, referer: http://ec2-52-47-138-159.eu-west-3.compute.amazonaws.com/
[Wed Jul 18 12:24:12.900033 2018] [wsgi:error] [pid 10224:tid 140691482736384] [client 89.115.58.201:23351]   File "/home/ubuntu/miniconda3/envs/app_env/lib/python3.6/site-packages/numpy/core/__init__.py", line 16, in <module>, referer: http://ec2-52-47-138-159.eu-west-3.compute.amazonaws.com/
[Wed Jul 18 12:24:12.900045 2018] [wsgi:error] [pid 10224:tid 140691482736384] [client 89.115.58.201:23351]     from . import multiarray, referer: http://ec2-52-47-138-159.eu-west-3.compute.amazonaws.com/
[Wed Jul 18 12:24:12.900062 2018] [wsgi:error] [pid 10224:tid 140691482736384] [client 89.115.58.201:23351] ImportError: cannot import name 'multiarray', referer: http://ec2-52-47-138-159.eu-west-3.compute.amazonaws.com/
[Wed Jul 18 12:24:12.900072 2018] [wsgi:error] [pid 10224:tid 140691482736384] [client 89.115.58.201:23351] , referer: http://ec2-52-47-138-159.eu-west-3.compute.amazonaws.com/
[Wed Jul 18 12:24:12.900075 2018] [wsgi:error] [pid 10224:tid 140691482736384] [client 89.115.58.201:23351] During handling of the above exception, another exception occurred:, referer: http://ec2-52-47-138-159.eu-west-3.compute.amazonaws.com/
[Wed Jul 18 12:24:12.900078 2018] [wsgi:error] [pid 10224:tid 140691482736384] [client 89.115.58.201:23351] , referer: http://ec2-52-47-138-159.eu-west-3.compute.amazonaws.com/
[Wed Jul 18 12:24:12.900083 2018] [wsgi:error] [pid 10224:tid 140691482736384] [client 89.115.58.201:23351] Traceback (most recent call last):, referer: http://ec2-52-47-138-159.eu-west-3.compute.amazonaws.com/
[Wed Jul 18 12:24:12.900171 2018] [wsgi:error] [pid 10224:tid 140691482736384] [client 89.115.58.201:23351]   File "/var/www/html/flaskapp/app.wsgi", line 10, in <module>, referer: http://ec2-52-47-138-159.eu-west-3.compute.amazonaws.com/
[Wed Jul 18 12:24:12.900176 2018] [wsgi:error] [pid 10224:tid 140691482736384] [client 89.115.58.201:23351]     from app import app as application, referer: http://ec2-52-47-138-159.eu-west-3.compute.amazonaws.com/
[Wed Jul 18 12:24:12.900181 2018] [wsgi:error] [pid 10224:tid 140691482736384] [client 89.115.58.201:23351]   File "/var/www/html/flaskapp/app.py", line 4, in <module>, referer: http://ec2-52-47-138-159.eu-west-3.compute.amazonaws.com/
[Wed Jul 18 12:24:12.900184 2018] [wsgi:error] [pid 10224:tid 140691482736384] [client 89.115.58.201:23351]     app = create_app(), referer: http://ec2-52-47-138-159.eu-west-3.compute.amazonaws.com/
[Wed Jul 18 12:24:12.900189 2018] [wsgi:error] [pid 10224:tid 140691482736384] [client 89.115.58.201:23351]   File "/var/www/html/flaskapp/app/__init__.py", line 33, in create_app, referer: http://ec2-52-47-138-159.eu-west-3.compute.amazonaws.com/
[Wed Jul 18 12:24:12.900192 2018] [wsgi:error] [pid 10224:tid 140691482736384] [client 89.115.58.201:23351]     from app.data import bp as data_bp, referer: http://ec2-52-47-138-159.eu-west-3.compute.amazonaws.com/
[Wed Jul 18 12:24:12.900197 2018] [wsgi:error] [pid 10224:tid 140691482736384] [client 89.115.58.201:23351]   File "/var/www/html/flaskapp/app/data/__init__.py", line 18, in <module>, referer: http://ec2-52-47-138-159.eu-west-3.compute.amazonaws.com/
[Wed Jul 18 12:24:12.900200 2018] [wsgi:error] [pid 10224:tid 140691482736384] [client 89.115.58.201:23351]     from app.data import views, referer: http://ec2-52-47-138-159.eu-west-3.compute.amazonaws.com/
[Wed Jul 18 12:24:12.900205 2018] [wsgi:error] [pid 10224:tid 140691482736384] [client 89.115.58.201:23351]   File "/var/www/html/flaskapp/app/data/views.py", line 7, in <module>, referer: http://ec2-52-47-138-159.eu-west-3.compute.amazonaws.com/
[Wed Jul 18 12:24:12.900207 2018] [wsgi:error] [pid 10224:tid 140691482736384] [client 89.115.58.201:23351]     from app.lca import mongo, referer: http://ec2-52-47-138-159.eu-west-3.compute.amazonaws.com/
[Wed Jul 18 12:24:12.900212 2018] [wsgi:error] [pid 10224:tid 140691482736384] [client 89.115.58.201:23351]   File "/var/www/html/flaskapp/app/lca/__init__.py", line 3, in <module>, referer: http://ec2-52-47-138-159.eu-west-3.compute.amazonaws.com/
[Wed Jul 18 12:24:12.900215 2018] [wsgi:error] [pid 10224:tid 140691482736384] [client 89.115.58.201:23351]     import brightway2 as bw2, referer: http://ec2-52-47-138-159.eu-west-3.compute.amazonaws.com/
[Wed Jul 18 12:24:12.900223 2018] [wsgi:error] [pid 10224:tid 140691482736384] [client 89.115.58.201:23351]   File "/home/ubuntu/miniconda3/envs/app_env/lib/python3.6/site-packages/brightway2/__init__.py", line 2, in <module>, referer: http://ec2-52-47-138-159.eu-west-3.compute.amazonaws.com/
[Wed Jul 18 12:24:12.900226 2018] [wsgi:error] [pid 10224:tid 140691482736384] [client 89.115.58.201:23351]     from bw2data import *, referer: http://ec2-52-47-138-159.eu-west-3.compute.amazonaws.com/
[Wed Jul 18 12:24:12.900231 2018] [wsgi:error] [pid 10224:tid 140691482736384] [client 89.115.58.201:23351]   File "/home/ubuntu/miniconda3/envs/app_env/lib/python3.6/site-packages/bw2data/__init__.py", line 33, in <module>, referer: http://ec2-52-47-138-159.eu-west-3.compute.amazonaws.com/
[Wed Jul 18 12:24:12.900234 2018] [wsgi:error] [pid 10224:tid 140691482736384] [client 89.115.58.201:23351]     from .project import projects, referer: http://ec2-52-47-138-159.eu-west-3.compute.amazonaws.com/
[Wed Jul 18 12:24:12.900239 2018] [wsgi:error] [pid 10224:tid 140691482736384] [client 89.115.58.201:23351]   File "/home/ubuntu/miniconda3/envs/app_env/lib/python3.6/site-packages/bw2data/project.py", line 9, in <module>, referer: http://ec2-52-47-138-159.eu-west-3.compute.amazonaws.com/
[Wed Jul 18 12:24:12.900242 2018] [wsgi:error] [pid 10224:tid 140691482736384] [client 89.115.58.201:23351]     from .utils import python_2_unicode_compatible, referer: http://ec2-52-47-138-159.eu-west-3.compute.amazonaws.com/
[Wed Jul 18 12:24:12.900246 2018] [wsgi:error] [pid 10224:tid 140691482736384] [client 89.115.58.201:23351]   File "/home/ubuntu/miniconda3/envs/app_env/lib/python3.6/site-packages/bw2data/utils.py", line 19, in <module>, referer: http://ec2-52-47-138-159.eu-west-3.compute.amazonaws.com/
[Wed Jul 18 12:24:12.900249 2018] [wsgi:error] [pid 10224:tid 140691482736384] [client 89.115.58.201:23351]     import stats_arrays as sa, referer: http://ec2-52-47-138-159.eu-west-3.compute.amazonaws.com/
[Wed Jul 18 12:24:12.900254 2018] [wsgi:error] [pid 10224:tid 140691482736384] [client 89.115.58.201:23351]   File "/home/ubuntu/miniconda3/envs/app_env/lib/python3.6/site-packages/stats_arrays/__init__.py", line 5, in <module>, referer: http://ec2-52-47-138-159.eu-west-3.compute.amazonaws.com/
[Wed Jul 18 12:24:12.900257 2018] [wsgi:error] [pid 10224:tid 140691482736384] [client 89.115.58.201:23351]     from .distributions import *, referer: http://ec2-52-47-138-159.eu-west-3.compute.amazonaws.com/
[Wed Jul 18 12:24:12.900262 2018] [wsgi:error] [pid 10224:tid 140691482736384] [client 89.115.58.201:23351]   File "/home/ubuntu/miniconda3/envs/app_env/lib/python3.6/site-packages/stats_arrays/distributions/__init__.py", line 1, in <module>, referer: http://ec2-52-47-138-159.eu-west-3.compute.amazonaws.com/
[Wed Jul 18 12:24:12.900265 2018] [wsgi:error] [pid 10224:tid 140691482736384] [client 89.115.58.201:23351]     from .base import UncertaintyBase, BoundedUncertaintyBase, referer: http://ec2-52-47-138-159.eu-west-3.compute.amazonaws.com/
[Wed Jul 18 12:24:12.900270 2018] [wsgi:error] [pid 10224:tid 140691482736384] [client 89.115.58.201:23351]   File "/home/ubuntu/miniconda3/envs/app_env/lib/python3.6/site-packages/stats_arrays/distributions/base.py", line 5, in <module>, referer: http://ec2-52-47-138-159.eu-west-3.compute.amazonaws.com/
[Wed Jul 18 12:24:12.900273 2018] [wsgi:error] [pid 10224:tid 140691482736384] [client 89.115.58.201:23351]     from ..utils import one_row_params_array, construct_params_array, referer: http://ec2-52-47-138-159.eu-west-3.compute.amazonaws.com/
[Wed Jul 18 12:24:12.900277 2018] [wsgi:error] [pid 10224:tid 140691482736384] [client 89.115.58.201:23351]   File "/home/ubuntu/miniconda3/envs/app_env/lib/python3.6/site-packages/stats_arrays/utils.py", line 3, in <module>, referer: http://ec2-52-47-138-159.eu-west-3.compute.amazonaws.com/
[Wed Jul 18 12:24:12.900280 2018] [wsgi:error] [pid 10224:tid 140691482736384] [client 89.115.58.201:23351]     import numpy as np, referer: http://ec2-52-47-138-159.eu-west-3.compute.amazonaws.com/
[Wed Jul 18 12:24:12.900287 2018] [wsgi:error] [pid 10224:tid 140691482736384] [client 89.115.58.201:23351]   File "/home/ubuntu/miniconda3/envs/app_env/lib/python3.6/site-packages/numpy/__init__.py", line 142, in <module>, referer: http://ec2-52-47-138-159.eu-west-3.compute.amazonaws.com/
[Wed Jul 18 12:24:12.900290 2018] [wsgi:error] [pid 10224:tid 140691482736384] [client 89.115.58.201:23351]     from . import add_newdocs, referer: http://ec2-52-47-138-159.eu-west-3.compute.amazonaws.com/
[Wed Jul 18 12:24:12.900295 2018] [wsgi:error] [pid 10224:tid 140691482736384] [client 89.115.58.201:23351]   File "/home/ubuntu/miniconda3/envs/app_env/lib/python3.6/site-packages/numpy/add_newdocs.py", line 13, in <module>, referer: http://ec2-52-47-138-159.eu-west-3.compute.amazonaws.com/
[Wed Jul 18 12:24:12.900298 2018] [wsgi:error] [pid 10224:tid 140691482736384] [client 89.115.58.201:23351]     from numpy.lib import add_newdoc, referer: http://ec2-52-47-138-159.eu-west-3.compute.amazonaws.com/
[Wed Jul 18 12:24:12.900302 2018] [wsgi:error] [pid 10224:tid 140691482736384] [client 89.115.58.201:23351]   File "/home/ubuntu/miniconda3/envs/app_env/lib/python3.6/site-packages/numpy/lib/__init__.py", line 8, in <module>, referer: http://ec2-52-47-138-159.eu-west-3.compute.amazonaws.com/
[Wed Jul 18 12:24:12.900305 2018] [wsgi:error] [pid 10224:tid 140691482736384] [client 89.115.58.201:23351]     from .type_check import *, referer: http://ec2-52-47-138-159.eu-west-3.compute.amazonaws.com/
[Wed Jul 18 12:24:12.900310 2018] [wsgi:error] [pid 10224:tid 140691482736384] [client 89.115.58.201:23351]   File "/home/ubuntu/miniconda3/envs/app_env/lib/python3.6/site-packages/numpy/lib/type_check.py", line 11, in <module>, referer: http://ec2-52-47-138-159.eu-west-3.compute.amazonaws.com/
[Wed Jul 18 12:24:12.900313 2018] [wsgi:error] [pid 10224:tid 140691482736384] [client 89.115.58.201:23351]     import numpy.core.numeric as _nx, referer: http://ec2-52-47-138-159.eu-west-3.compute.amazonaws.com/    
[Wed Jul 18 12:24:12.900318 2018] [wsgi:error] [pid 10224:tid 140691482736384] [client 89.115.58.201:23351]   File "/home/ubuntu/miniconda3/envs/app_env/lib/python3.6/site-packages/numpy/core/__init__.py", line 26, in <module>, referer: http://ec2-52-47-138-159.eu-west-3.compute.amazonaws.com/
[Wed Jul 18 12:24:12.900321 2018] [wsgi:error] [pid 10224:tid 140691482736384] [client 89.115.58.201:23351]     raise ImportError(msg), referer: http://ec2-52-47-138-159.eu-west-3.compute.amazonaws.com/
[Wed Jul 18 12:24:12.900336 2018] [wsgi:error] [pid 10224:tid 140691482736384] [client 89.115.58.201:23351] ImportError: , referer: http://ec2-52-47-138-159.eu-west-3.compute.amazonaws.com/
[Wed Jul 18 12:24:12.900352 2018] [wsgi:error] [pid 10224:tid 140691482736384] [client 89.115.58.201:23351] Importing the multiarray numpy extension module failed.  Most, referer: http://ec2-52-47-138-159.eu-west-3.compute.amazonaws.com/
[Wed Jul 18 12:24:12.900355 2018] [wsgi:error] [pid 10224:tid 140691482736384] [client 89.115.58.201:23351] likely you are trying to import a failed build of numpy., referer: http://ec2-52-47-138-159.eu-west-3.compute.amazonaws.com/
[Wed Jul 18 12:24:12.900357 2018] [wsgi:error] [pid 10224:tid 140691482736384] [client 89.115.58.201:23351] If you're working with a numpy git repo, try `git clean -xdf` (removes all, referer: http://ec2-52-47-138-159.eu-west-3.compute.amazonaws.com/
[Wed Jul 18 12:24:12.900360 2018] [wsgi:error] [pid 10224:tid 140691482736384] [client 89.115.58.201:23351] files not under version control).  Otherwise reinstall numpy., referer: http://ec2-52-47-138-159.eu-west-3.compute.amazonaws.com/
[Wed Jul 18 12:24:12.900362 2018] [wsgi:error] [pid 10224:tid 140691482736384] [client 89.115.58.201:23351] , referer: http://ec2-52-47-138-159.eu-west-3.compute.amazonaws.com/
[Wed Jul 18 12:24:12.900365 2018] [wsgi:error] [pid 10224:tid 140691482736384] [client 89.115.58.201:23351] Original error was: cannot import name 'multiarray', referer: http://ec2-52-47-138-159.eu-west-3.compute.amazonaws.com/
[Wed Jul 18 12:24:12.900369 2018] [wsgi:error] [pid 10224:tid 140691482736384] [client 89.115.58.201:23351] , referer: http://ec2-52-47-138-159.eu-west-3.compute.amazonaws.com/

I’ve tried multiple times to reinstall numpy and create a new conda environment but the problem seems to be persisting. Moreover, if I activate my conda env I can import directly multiarray (from numpy.core import multiarray). The app also runs perfectly if I load it directly as a localhost (python app.py). Is there some peculiarity when trying to import numpy via mod_wsgi?

Thanks!

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
njsmithcommented, Jul 18, 2018

I don’t know if this is your issue or not, but as a heads up: in general numpy and mod_wsgi are not compatible. (mod_wsgi is one of two known applications that uses CPython’s “subinterpreter” support, and making numpy work with subinterpreters is somewhere between “a lot of work” and “impossible without new interpreter features”. So far no-one has been motivated to figure it out, given that there are about a dozen mod_wsgi alternatives that don’t have this issue.)

0reactions
rgommerscommented, Feb 1, 2021

I think we can close this as wontfix/invalid, there’s nothing actionable here as far as I can tell.

Read more comments on GitHub >

github_iconTop Results From Across the Web

"ImportError: Cannot import name multiarray" - Stack Overflow
Original error was: cannot import name multiarray. I uninstalled numpy using pip uninstall numpy. Although it worked, it gave me this:
Read more >
Cannot import name 'multiarray' #9047 - numpy/numpy - GitHub
Everytime I try to import numpy, it says cannot import name 'multiarray'. I have tried uninstalling and reinstalling multiple times and with ...
Read more >
ImportError: cannot import name 'multiarray' - Ask Ubuntu
Now start your Python shell and try to import it: >>> import numpy >>>. There should be no errors. You can now continue...
Read more >
Excel to Table Error: Cannot import name multiarray
I am trying to convert an Excel table to a .dbf Table, but coming across an error. Before I input the location of...
Read more >
[SOLVED] numpy error: cannot import name multiarray
Hi,. I am using Spyder in anaconda2 to write a part of my code and then run the .py file using runSofa. It...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found