Lab - IP and Ports Q2 : ImportError: No module named flask

hi @mmumshad / @Ayman

In Lab - IP and Ports Q2 I get error when I try to execute below .

[thor@app01 simple-webapp-flask]$ cat /home/thor/nohup.out
Traceback (most recent call last):
File “app.py”, line 2, in
from flask import Flask
ImportError: No module named flask

I tried installing flask but it did not work as well . Can you please review and advise

==========================================================================

Q : In app01 server ensure that our app in /opt/simple-webapp-flask/ run on port 5000 and listen to 127.0.0.1 IP.

Run python app in background with nohup

Note: Nohup stands for no hang up, which can be executed as shown below.

nohup command-with-options &

Adding “&” at the end will move the process to run in background. When you execute a Unix job in the background ( using &) and logout from the session, your process will get killed. You can avoid this with nohup .

===========================================================================
Hint

line Hint

In app01 server run below

sudo sed -i 's/0.0.0.0/127.0.0.1/g;s/8080/5000/g' /opt/simple-webapp-flask/app.py;

cd /opt/simple-webapp-flask/; nohup python app.py &



thor@app01 simple-webapp-flask]$ pwd
/opt/simple-webapp-flask
[thor@app01 simple-webapp-flask]$ ls -al
total 32
drwxr-xr-x 3 root root 4096 Jan 27 00:30 .
drwxr-xr-x 1 root root 4096 Jan 27 00:29 ..
-rw-r--r-- 1 root root  256 Jan 27 00:30 app.py
-rw-r--r-- 1 root root  187 Jan 27 00:29 Dockerfile
drwxr-xr-x 8 root root 4096 Jan 27 00:29 .git
-rw-r--r-- 1 root root 1075 Jan 27 00:29 LICENSE
-rw-r--r-- 1 root root 1081 Jan 27 00:29 README.md
-rw-r--r-- 1 root root    6 Jan 27 00:29 requirements.txt
[thor@app01 simple-webapp-flask]$
[thor@app01 simple-webapp-flask]$ sudo pip install flask
Traceback (most recent call last):
  File "/bin/pip", line 9, in <module>
    load_entry_point('pip==21.0', 'console_scripts', 'pip')()
  File "/usr/lib/python2.7/site-packages/pkg_resources.py", line 378, in load_entry_point
    return get_distribution(dist).load_entry_point(group, name)
  File "/usr/lib/python2.7/site-packages/pkg_resources.py", line 2566, in load_entry_point
    return ep.load()
  File "/usr/lib/python2.7/site-packages/pkg_resources.py", line 2260, in load
    entry = __import__(self.module_name, globals(),globals(), ['__name__'])
  File "/usr/lib/python2.7/site-packages/pip/_internal/cli/main.py", line 60
    sys.stderr.write(f"ERROR: {exc}")
                                   ^
SyntaxError: invalid syntax
[thor@app01 simple-webapp-flask]$ sudo pip3 install flask
sudo: pip3: command not found
[thor@app01 simple-webapp-flask]$
[thor@app01 simple-webapp-flask]$ pip show flask
Traceback (most recent call last):
  File "/usr/bin/pip", line 9, in <module>
    load_entry_point('pip==21.0', 'console_scripts', 'pip')()
  File "/usr/lib/python2.7/site-packages/pkg_resources.py", line 378, in load_entry_point
    return get_distribution(dist).load_entry_point(group, name)
  File "/usr/lib/python2.7/site-packages/pkg_resources.py", line 2566, in load_entry_point
    return ep.load()
  File "/usr/lib/python2.7/site-packages/pkg_resources.py", line 2260, in load
    entry = __import__(self.module_name, globals(),globals(), ['__name__'])
  File "/usr/lib/python2.7/site-packages/pip/_internal/cli/main.py", line 60
    sys.stderr.write(f"ERROR: {exc}")
                                   ^
