Unable to use Flask - python

I basically used the install command "$pip install Flask" and when I try to run a program it says "module can't be found." Flask is installed in "/usr/local/lib/python2.7/site-packages" but I thought the point of pip was so I could import these packages everywhere. I'm trying to run a file on my desktop and even when I move the Flask folder to the desktop, it doesn't work. Any advice? Thanks!

This may not directly solve whatever problem you are having with path variables, but one alternative would to download virtualenv
Flask actually has a good tutorial on how to accomplish this here

Related

Replit error: /usr/bin/env: ‘./python3’: No such file or directory after using PIP

whenever I type, for an example: pip install aiohttp==3.7.3, it gives me: /usr/bin/env: ‘./python3’: No such file or directory is there any way to fix it? (The error is in REPLIT)
I had problems with using aiohttp in REPLIT, I tried uninstalling package files. I "reinstalled" packages, such as "aiohttp" after doing the problem referred to the title popped up in the console.
I ran into this error as well and haven't been able to solve it.
In the meantime, I use python3 -m instead and it works:
python3 -m <module-name> <args>
Well, go to .replit and delete the Variable called hidden = ["venv", ".config", "**/__pycache__", "**/.mypy_cache", "**/*.pyc"]
after deleting, go to the file directly and download the module to your computer, then upload it to the file it's not in.
I hope this works,
-JKID_Tech
P.S. I tried this IT WORKS if you get python from your computer then go to the python files or try to find it on the internet for example PyPI

ModuleNotFoundError on Centos8

I am trying to run a python script to pull a table from MariaDB. I can run it locally on the MariaDB I installed on my device but when I go to run it on my vm it throws the ModuleNotFoundError. If I run 'pip-safe list' it shows both modules are there but when I run the script I get the error above. I have also tried moving the location that the modules are stored to see if it was a directory issue. I think that it's simply an issue with the import syntax with the '.' in mysql.connector but I can't figure out why. If anyone could help me troubleshoot this that would be greatly appreciated.
Code
Error Message
"pip-safe" was installing the modules to a virtualenv within my system. Where as "sudo pip3" would install to a different directory. When I installed mysql-connector-python via "sudo pip3" and ran the same script I didn't get any errors.
I still don't fully understand why python3 wasn't able to find the modules that were istalled via "pip-safe" but the script is working.

Unable to import Flask without virtual enviroment

So, I have my folder, inside it when I create my venv I can use Flask just fine inside my folder.
However, when I start a new project, I do not have a venv yet. I create my server.py file, and I try to "from flask import Flask" but its all grayed out saying:
"Import "flask" could not be resolvedPylancereportMissingImports"
What is the reason for this, and why do I always need to create a venv for flask to work in my folder? I think it is supposed to work without a venv.
Not working
Working with venv
Do you have flask installed globally?
When you're using a virtual environment, your IDE knows which Python binary to use and the available packages installed. It is therefore aware of flask and can provide language assistance + all of the other relevant features.
When you aren't in a virtual environment, your IDE is defaulting to some Python version on your computer that doesn't have flask as an installed package.
why do I always need to create a venv for flask to work in my folder? I think it is supposed to work without a venv.
As someone who has coded in Python for over 5 years, I highly encourage you to always use a virtual environment. Venvs allow us to avoid installing Python packages globally which could break system tools or other projects.

pip in venv on Windows 10: 'Fatal error in launcher: Unable to create process using '"c:\users\..." ' encountered during flask tutorial

I'm going through the Flask tutorial, and I encounter a problem where I can't use pip (and thus anything else really) a venv in Powershell. The same flask app runs correctly in an Ubuntu terminal with Python 3.6.6 in WSL.
The problem seems to depend on the directory, which makes me think it's somehow related to file path length; I enabled long file paths in the windows Group Editor but this hasn't fixed the problem. In the below steps my venv directory is c:\users\rwgpu\google-drive\code\flask-tutorial\winEnvflaskr\ and I experience the error, but everything works correctly in the directory C:\python\test\testVenv. (in each case I'm running the commands in the directory one up from the listed above, flask-tutorial and test respectively)
Minimal steps to reproduce are:
Completely fresh Python 3.7 installation.
Change directory to app folder.
py -m venv winEnvFlaskr
./winEnvFlaskr/Scripts/activate
pip list
The ultimate goal is to then
pip install FLask
and run the Flask tutorial app. Again, all steps work correctly in Bash on Ubuntu in WSL (running its own Python) and in a different windows directory with the same Python 3.7.
After pip list I get the error:
Fatal error in launcher: Unable to create process using '"c:\users\rwgpu\google-drive\code\flask-tutorial\winenvflaskr\scripts\python.exe" "C:\Users\rwgpu\Google-Drive\Code\flask-tutorial\winEnvFlaskr\Scripts\pip.exe" list'
and if I try
python -m pip list
I get nothing; the terminal hangs for a second and returns with no output. If I run
py -m pip install -U pip
in the bugged venv it will try to install and report success. It will do this again, and will never report "requirement already satisfied" which would be correct.
I had the same problem on Windows with running flask in command line from venv(for example, "(venv)...\flask run"). I resolved the problem with changing path in flask.exe code(open "your_venv\Scripts\flask.exe" with notepad or etc.): in my way I correct the 436-th line at the end; you need to put there "your_absolute_path_to_venv\Scripts\python.exe" instead of the path indicated there.
Good luck!
Well, I still don't know why this was happening -- it persisted through deleting and recreating the venv (obviously), but when I deleted the entire folder, that somehow cleared it up. I just copied the code into a new directory in the same parent and everything seems to be working ¯\_(ツ)_/¯
If anyone knows what would cause this in my case I still welcome input.

How to disable flask global installation

I have created a python project using Flask.Let's call it projectA. I have run the command . flask/bin/activate to make it global. I have created another project called projectB. I ran the same command to make this Flask installation global. Next I try to install python-mysql module in the projectB. However, I noticed that it gets installed in the projectA.
How to fix this issue?
I assumed that If I can deactivate projectA global installation, this issue may be fixed. However, I didn't find a suitable command in the Flask documentation.Even though, I deleted the projectA, it still try to install the mysql module in the projectA.
I don't believe that I got it right: what are your flask folder contents?
I ask it because sometimes it is the virtualenv – a lot of Flask tutorials suggest installing a virtualenv under the flask folder.
If that is the case, it doesn't make the project global. On the contrary: it makes your commands use the local version of Python (the one installed inside the flask/bin folder), and not the global Python installed wihin your operational system.
So, your problem might not be with Flask itself, but with the lack of understanding of virtualenv.
When you run . flask/bin/activate inside project A, whatever you do in terms of Python (pip and easy_install included) will reflect only in the Python installation under project A's flask folder. Until you run deactivate. Does that make sense?
So, maybe the command you need is deactivate so you can jump from one virtualenv to another.
And, as a final advice, take some time to study virtualenv and, from there, go to virtualenvwrapper.

Categories

Resources