Home  >  Q&A  >  body text

python flask module cannot be called

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

PHP中文网PHP中文网2686 days ago945

reply all(4)I'll reply

  • 仅有的幸福

    仅有的幸福2017-06-12 09:29:37

    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:

    c:\python36\Lib\site-packages
    
    C:\ProgramData\Anaconda3\Lib\site-packages
    

    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.

    reply
    0
  • 阿神

    阿神2017-06-12 09:29:37

    pip install flask
    
    python
    >> import flask
    

    If you’re right, you’re right

    reply
    0
  • 淡淡烟草味

    淡淡烟草味2017-06-12 09:29:37

    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.

    reply
    0
  • 阿神

    阿神2017-06-12 09:29:37

    Have you installed this module

    reply
    0
  • Cancelreply