SyntaxError: invalid syntax
[thor@app01 simple-webapp-flask]$
[thor@app01 simple-webapp-flask]$ cat /home/thor/nohup.out
Traceback (most recent call last):
  File "app.py", line 2, in <module>
    from flask import Flask
ImportError: No module named flask
[thor@app01 simple-webapp-flask]$
[thor@app01 simple-webapp-flask]$ date
Wed Jan 27 00:35:56 UTC 2021
[thor@app01 simple-webapp-flask]$
[thor@app01 simple-webapp-flask]$ pwd
/opt/simple-webapp-flask
[thor@app01 simple-webapp-flask]$
[thor@app01 simple-webapp-flask]$ ls -al
total 32
drwxr-xr-x 3 root root 4096 Jan 27 00:30 .
drwxr-xr-x 1 root root 4096 Jan 27 00:29 ..
-rw-r--r-- 1 root root  256 Jan 27 00:30 app.py
-rw-r--r-- 1 root root  187 Jan 27 00:29 Dockerfile
drwxr-xr-x 8 root root 4096 Jan 27 00:29 .git
-rw-r--r-- 1 root root 1075 Jan 27 00:29 LICENSE
-rw-r--r-- 1 root root 1081 Jan 27 00:29 README.md
-rw-r--r-- 1 root root    6 Jan 27 00:29 requirements.txt
[thor@app01 simple-webapp-flask]$
[thor@app01 simple-webapp-flask]$
[thor@app01 simple-webapp-flask]$ sudo pip install flask
Traceback (most recent call last):
  File "/bin/pip", line 9, in <module>
    load_entry_point('pip==21.0', 'console_scripts', 'pip')()
  File "/usr/lib/python2.7/site-packages/pkg_resources.py", line 378, in load_entry_point
    return get_distribution(dist).load_entry_point(group, name)
  File "/usr/lib/python2.7/site-packages/pkg_resources.py", line 2566, in load_entry_point
    return ep.load()
  File "/usr/lib/python2.7/site-packages/pkg_resources.py", line 2260, in load
    entry = __import__(self.module_name, globals(),globals(), ['__name__'])
  File "/usr/lib/python2.7/site-packages/pip/_internal/cli/main.py", line 60
    sys.stderr.write(f"ERROR: {exc}")
                                   ^
SyntaxError: invalid syntax
[thor@app01 simple-webapp-flask]$ sudo pip3 install flask
sudo: pip3: command not found
[thor@app01 simple-webapp-flask]$
[thor@app01 simple-webapp-flask]$
[thor@app01 simple-webapp-flask]$ history
    1  clear
    2  pwd
    3  ls -al
    4  cd /opt
    5  ls -al
    6  clear
    7  ls -al
    8  cd simple-webapp-flask/
    9  ls -al
   10  cat app.py
   11  sudo sed -i 's/8080/5000/g' app.py
   12  sudo sed -i 's/0.0.0.0/127.0.0.1/g' app.py
   13  cat app.py
   14  clear
   15  nohup python app.py &
   16  ps -ef | grep app
   17  ls -al
   18  nohup python3 app.py &
   19  ps -ef | grep python
   20  clear
   21  pwd
   22  ls -al
   23  sudo pip install flask
   24  sudo pip3 install flask
   25  pip show flask
   26  cat /home/thor/nohup.out
   27  date
   28  pwd
   29  ls -al
   30  sudo pip install flask
   31  sudo pip3 install flask
   32  history
[thor@app01 simple-webapp-flask]$

seems to be an issue with a broken configuration on app01 by default. We will get this fixed.

in the mean time, you can do this to get it working -

As root (in app01):

cd /opt/simple-webapp-flask/
yum install python-virtualenv
. venv/bin/activate
pip install flask
python app.py

1 Like

Hi Team,
I am facing problem in below question of ip and port. Can someone please provide me appropiate resolution -

@Piyushm , You can find the IP and port of the app.py as shown in the screenshot.