In fact I cannot use any pakage now!
importerror: no module named flask.ext.script
importerror: no module named Pymongo
It seems that you virtual environment doesn't work. You've installed the flask-script package, but when you run the script, it still looks for it in C:\Python3.4. You may give us more info so that we can figure it out where is wrong. (How do you install it, how do you active the virtualenv, does reinstall virtualenv work, close the cmd shell and try again works?)
Also note that from flask.ext.extension import xxx is the old way to use the flask extension. Instead you should use from flask_script import Manager, Server if you are using the latest flask-script 2.0.5
If you are using the IDE such as pycharm, then maybe need to set the interpreter of python for the right version. Otherwise the packages that you have installed can not be used for the current project. I have also encountered such kind of questions until I set my IDE's interpreter to the Python 2.7.
Then you can freely import the flask_script
I think you should use python 2 to use this module flask.ext.script" because this is the old way of doing it, or you could install Flask-Script and import it this way from flask_script import ...
from flask.ext.extension import xxx is the old way of importing extensions ,now it's not working .You have to freeze first to outputs the package and its version installed in the current environment . Then you can check your module and import it as usual
e.g: -from flask_bcrypt import Bcrypt
#this import the Bcrypt from flask_bcrypt
Related
Here is my file structure and requirements.txt:
Getting ModuleNotFoundError, any help will be appreciated.
main.py
from fastapi import FastAPI
from .import models
from .database import engine
from .routers import ratings
models.Base.metadata.create_all(bind=engine)
app = FastAPI()
app.include_router(ratings.router)
The error comes from the fact that you were not using the right environment and python version on VSCODE.
Your environment knew your different packages, but VSCode probably did not take them into account.
The solution was, in VSCODE: CTRL + SHIFT + P then Python:select interpreter and choose the version of python linked to your environment.
You can try to change the version of python to see the consequences on your imports
Try this to install all dependencies:
$ pip install "fastapi[all]"
Try this :
python -m pip install fastapi uvicorn[standard]
I am attempting to run the following code which I received from samples here
from __future__ import print_function
import atexit
from pyVim.connect import SmartConnectNoSSL, Disconnect
from pyVmomi import vim
from tools import cli
I am receiving the following error:
ModuleNotFoundError: No Module named 'pyVim.connect'
The packages in question are from here and were installed using:
pip install pyvmomi
Is there something wrong with how I am installing these packages?
Looks like the code was a bit old. Importing 'pyvim' instead of 'pyVim' worked, though it seems to be named 'pyVim' on the github.
It's possible that you need to reinstall pvmomi to force the re-install of additional files in the pyVim/ package dir:
pip3 install --force pyvmomi
I haven't figured out how or what causes this, but the issue seems to occur on case-insensitive macOS file systems.
Since it has different behavior than Linux and case-sensitive macOS, I use the following "hack" to make it compatible between systems:
try:
from pyVim.connect import SmartConnectNoSSL
except ImportError:
from pyvim.connect import SmartConnectNoSSL
PS: You can use diskutil info / on macOS to figure out if your file system is case-sensitive or not (Details in another StackExchange question)
I am used to see import errors of my own modules.
But this time, this is about modules installed via pip and located in site-packages.
Here is a test file expurged from everything but just the imports :
import flask
import pygments
from flask_restful import Resource, Api
#from weather_tool import *
#from flask_restless import *
while running pytest :
Traceback:
test_MonAPPflaskRest.py:3: in <module>
from flask_restful import Resource, Api
E ModuleNotFoundError: No module named 'flask_restful'
Actually, every module with an underscore will fail !!!
flask_restless will fail to import to.
But it work when executed outside of pytest, or simply on the python shell...
Ok, I went through it.
Actually, Anaconda was installed. From here, no problem with that.
I installed Python from source as I'm used to do on a Linux platform and it works normally as expected.
I found out that pytest was not is the list of packages installed via pip.
Seems Anaconda provides a default pytest install. Maybe something is wrong with this version. (which pytest will return a pystest file in the python bin directory.
Actually, a simple pip install pytest in your virtualenv will 'overwrite' this - maybe messy - pytest version.
However calling pytest won't still work. You have to user py.test.
I know this is pretty much empirical. But that's it...
I got a similar error while importing stocker (Unable to find stocker module).
Try adding your 'code directory' to 'sys.path' where python looks for modules and it should be able to import then.
For more details:
https://bic-berkeley.github.io/psych-214-fall-2016/sys_path.html
I used the code:
>>> import sys
>>> sys.path.append('code') # code = the directory where your module is saved
>>> # Now the import will work
>>> import a_module # a_module = the module you are trying to import
I also faced the same issue when installed in virtual environment. I've deactivated virtual environment, installed flask-restful from PIP and then activated virtual environment. The issue is resolved.
I'm new at this and have no idea of what I'm doing wrong:
I have installed the flask_login module with
pip install flask_login
It apparently worked: if see it installed in c:\users\~\python\python36-32\lib\site-packages
And when I use pip list, I can see it listed as Flask-Login (0.4.0)
Despite of this, when I try to run from flask_login import LoginManager, I'm getting ImportError: No module named flask_login.
What am I doing wrong?
I figured out what was happening.
For some reason, Anaconda installed Python 2.7 in a path that was colliding with the one I use normally (w/ Python 3). Once I uninstalled Python 2.7, everything worked fine.
For some reason, only flask_login was being affected. My other flask_** libraries were working fine.
In case you are experiencing this in a Python environment with Apache2 and mod_wsgi: you have to restart the Apache2 server after installing new Python modules, as otherwise Apache2 will not "see" them even though the Python path is correct. So (assuming Debian / Ubuntu Linux):
service apache2 restart
Of course, this issue could happen with any module not being found, not just with flask_login. It just happened to me with flask_login, which is why I'm here …
I had the same problem and was able to solve using sudo:
sudo pip install flask_login
I think import errors are so common in flask because flask users normally work in virtual environments. Running pip install inside a VE or outside leads to different installations in different paths and can cause confusion. sudo installation works globally and can be a solution if you don't need a certain dependency in a specific VE.
I was using VS code. In the .venv there was another copy of flask_login so basically just check if another copy of flask_login exists within your lib
I have the following code :
#!/usr/bin/env python2
#coding: utf-8
from flask import Flask, render_template
from flask.ext.flatpages import FlatPages
from flask.ext.markdown import Markdown
But when I try to run it, this error occurs : ImportError: No module named flask.ext.markdown whereas normally this module is existing.
Is there somebody who can say how to fix that ?
It seems you need to install the flask-markdown plugin.
http://pythonhosted.org/Flask-Markdown/
You can install this with pip:
pip install flask-markdown
alternatively:
easy_install flask-markdown
If it is already installed try downloading the source and importing it directly.
That module hasn't been updated in over 3 years and uses the old flask extension API. There is a newer package called flask-markdown2.