Python — нет модуля с именем «PyMySQL»

Я пытаюсь добавить «PyMySQL, но он продолжает выдавать

Traceback (most recent call last):
  File "/home/john/workspace/Python/sql/sql.py", line 1, in <module>
    import PyMySQL
ImportError: No module named 'PyMySQL'

Я попытался установить его через pip и снова запустить, но ошибка не исчезла. Любые идеи о том, что не так?

john@john-PC:$ sudo pip install PyMySQL
The directory '/home/john/.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/john/.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.
Collecting PyMySQL
/usr/local/lib/python2.7/dist-packages/pip/_vendor/requests/packages/urllib3/util/ssl_.py:318: SNIMissingWarning: An HTTPS request has been made, but the SNI (Subject Name Indication) extension to TLS is not available on this platform. This may cause the server to present an incorrect TLS certificate, which can cause validation failures. You can upgrade to a newer version of Python to solve this. For more information, see https://urllib3.readthedocs.org/en/latest/security.html#snimissingwarning.
  SNIMissingWarning
/usr/local/lib/python2.7/dist-packages/pip/_vendor/requests/packages/urllib3/util/ssl_.py:122: InsecurePlatformWarning: A true SSLContext object is not available. This prevents urllib3 from configuring SSL appropriately and may cause certain SSL connections to fail. You can upgrade to a newer version of Python to solve this. For more information, see https://urllib3.readthedocs.org/en/latest/security.html#insecureplatformwarning.
  InsecurePlatformWarning
  Downloading PyMySQL-0.7.9-py2-none-any.whl (78kB)
    100% |████████████████████████████████| 81kB 1.3MB/s 
Installing collected packages: PyMySQL
Successfully installed PyMySQL-0.7.9

john@john-PC:$ pip install PyMySQL
Requirement already satisfied (use --upgrade to upgrade): PyMySQL in /usr/local/lib/python2.7/dist-packages

john@john-PC:$ sudo apt-get install python3-pymysql
Reading package lists... Done
Building dependency tree       
Reading state information... Done
python3-pymysql is already the newest version.
0 upgraded, 0 newly installed, 0 to remove and 56 not upgraded.

sql.py

import PyMySQL
print("Here")

Решение. Это была комбинация двух ответов ниже, а также онлайн-отчет об ошибке.

apt-get install software-properties-common
add-apt-repository cloud-archive:mitaka
apt-get update && apt-get dist-upgrade 
sudo apt-get install python3-pymysql
import pymysql

person AJ_    schedule 23.10.2016    source источник
comment
как вы запускаете свой скрипт?   -  person Loïc    schedule 23.10.2016
comment
@Лоик /usr/bin/python3 sql.py   -  person AJ_    schedule 23.10.2016
comment
Python 3.4.3 (по умолчанию, 14 сентября 2016 г., 12:36:27) [GCC 4.8.4] в Linux Для получения дополнительной информации введите help, Copyright, Credits или License. ››› pymysql Traceback (последний последний вызов): файл ‹stdin›, строка 1, в ‹module› NameError: имя 'pymysql' не определено ›››   -  person AJ_    schedule 23.10.2016


Ответы (6)


Попробуйте запустить

sudo apt-get установить python3-pymysql

для питона3.

Уже ответил здесь на stackoverflow.com

person warl0ck    schedule 23.10.2016
comment
sudo apt-get install python3-pymysql Чтение списков пакетов... Готово Построение дерева зависимостей Чтение информации о состоянии... Готово E: Не удалось найти пакет python3-pymysql - person AJ_; 23.10.2016
comment
Мне пришлось запустить некоторые обновления/и другие библиотеки. Затем измените имя на pymysql - person AJ_; 24.10.2016
comment
Спасибо @John, моя проблема также заключалась в использовании прописных букв - person Levi; 14.12.2016

После установки «PyMySQL» вам также необходимо обновить the _init__.py, добавив import pymysql
pymysql.install_as_MySQLdb()
и заменив MySQLdb на pymysql в файле base.py.

person Zhengdong Pan    schedule 15.03.2018

Недавно у меня была такая же проблема. И я решил это, используя это:

sudo pip-3.2 install pymysql**3**

Эти 3 в pymysql3 имели большое значение.

Это было на Raspberry Pi с хрипом

person Luciano Oliveira    schedule 23.09.2017

Причина, по которой он выдает ошибку даже после установки правильных пакетов, связана с используемым именем. Это должно быть «импортировать pymysql» вместо «импортировать PyMySQL». Это сработало для меня.

person abhishek kumar    schedule 28.09.2017

Использование Debian 9 и вызов python3 из BASH.

import pymysql

работал на меня

import PyMySql

не удалось с

Traceback (последний последний вызов): файл «», строка 1, в NameError: имя «PyMySQL» не определено

person Jesse Croucher    schedule 26.01.2018

Это сработало для меня:

#!/usr/bin/env python3

#Importing needed modules of PyMySQL
from pymysql import connect, err, sys, cursors

#Doing our connection
conn = connect( host = 'localhost',

cursor = conn.cursor( cursors.DictCursor );
person Ion Chirita    schedule 02.04.2019