Reputation: 29
I'm on Windows 10 and I am using PyCharm to run my application. I'm pretty new to Python and just coding in general.
I typed:
pip install flask
in the cmd prompt but forgot to open cmd prompt under administrator privileges. Could this be the problem? I ended up re-opening the cmd prompt with administrator rights and typed
pip install flask
again and it showed that it was already installed. I'm pretty sure I have flask installed on my system.
When I try to run the python file below which I named test_webapp.py I get the following error:
from flask import Flask
app = Flask(__name__)
@app.route("/")
def hello():
return "Hello World!"
if __name__ == "__main__":
app.run()
I get an error:
ModuleNotFoundError: No module named 'flask'
when i type in python --version into the command prompt i get version 3.6.3.
When i type the same code into the Python 3.6 (32-bit) command line, the code works! However, when i try to run it using the IDLE I get a SyntaxError and the number 6 in Python 3.6.3 gets highlighted in red.
Any ideas as to what's going on?
Upvotes: 1
Views: 10484
Reputation: 19
Check version of python
python --version
And then use accordingly if python 3.x.x then type
python3 app.py
if python 2.x.x then type
python2 app.py
Upvotes: 0
Reputation: 11
When you typed pip install flask in the command prompt, it installed flask in the global environment. That is the reason when you run it in command line it works because it used global environment by default.
Pycharm has a virtual environment, therefore you need to install it in that virtual environment. Open Pycharm, then open the terminal within Pycharm and type "pip install flask".
You can read about virtual environment in python to get a clear idea.
Upvotes: 1
Reputation: 685
Sounds like the pip you are using is not installing for the same python you are using.
try which pip
and which python
the they should be in the same folder. Might want to make an alias or two if you have a bunch of pythons (sys, 2, 3, conda etc) or just start with a fresh virtual env for your project. <- best imo.
Upvotes: 1
Reputation: 335
Try to install flask with specific version of python, do something like:
python[version] -m pip install flask
Note: replace [version] with python version (such as python3).
Upvotes: 3