The flask module has been installed using pip install (screenshot), However, when executing the code in the command line cmd ModuleNotFoundError: No module named 'flask May I ask what I should do Solution for beginners
This is a confusion caused by the possibility that the same computer has more than two Python environments. Please try executing the following code in all your Python environments:
from distutils.sysconfig import get_python_lib
print(get_python_lib())
For example, my computer has two Python environments, one is IDLE and the other is Anaconda. The above executed program will have the following different results:
It can be seen that the two Python environments are separate. One Python environment is isolated from the other. Your situation should be to confirm whether the environment where you pip install is consistent with the environment where you execute the code. You can check to see that the site-packages directory in the environment where you cannot run import flask does not have a flask directory, and the one you installed with pip install is another environment.
So first check the environment (get_python_lib() code), check whether the install and execution codes are consistent, and then install pip install flask.
You first open cmd, then enter python, and then perform the following operations:
import flask
Check if it runs successfully. It should be noted that if you are using an IDE such as PyCharm to install flask, it will not be found under cmd. Can only be run in PyCharm.
This is a confusion caused by the possibility that the same computer has more than two Python environments. Please try executing the following code in all your Python environments:
For example, my computer has two Python environments, one is IDLE and the other is Anaconda. The above executed program will have the following different results:
It can be seen that the two Python environments are separate. One Python environment is isolated from the other. Your situation should be to confirm whether the environment where you pip install is consistent with the environment where you execute the code. You can check to see that the site-packages directory in the environment where you cannot run import flask does not have a flask directory, and the one you installed with pip install is another environment.
So first check the environment (get_python_lib() code), check whether the install and execution codes are consistent, and then install pip install flask.
If you’re right, you’re right
You first open cmd, then enter python, and then perform the following operations:
Check if it runs successfully. It should be noted that if you are using an IDE such as PyCharm to install flask, it will not be found under cmd. Can only be run in PyCharm.
Have you installed this module