I have only python 3.8.5 installed.
I started diving into Python and Flask for the first time (I'm coming from the javascript side of things). I've already ran into an interesting issue in just my first few lines of code.
I was able to run pipenv install flask flask-sqlalchemy flask-marshmallow marshmallow-sqlalchemy
and they all seemed to have installed just fine. They all appear in the pipfile.lock. flask-marshmallow is version 0.13.0.
pipfile.lock
When I started coding, I was able to import flask and flask_sqlalchemy with no issues. Intellisense even helped me out with them. But from flask-marshmallow import Marshmallow
didn't seem to work.
When I ran python app.py
I get the following error
Traceback (most recent call last):
File "app.py", line 3, in <module>
from flask_marshmallow import Marshmallow
ModuleNotFoundError: No module named 'flask_marshmallow'
I've tried uninstalling flask-marshmallow and marshmallow and reinstalling. The console always says the installation is successful but I can't seem to import it when all the other packages seem to work fine.
What a great start to a new language xD Here is the whole file so far for reference, if I remove the marshmallow line it starts without any issues
from flask import Flask, request, jsonify
from flask_sqlalchemy import SQLAlchemy
from flask_marshmallow import Marshmallow
import os
app = Flask(__name__)
if __name__ == "__main__":
app.run(debug=True)
Make sure that, because you have created a pipenv
, you have set the Python interpreter path correctly in your IDE.
I was facing the exact issue (and that is how I reached this question). I am using VS code, was using python3.8
and pipenv
.
Even though I have installed the packages using pip3
, I was facing import issues while running the code. After a futile search on the Internet, I realised that the issue was very silly.
The Python interpreter path (Cntrl+Shift+P
-> Select Interpreter
) was not set to the newly created pipenv
. After I have set the interpreter path properly, the code resumed to function as expected.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With