skip to Main Content

I need to use Numpy on EC2 instance that runs Flask with WSGI-py3, which can be accessed over HTTP.

After setting up everything needed, I can see the page in the browser. However, later I am installing Numpy using pip3 and now the service breaks with the following error in /var/log/apache2/error.log ModuleNotFoundError: No module named 'numpy', however I can import numpy in python3 without any problems

What could be done to be able to import numpy in Flask application?

EDIT:
It is confusing.. If I list all Python versions installed, I get:

   0 lrwxrwxrwx 1 root root       9 Oct 25  2018 /usr/bin/python3 -> python3.6
   0 lrwxrwxrwx 1 root root      16 Oct 25  2018 /usr/bin/python3-config -> python3.6-config
   4 -rwxr-xr-x 1 root root    1018 Oct 28  2017 /usr/bin/python3-jsondiff
   4 -rwxr-xr-x 1 root root    3661 Oct 28  2017 /usr/bin/python3-jsonpatch
   4 -rwxr-xr-x 1 root root    1342 May  1  2016 /usr/bin/python3-jsonpointer
   4 -rwxr-xr-x 1 root root     398 Nov 15  2017 /usr/bin/python3-jsonschema
4424 -rwxr-xr-x 2 root root 4526456 Apr 18 01:56 /usr/bin/python3.6
   0 lrwxrwxrwx 1 root root      33 Apr 18 01:56 /usr/bin/python3.6-config -> x86_64-linux-gnu-python3.6-config
4424 -rwxr-xr-x 2 root root 4526456 Apr 18 01:56 /usr/bin/python3.6m
   0 lrwxrwxrwx 1 root root      34 Apr 18 01:56 /usr/bin/python3.6m-config -> x86_64-linux-gnu-python3.6m-config
   0 lrwxrwxrwx 1 root root      10 Oct 25  2018 /usr/bin/python3m -> python3.6m
   0 lrwxrwxrwx 1 root root      17 Oct 25  2018 /usr/bin/python3m-config -> python3.6m-config
  • pip3 seems to be connected to python3.6

  • /usr/local/bin/flask uses #!/usr/bin/python3

  • If I install numpy using /usr/bin/python3 -m pip install numpy I still have the same problem

2

Answers


  1. Chosen as BEST ANSWER

    Using virtual environment in EC2 has helped:

    sudo apt-get update
    sudo apt-get install apache2
    sudo apt-get install libapache2-mod-wsgi-py3
    sudo apt-get install python3.6
    sudo ln -sT /usr/bin/python3 /usr/bin/python
    sudo apt-get install python3-pip
    sudo ln -sT /usr/bin/pip3 /usr/bin/pip
    sudo pip install flask
    sudo apt-get install virtualenv
    mkdir ~/flaskapp
    sudo ln -sT ~/flaskapp /var/www/html/flaskapp
    cd ~/flaskapp
    virtualenv flask --python=python3
    sudo vim /etc/apache2/sites-enabled/000-default.conf:
    .....
    sudo pip3 install numpy
    ...
    

  2. This probably means, the Python interpreter which runs Flask is a different than the Python interpreter which you have installed numpy into.

    Unfortunately, I have no experience with AWS.

    Basically, you have to figure out how to find the Python interpreter you installed Flask with.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search