#π I'm not able to use the Flask module even tho it's installed
16 messages Β· Page 1 of 1 (latest)
@mortal forum
Remember to:
- Ask your Python question, not if you can ask or if there's an expert who can help.
- Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
- Explain what you expect to happen and what actually happens.
:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.
Traceback (most recent call last):
File "/home/project/lab/server.py", line 1, in <module>
from flask import sk
ModuleNotFoundError: No module named 'flask'```
Defaulting to user installation because normal site-packages is not writeable
Requirement already satisfied: flask in /home/theia/.local/lib/python3.11/site-packages (2.2.2)
Requirement already satisfied: Werkzeug>=2.2.2 in /usr/local/lib/python3.11/dist-packages (from flask) (2.2.3)
Requirement already satisfied: Jinja2>=3.0 in /usr/local/lib/python3.11/dist-packages (from flask) (3.1.4)
Requirement already satisfied: itsdangerous>=2.0 in /usr/local/lib/python3.11/dist-packages (from flask) (2.2.0)
Requirement already satisfied: click>=8.0 in /usr/local/lib/python3.11/dist-packages (from flask) (8.1.7)
Requirement already satisfied: MarkupSafe>=2.0 in /usr/local/lib/python3.11/dist-packages (from Jinja2>=3.0->flask) (2.1.5)
[theia: lab]$ ```
from flask import Flask
app = Flask(__name__)
@app.route("/")
def hello_world():
return"<b> my first flask application in action! </b>"```
You likely have a virtual environment enabled for the project, and aren't installing into that environment
!venv
Virtual environments are isolated Python environments, which make it easier to keep your system clean and manage dependencies. By default, when activated, only libraries and scripts installed in the virtual environment are accessible, preventing cross-project dependency conflicts, and allowing easy isolation of requirements.
To create a new virtual environment, you can use the standard library venv module: python3 -m venv .venv (replace python3 with python or py on Windows)
Then, to activate the new virtual environment:
Windows (PowerShell): .venv\Scripts\Activate.ps1
or (Command Prompt): .venv\Scripts\activate.bat
MacOS / Linux (Bash): source .venv/bin/activate
Packages can then be installed to the virtual environment using pip, as normal.
For more information, take a read of the documentation. If you run code through your editor, check its documentation on how to make it use your virtual environment. For example, see the VSCode or PyCharm docs.
Tools such as poetry and pipenv can manage the creation of virtual environments as well as project dependencies, making packaging and installing your project easier.
Note: When using PowerShell in Windows, you may need to change the execution policy first. This is only required once per user:
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser
You need to activate the environment prior to running pip.
How do I use the virtual environment?
Pretty sure I activated it but can't find how to enter it
Okay, I tried it there as well and it still says that the flask module doesn't exist
Make sure the same environment is enabled both when installing the library and running the program.
Okay, I've tried on a independed system, a virtual environment, tried running it, twice, and on visual studios codes, not a single one can even detect flask as a module, and only visual studio and the indendepended can even do "flask run"
This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.