Solucionado (ver solução)
Solucionado
(ver solução)
12
respostas

Falhas ao conectar ao banco

olá pessoal.

Eu já tentei de muitas maneiras diferentes usar o módulo do flask mysql. Não sei o pq não consigo. Já usei:

from flask.ext import MySQL
from flask_mysqldb import MySQL

Mas só tomo erro.

Traceback (most recent call last):
  File "app.py", line 5, in <module>
    from flask_mysqldb import MySQL
ImportError: No module named flask_mysqldb

Alguém tem alguma ajuda para mim?

PS.: o Import MySQLdb funciona.

12 respostas

Marcos,

E só vc instalar este modulo:

pip install flask_mysql

olá no meu terminal diz que já está instalado, mas o erro persiste.

=/

Qual erro?

ta aqui toda a pilha

vinicius@vinicius-VPCEG17FB:~/Documentos/Flask projects/ForIt$ sudo pip install flask_mysql
[sudo] senha para vinicius:
The directory '/home/vinicius/.cache/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
The directory '/home/vinicius/.cache/pip' or its parent directory is not owned by the current user and caching wheels has been disabled. check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
Requirement already satisfied: flask_mysql in /usr/local/lib/python3.5/dist-packages (1.4.0)
Requirement already satisfied: Flask in /usr/local/lib/python3.5/dist-packages (from flask_mysql) (1.0.2)
Requirement already satisfied: PyMySQL in /usr/local/lib/python3.5/dist-packages (from flask_mysql) (0.8.1)
Requirement already satisfied: itsdangerous>=0.24 in /usr/local/lib/python3.5/dist-packages (from Flask->flask_mysql) (0.24)
Requirement already satisfied: Werkzeug>=0.14 in /usr/local/lib/python3.5/dist-packages (from Flask->flask_mysql) (0.14.1)
Requirement already satisfied: Jinja2>=2.10 in /usr/local/lib/python3.5/dist-packages (from Flask->flask_mysql) (2.10)
Requirement already satisfied: click>=5.1 in /usr/local/lib/python3.5/dist-packages (from Flask->flask_mysql) (6.7)
Requirement already satisfied: MarkupSafe>=0.23 in /usr/lib/python3/dist-packages (from Jinja2>=2.10->Flask->flask_mysql) (0.23)
You are using pip version 10.0.1, however version 18.0 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
vinicius@vinicius-VPCEG17FB:~/Documentos/Flask projects/ForIt$ python app.py
Traceback (most recent call last):
  File "app.py", line 5, in <module>
    from flask_mysqldb import MySQL
ImportError: No module named flask_mysqldb
vinicius@vinicius-VPCEG17FB:~/Documentos/Flask projects/ForIt$ python app.py
Traceback (most recent call last):
  File "app.py", line 5, in <module>
    from flask_mysql import MySQL
ImportError: No module named flask_mysql

Marcos,

O próprio PIP já esta falando o possível problema, vc esta usando um versão muito antiga do mesmo!

"You are using pip version 10.0.1, however version 18.0 is available."

Atualiza o seu pip, como demostrado por ele:

pip install --upgrade pip

depois o flask_mysql vai instalar normalmente:

pip install flask_mysql

que coisa não?! xD

mas agora veja o que aconteceu.

vinicius@vinicius-VPCEG17FB:~/Documentos/Flask projects/ForIt$ pip install --upgrade pip
Requirement already up-to-date: pip in /usr/local/lib/python3.5/dist-packages (18.0)
vinicius@vinicius-VPCEG17FB:~/Documentos/Flask projects/ForIt$ pip install flask_mysql
Requirement already satisfied: flask_mysql in /usr/local/lib/python3.5/dist-packages (1.4.0)
Requirement already satisfied: Flask in /usr/local/lib/python3.5/dist-packages (from flask_mysql) (1.0.2)Requirement already satisfied: PyMySQL in /usr/local/lib/python3.5/dist-packages (from flask_mysql) (0.8.1)
Requirement already satisfied: click>=5.1 in /usr/local/lib/python3.5/dist-packages (from Flask->flask_mysql) (6.7)
Requirement already satisfied: itsdangerous>=0.24 in /usr/local/lib/python3.5/dist-packages (from Flask->flask_mysql) (0.24)
Requirement already satisfied: Jinja2>=2.10 in /usr/local/lib/python3.5/dist-packages (from Flask->flask_mysql) (2.10)
Requirement already satisfied: Werkzeug>=0.14 in /usr/local/lib/python3.5/dist-packages (from Flask->flask_mysql) (0.14.1)
Requirement already satisfied: MarkupSafe>=0.23 in /usr/lib/python3/dist-packages (from Jinja2>=2.10->Flask->flask_mysql) (0.23)
vinicius@vinicius-VPCEG17FB:~/Documentos/Flask projects/ForIt$
vinicius@vinicius-VPCEG17FB:~/Documentos/Flask projects/ForIt$ python app.py
Traceback (most recent call last):
  File "app.py", line 5, in <module>
    from flask_mysql import MySQL
