windows 10 python modulenotfounderror - python-3.x

I have an issue with Python 3.6.3 on Windows 10.
I have installed flask_bootstrap. Here is my (edited) pip freeze:
C:\Users\pablo\willwriter2>pip freeze
Flask==0.12.2
Flask-Bootstrap==3.3.7.1
When I run a very simple script:
from flask import Flask
from bootstrap import Bootstrap
app = Flask(__name__)
bootstrap = Bootstrap(app)
#app.routes('/')
def homepage():
return "<h1>Hello World</h1>"
I get the following error message:
File "C:\Users\pablo\willwriter2\main2.py", line 2, in <module>
from bootstrap import Bootstrap
ModuleNotFoundError: No module named 'bootstrap'
This error occurs whether I use a virtual environment or the global python install. It has occurred for other modules as well.
Does anyone know why this is happening?
Thanks,
Paul.

Related

Getting a ModuleNotFound error with flask in python

I installed the flask module via following command.[![cmd image][1]][1]
When I ran the following code.
from flask import Flask, render_template
app = Flask(__name__)
#app.route('/')
def index():
#a = input('Enter name')
return render_template(r'form.html')
if __name__ == "__main__":
app.run(debug=True)
It gave an error.
ModuleNotFoundError: No module named 'flask'
Note:- I am not using virtualenv. And I am having my html page in templates folder
[1]: https://i.stack.imgur.com/t4XzJ.png
It seems you have installed flask on the system wide environment. To access the flask in your virtualenv, you have to get into the virtualenv directory and activate it by using following command.
source virtual_env_name/bin/activate
replace 'virtual_env_name' with the virtualenv name you created.
After that in your command line, you will get (virtual_env_name) added before. the current directory path.
Now you can install the flask framework using pip3.
pip3 install flask
Keep in mind to activate venv everytime you are using the flask.

dnspython: module not found in pycharm

I'm trying to connect to MongoDB from the pyCharm environment.
I'm using python 3.8 and I installed pymongo, dnspython and dnspython3.
My settings for the project are:
My code is:
from pymongo import MongoClient
import argparse
import dnspython
if __name__ == "__main__":
client = MongoClient("mongodb+srv://rajnesh:<myPassword>#cluster0-chffs.mongodb.net/test?authSource=admin&replicaSet=Cluster0-shard-0&readPreference=primary&appname=MongoDB%20Compass&ssl=true")
print("Hello there!")
However, I get the following Error:
Traceback (most recent call last): File
"/Users/rajnesh/pyProgram.py", line 17, in
import dnspython ModuleNotFoundError: No module named 'dnspython'
Process finished with exit code 1
Thanks in advance for your help.
For the dnspython package, the import name is "dns". More info about this can be found below:
http://www.dnspython.org/docs/1.16.0/
http://www.dnspython.org/examples.html

"How to fix' ImportError: cannot import name 'SQLAlchemy'

import os
from flask import Flask
from flask_wtf import FlaskForm
import sqlalchemy
from flask_sqlalchemy import SQLAlchemy
bsdir = os.path.abspath(os.path.dirname(__file__))
# print(bsdir)
app = Flask(__name__, template_folder = 'template')
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///'+os.path.join(bsdir,'data.sqlite')
app.config['SQLALCHEMY_TRACK_MODIFICATION'] = False
db = SQLAlchemy(app)
class Puppy(db.Model):
pass
Traceback (most recent call last):
File "D:\PYTHON\GIT_EXC\FLASK_\flask_sqlalchemyex.py", line 5, in
from flask_sqlalchemy import SQLAlchemy File "D:\PYTHON\GIT_EXC\FLASK_\flask_sqlalchemy.py", line 4, in
from flask_sqlalchemy import SQLAlchemy ImportError: cannot import name 'SQLAlch
Try using this command
pip install flask-sqlalchemy --user
It worked for me
And If you are using PyCharm go to file
Select Invalidate caches and restart
Try to install it with these commands , (it worked for me):
pip install flask-sqlalchemy
pip3 install flask-sqlalchemy
Refer this site for Example
or
Refer the official guide site for installation
if it doesnt worked then try above commands with --user at the end of both commands
another solution maybe to install an IDE (if you are not using one) like PyCharm ; rather than a some simple text editors
First command installs package to python v2.x
Second one installs package to python 3.x
If you want to use 3.x to run your app ;then go to configuration and change it to python 3.x
Refer this for Getting Help / Development / Bug reporting
Try changing the name of your .py file. It may be causing a conflict with the flask-sqlalchemy package.
"D:\PYTHON\GIT_EXC\FLASK_\flask_sqlalchemy.py"
I faced same issue while instantiating airflow db by command
$airflow db init
error: ImportError: cannot import name 'SQLAlchemyAutoSchema'
Fixes:
Uninstall:
$pip uninstall marshmallow-sqlalchemy
Then upgrade it to version 0.24.0
$pip3 install marshmallow-sqlalchemy==0.24.0
My problem resolved and able to initialize airflow db.

ImportError: cannot import name 'cluster_resolver'

I get this error when trying to setup Unity3d ml-agents
ImportError: cannot import name 'cluster_resolver'
Following https://github.com/Unity-Technologies/ml-agents/blob/master/docs/Installation.md tutorial
from tensorflow.contrib import cluster_resolver
Error happens when I try to run mlagents-learn --help
I am on MacOS with Python 3.6
Fixed by using Tensorflow 1.7.0 instead of 1.7.1 as in the tutorial.

pyramid.config.Configurator() does not work with 'with' context manager

Is trying the quick start guide in pyramid website: https://trypyramid.com
from wsgiref.simple_server import make_server
from pyramid.config import Configurator
from pyramid.request import Response
def hello_world(request):
return Response('Hello World')
if __name__ == "__main__":
with Configurator() as config:
config.add_route('hello','/')
config.add_view(hello_world, route_name='hello')
app = config.make_wsgi_app()
server = make_server('0.0.0.0',6543,app)
Gives the following error:
/anaconda3/bin/python /Users/user1/Desktop/play/pyramid_play/tut_1/exp1.py
Traceback (most recent call last):
File "/Users/user1/Desktop/play/pyramid_play/tut_1/exp1.py", line 12, in <module>
with Configurator() as config:
AttributeError: __enter__
Process finished with exit code 1
Thanks Steve Piercy. This was an installation problem. I let pycharm install Pyramid while creating the project. pycharm used conda to install the package, which installed v1.5.7 (latest on conda repos) instead of the 1.9.1 (current version).
I installed pip to install the latest version which fixed the issue.

Resources