error when running flask - no module with name '_crypt' - python

i have a problem running flask. It started fine until I loaded a simple login form.
when running flask via gitbash, I get an error like this
flask run
* Environment: production
WARNING: This is a development server. Do not use it in a production deployment.
Use a production WSGI server instead.
* Debug mode: off
Usage: flask run [OPTIONS]
Try 'flask run --help' for help.
Error: While importing 'app', an ImportError was raised:
Traceback (most recent call last):
File "C:\Users\****\AppData\Local\Programs\Python\Python39\lib\crypt.py", line 6, in <module>
import _crypt
ModuleNotFoundError: No module named '_crypt'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\****\AppData\Local\Programs\Python\Python39\lib\site-packages\flask\cli.py", line 234, in locate_app
__import__(module_name)
File "E:\Program Files\xampp\htdocs\****\app.py", line 2, in <module>
from crypt import methods
File "C:\Users\****\AppData\Local\Programs\Python\Python39\lib\crypt.py", line 9, in <module>
raise ImportError("The crypt module is not supported on Windows")
ImportError: The crypt module is not supported on Windows
btw, i used windows

remove this from the top of the file:
from crypt import methods
it should work again. At least it did for me. VSCode may have autogenerated this for you.

This thing occur most times with auto-import in vs code.
If you inspect your code critically, you'd notice that your vs-code editor has automatically included the line of code from crypt import methods above your imports.
Just comment or delete it out and try re-running your app again, you'd be in good shape.

Related

Visual Studio Code ModuleNotFoundError: No module named '_overlapped'

I have developed the following message when running flask. I attempted to add overlapped, via pip install overlap. I can't find answers to this. This is my terminal output. Can someone please help?
dvdjms#DESKTOP-OPG4GRH:/mnt/c/Users/dvdjm/Documents/CS50/project$ flask run
Usage: flask run [OPTIONS]
Try 'flask run --help' for help.
Error: While importing 'app', an ImportError was raised:
Traceback (most recent call last):
File "/home/dvdjms/.local/lib/python3.8/site-packages/flask/cli.py", line 218, in locate_app
__import__(module_name)
File "/mnt/c/Users/dvdjm/Documents/CS50/project/app.py", line 1, in <module>
from asyncio.windows_events import NULL
File "/usr/lib/python3.8/asyncio/windows_events.py", line 3, in <module>
import _overlapped
ModuleNotFoundError: No module named '_overlapped'
Did you mean to import NULL from asyncio.windows_event? I'm guessing it was automatically imported by your IDE, None is likely what you're looking for instead of NULL, which isn't a keyword in Python.

For what reason would a Flask application run fine, but fail to load a module in the unittest?

So, I created a small flask API. Basically a wrapper for another API.
I used requests-futures to send multiple calls asynchronously.
I set up my virtual environment. Everything works exactly as I intend. However, when I try to run some tests I've written (using python -m unittest) this is the error I get:
======================================================================
ERROR: test (unittest.loader._FailedTest)
----------------------------------------------------------------------
ImportError: Failed to import test module: test
Traceback (most recent call last):
File "/usr/lib/python3.8/unittest/loader.py", line 436, in _find_test_path
module = self._get_module_from_name(name)
File "/usr/lib/python3.8/unittest/loader.py", line 377, in _get_module_from_name
__import__(name)
File "/home/cwverica/take-home-apps/quixr/test.py", line 2, in <module>
from app import app, session
File "/home/cwverica/take-home-apps/quixr/app.py", line 3, in <module>
from requests_futures.sessions import FuturesSession
ModuleNotFoundError: No module named 'requests_futures'
I have reinstalled the module using pip. I made sure to pip freeze > requirements.txt just in case it was reading module availability from there. But all in all I'm stumped. If anyone could help me out here, I'd greatly appreciate it.

Flask: ModuleNotFoundError: No module named 'SocketServer'

