Score:2

source venv/bin/activate isn't returning anything on CentOS

im flag

I'm trying to deploy a Python Flask app (for API endpoint) on CentOS for work, but every online guide I've followed isn't working for me!

python3 -m venv APIenv

The env was created successfully, but then trying to activate it:

source APIenv/bin/activate

Returns nothing, neither an error not is it activating it!

from what I understood, activating it should make the CLI look like this:

(venv) $ _

I'm also having another problem:

pip3 install firebase_admin

this worked and it was installed, but then running my app:

python3 app.py

Traceback (most recent call last): File "app.py", line 4, in import firebase_admin ModuleNotFoundError: No module named 'firebase_admin'

Every online guide I've followed is getting me stuck here, I really need to get this to work, what am I doing wrong?

Score:3
us flag

Probably you have pip3 linked to another version of python(3.6,3.8, etc) than python3 which you are using

Make sure you are using the same versions and it is in venv actually check python3

# python3 -V
Python 3.8.6
# which python3
/tmp/APIenv/bin/python3
# ls -laht /tmp/APIenv/bin/python3
lrwxrwxrwx 1 root root 8 Sep 30 13:59 /tmp/APIenv/bin/python3 -> python38

Check pip3

# pip3 -V
pip 19.3.1 from /tmp/APIenv/lib64/python3.8/site-packages/pip (python 3.8)
# which pip3
/tmp/APIenv/bin/pip3
# ls -laht /tmp/APIenv/bin/pip3
-rwxr-xr-x 1 root root 225 Sep 30 13:59 /tmp/APIenv/bin/pip3

sometimes it can be looking so even under VENV:

#  which python38
/tmp/APIenv/bin/python38
# ls -laht /tmp/APIenv/bin/python38
lrwxrwxrwx 1 root root 17 Sep 30 13:59 /tmp/APIenv/bin/python38 -> /usr/bin/python38

Check paths of your pip and python interpreter then, to be sure you can use it by absolute path of your venv

Updated:

Issue related to python3.6 version.

firebase_admin cannot be installed with python3.6 version

Required at least python3.8 (3.7 not tested)

Python38 installation for Centos 8 and related question modules:

dnf install python38 python38-pip
pip38 install firebase_admin flask venv
KiDo avatar
im flag
python3 -V => Python 3.6.8 | which python3 => /bin/python3 | As for pip: pip3 -V => pip 9.0.3 from /usr/lib/python3.6/site-packages (python 3.6) | which pip3 => /bin/pip3 | Is the problem Python is 3.6.8 while pip is only 3.6?
us flag
no, it is not an issue, is that output under VENV? as i see there is system environment paths, not from virtual environment, it looks as an issue
KiDo avatar
im flag
I'm sorry, I didn't understand, if it helps, I'm using root, installed python & pip before moving into venv directory
us flag
you should activate virtuan environment with command `source APIenv/bin/activate` then you will see such prefix in the shell `(venv) $ _`, then run commands `pip3 install firebase_admin` and `python3 app.py`, all of it in virtual environment which you can notice by prefix `(venv) $ _`
KiDo avatar
im flag
I am trying that, but it returns nothing, as you mentioned, the shell should change to ```(venv) $``` but in my case it remain the same ```[root@ MyAPI]#```
us flag
so, you have 2 issue, one related to venv activation and sercond i'm pretty sure issue with `pip3 install firebase_admin` because of python3.6 version firebase_admin trying to install but failed at the end, you should install newer version of python, at least 3.8 then run something like `pip38 install firebase_admin flask venv` and trying steps from your question above again, but with using new version with `python38` instead python3
KiDo avatar
im flag
I followed those steps and everything seems to be working, the only problem left is that I still can't access it using public IP (other PCs), I'm running it with: ```flask run --host=0.0.0.0``` and I've opened port 5000, but trying to check it using Postman returns Connection Timed Out
us flag
try clearing iptables rules if it possible with `iptables -F` and check connection, if it will work you can creating iptables accept rule for that port, if it doesn't help - provide me flask terminal output during start
KiDo avatar
im flag
[root@ MyAPI]# flask run --host=0.0.0.0 * Serving Flask app 'app.py' (lazy loading) * Environment: production WARNING: This is a development server. Do not use it in a production deployme nt. Use a production WSGI server instead. ...
KiDo avatar
im flag
* Debug mode: off * Running on all addresses. WARNING: This is a development server. Do not use it in a production deployme nt. * Running on http://serverIP:5000/ (Press CTRL+C to quit)
us flag
what the `serverIP:5000` ?, there should be `Running on http://0.0.0.0:5000/` do you have app.run string like that `app.run(host='0.0.0.0', port=5000)` inside app or does it looks different? also you should have realy public ip address (which not related to private range)
KiDo avatar
im flag
serverIP is my server’s IP: ‘’’xx.xx.xx.xx:5000’’’, and in app.run, I just have “app.run()”, because Flask guide says I just need to run this command to make it public: “flask run —host=0.0.0.0”, and I do have a public IP, it’s where my WordPress website is hosted on.
us flag
if you say so and you have not able to connect with public ip and 5000 port it's network issue on server OS side (related to input connection rules) or at your side (router, internet provider, etc, something that can blocking output connects to 5000 port), you can provide output of `iptables-save` then i'd look if there some issue
KiDo avatar
im flag
OMG you're right! I tried to access it using another network and it worked! You're a genius and I have no words to show my appreciation and gratitude for your help! I just have one last question, how do I keep it running in the background?
us flag
You can follow my answer at this question to run it as systemd service: https://serverfault.com/questions/1078666/how-do-i-create-a-python-3-service-that-uses-socket-with-systemd/1079133#1079133
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.