1

I have tried installing flask_restful via pip and it shows that all the requirements for it are already satisfied. But when I try to run the following command (python run.py) on my mac terminal, I get this error :

$ python run.py
Traceback (most recent call last):
  File "run.py", line 17, in <module>
    app = create_app("config")
  File "run.py", line 7, in create_app
    from app import api_bp
  File "/Users/userName/Backend/app.py", line 2, in <module>
    from flask_restful import Api
ModuleNotFoundError: No module named 'flask_restful'
  • Which `python` are you using? You need to use the one in your `pip` environment - either by sourcing `activate` or by specifying the path, e.g. `venv/bin/python` – match Sep 29 '20 at 15:05
  • i am using python3 as a default. I tried with both, pip and pip3. it still shows all requirements are satisfied. – Vivek Bhadula Sep 29 '20 at 15:10
  • Does this answer your question? [ImportError: No module named flask\_restful](https://stackoverflow.com/questions/51213822/importerror-no-module-named-flask-restful) – Akif Sep 29 '20 at 15:30
  • @Akif It didn't work for me – Vivek Bhadula Sep 30 '20 at 03:57

1 Answers1

2

Can you please try this in your project instead of the current virtual environment?

  • First install pipenv library pip install pipenv

  • Go to the project directory.

  • Next, activate the virtual environment pipenv shell

  • Install all required python libraries.

    pipenv install <library_name>

    for example:
    pipenv install flask
    pipenv install flask-restful
    If requirements.txt file is available then
    pipenv install -r requirements.txt

  • Run your code. python run.py

arun n a
  • 684
  • 9
  • 26
  • After running multiple commands in mac, now it is showing : can't open file 'run.py': [Errno 2] No such file or directory. Looks like I will have to restart my project as I've been stuck at it for long enough. But your answer was going pretty smoothly, so I think it might be able to help others who have the same problem. Do try this one if you have the same problem. Thanks a lot. – Vivek Bhadula Sep 30 '20 at 04:01