ImportError: No module named flask_mysql
vinicius@vinicius-VPCEG17FB:~/Documentos/Flask projects/ForIt$

Marcos,

Só por curiosidade, no seu terminal, digita?

python --version

eu uso a versão 2.7.12

Marcos,

Vc tem que usar o pip da versão 2.7.12, digita no terminal que vai funcionar? Desculpe eu deveria ter comentado isso antes!

Atualiza o seu pip, como demostrado por ele:

pip2.7 install --upgrade pip

depois o flask_mysql vai instalar normalmente:

pip2.7 install flask_mysql

eu que peço desculpa pela insistência. Mas...:

vinicius@vinicius-VPCEG17FB:~/Documentos/Flask projects/ForIt$ sudo pip2.7 install --upgrade pip
/usr/local/lib/python2.7/dist-packages/pip/_vendor/requests/__init__.py:83: RequestsDependencyWarning: Old version of cryptography ([1, 2, 3]) may cause slowdown.
  warnings.warn(warning, RequestsDependencyWarning)
The directory '/home/vinicius/.cache/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
The directory '/home/vinicius/.cache/pip' or its parent directory is not owned by the current user and caching wheels has been disabled. check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
Requirement already up-to-date: pip in /usr/local/lib/python2.7/dist-packages (18.0)vinicius@vinicius-VPCEG17FB:~/Documentos/Flask projects/ForIt$ sudo pip2.7 install flask_mysql
/usr/local/lib/python2.7/dist-packages/pip/_vendor/requests/__init__.py:83: RequestsDependencyWarning: Old version of cryptography ([1, 2, 3]) may cause slowdown.
  warnings.warn(warning, RequestsDependencyWarning)
The directory '/home/vinicius/.cache/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
The directory '/home/vinicius/.cache/pip' or its parent directory is not owned by the current user and caching wheels has been disabled. check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
Requirement already satisfied: flask_mysql in /usr/local/lib/python2.7/dist-packages (1.4.0)
Requirement already satisfied: Flask in /usr/local/lib/python2.7/dist-packages (from flask_mysql) (0.12.2)
Requirement already satisfied: PyMySQL in /usr/local/lib/python2.7/dist-packages (from flask_mysql) (0.9.2)
Requirement already satisfied: Jinja2>=2.4 in /usr/local/lib/python2.7/dist-packages (from Flask->flask_mysql) (2.10)
Requirement already satisfied: Werkzeug>=0.7 in /usr/local/lib/python2.7/dist-packages (from Flask->flask_mysql) (0.14.1)
Requirement already satisfied: click>=2.0 in /usr/local/lib/python2.7/dist-packages (from Flask->flask_mysql) (6.7)
Requirement already satisfied: itsdangerous>=0.21 in /usr/local/lib/python2.7/dist-packages (from Flask->flask_mysql) (0.24)
Requirement already satisfied: cryptography in /usr/lib/python2.7/dist-packages (from PyMySQL->flask_mysql) (1.2.3)
Requirement already satisfied: MarkupSafe>=0.23 in /usr/local/lib/python2.7/dist-packages (from Jinja2>=2.4->Flask->flask_mysql) (1.0)
vinicius@vinicius-VPCEG17FB:~/Documentos/Flask projects/ForIt$ python app.py
Traceback (most recent call last):
  File "app.py", line 5, in <module>
    from flask_mysql import MySQL
ImportError: No module named flask_mysql
vinicius@vinicius-VPCEG17FB:~/Documentos/Flask projects/ForIt$
solução!

Consegui arrumar cara! Esse foi o comando que usei

 sudo pip2.7 install flask_mysqldb

e fiz o import do :

flast_mysqldb

obrigado