I have a strange error, that I never saw before.
I wrote a small http web server using flask and when I run I got the error bellow.
I am using virtual env and my python version is 3.8
What can be?
from flask import Flask, request
app = Flask(__name__)
#app.route("/")
def index():
print(request.get_json())
if __name__ == "__main__":
app.run(debug=True)
python tools/fake.pyTraceback (most recent call last):
File "/home/ubuntu/workspace/otc/venv/lib/python3.8/site-packages/werkzeug/serving.py", line 58, in <module>
from http.server import BaseHTTPRequestHandler
ModuleNotFoundError: No module named 'http.server'; 'http' is not a package
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "tools/fake.py", line 1, in <module>
from flask import Flask, request
File "/home/ubuntu/workspace/otc/venv/lib/python3.8/site-packages/flask/__init__.py", line 16, in <module>
from werkzeug.exceptions import abort
File "/home/ubuntu/workspace/otc/venv/lib/python3.8/site-packages/werkzeug/__init__.py", line 15, in <module>
from .serving import run_simple
File "/home/ubuntu/workspace/otc/venv/lib/python3.8/site-packages/werkzeug/serving.py", line 61, in <module>
import SocketServer as socketserver
ModuleNotFoundError: No module named 'SocketServer'```
The issue comes from the first traceback:
ModuleNotFoundError: No module named 'http.server'; 'http' is not a package
You need to rename the http.py file to something else because it is overriding the standard library http module. To fix it, you will need to do the following:
Rename the file http.py to something else.
Remove .pyc files in the project
find . -name "*.pyc" -delete
Run the program again
Python3 uses socketserver, all lowercase. Python2 uses SocketServer
this maybe helps you
`
pip uninstall Flask
pip uninstall Werkzeug
pip install Flask
pip install Werkzeug
`

Flask - ModuleNotFoundError, though it is in the same folder - Updated

everyone. Can't understand where my problem is.
My structure is:
But in my cmd I have:
(venv2) C:\Users\chainsaw\Desktop\work\bot-1\archie\autosales_bot>flask run
* Environment: production
WARNING: This is a development server. Do not use it in a production deployme
nt.
Use a production WSGI server instead.
* Debug mode: off
Usage: flask run [OPTIONS]
Error: While importing "autosales_bot.wsgi", an ImportError was raised:
Traceback (most recent call last):
File "c:\users\chainsaw\appdata\local\programs\python\python37-32\lib\site-pac
kages\flask\cli.py", line 240, in locate_app
__import__(module_name)
File "C:\Users\chainsaw\Desktop\work\bot-1\archie\autosales_bot\__init__.py",
line 1, in <module>
from admin_panel.run import generate_password
ModuleNotFoundError: No module named 'admin_panel'
Thanks in advance
Maybe I should run it as
python run.py
?
I have init.py in my apps

Start flask app from console - ModuleNotFoundError

Why, when I try to run a flask application from the console, I encounter an error: ModuleNotFoundError:
$ python run.py
Traceback (most recent call last):
File "run.py", line 1, in <module>
from src.app.controller import app
ModuleNotFoundError: No module named 'src'
or
$ env FLASK_APP=run.py flask run
* Serving Flask app "run.py"
* Environment: production
WARNING: This is a development server. Do not use it in a production deployment.
Use a production WSGI server instead.
* Debug mode: off
Usage: flask run [OPTIONS]
Error: While importing "run", an ImportError was raised:
Traceback (most recent call last):
File "/home/pronect/PycharmProjects/it-informer-master/venv/lib/python3.7/site-packages/flask/cli.py", line 240, in locate_app
__import__(module_name)
File "/home/pronect/PycharmProjects/it-informer-master/src/run.py", line 1, in <module>
from src.app.controller import app
ModuleNotFoundError: No module named 'src'
Here is a project screenshot:
But if I run the application from Paycharm, then everything works fine.
How to solve this problem?
Just try to change the code to this:
from app.controller import app
from config import Config
The file run.py is already in the directory src. The error occurs, because there is no other folder called src in the directory where the file run.py is stored.

Categories

Resources