Lỗi tên: tên pymysql không được xác định

GHI CHÚ. PyMySQL không hỗ trợ API cấp thấp mà _mysql cung cấp như data_seek, store_result và use_result. Bạn nên sử dụng API cấp cao được xác định trong PEP 249. Nhưng một số API như autocommit và ping được hỗ trợ vì PEP 249 không bao gồm trường hợp sử dụng của chúng

  • Python - một trong những điều sau đây

  • Máy chủ MySQL - một trong những điều sau đây

Gói được tải lên trên PyPI

Bạn có thể cài đặt nó với pip

$ python3 -m pip install PyMySQL

Để sử dụng “sha256_password” hoặc “caching_sha2_password” để xác thực, bạn cần cài đặt phụ thuộc bổ sung

Này các bạn

Tôi gặp sự cố khi nhập PyMySQL. Vì vậy, tôi đã cài đặt PyMySQL bằng cách


khi tôi cố gắng nhập PyMySQL

Một lỗi xuất hiện cho biết "ImportError. Không có mô-đun nào có tên PyMySQL" khi chạy mã

Sau đó tôi đã kiểm tra xem PyMySQL đã được cài đặt thành công hay chưa bằng cách


"PyMySQL    0. 8. 1 " xuất hiện trong danh sách

Điều tiếp theo tôi cần kiểm tra để mã hoạt động là gì

Tôi đang sử dụng MacBook với MacOS10. 13. 4

Tôi đã thử cài đặt nó qua pip và chạy lại, nhưng lỗi không biến mất. Bất kỳ ý tưởng về những gì là sai?

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 //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 //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"]

Dung dịch. Đó là sự kết hợp của hai câu trả lời bên dưới, cộng với một báo cáo lỗi trực tuyến

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
- stackoverflow. com

ghi bàn. 3

câu trả lời được chấp nhận

thử chạy

sudo apt-get cài đặt python3-pymysql

cho trăn3

Đã trả lời ở đây tại stackoverflow. com

Đọc thêm

ghi bàn. 0

Tôi đã có cùng một vấn đề này gần đây. Và tôi đã giải quyết nó bằng cái này

sudo pip-3.2 install pymysql**3**

3 cái đó trong pymysql3 đã tạo nên sự khác biệt

Đó là trên một pi mâm xôi với khò khè

ghi bàn. 0

Lý do nó gây ra lỗi, ngay cả sau khi cài đặt đúng gói là do tên đang được sử dụng. Nó phải là "nhập pymysql" thay vì "nhập PyMySQL". Điều này làm việc cho tôi

Câu hỏi và câu trả lời tương tự

ghi bàn. 0

Sử dụng Debian 9 và gọi python3 từ BASH

import pymysql

đã làm cho tôi

import PyMySql

thất bại với

Traceback [cuộc gọi gần đây nhất cuối cùng]. Tệp "", dòng 1, trong NameError. tên 'PyMySQL' không được xác định

ghi bàn. 0

Điều này làm việc cho tôi

#!/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 ];

ghi bàn. 0

Tôi nhận thấy rằng nếu tôi sử dụng GUI Phiên dịch Thêm gói của PyCharm thì máy tính của tôi có thể tìm thấy pymysql

Tôi chỉ gặp sự cố này khi sử dụng VSCode

ghi bàn. 0

Sử dụng pip hoặc pipenv để cài đặt phần phụ thuộc PyMySQL

________số 8

HOẶC

pipenv install PyMySQL

Sau đó thêm phần này vào cài đặt của bạn. tập tin py [django]

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 //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 //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.
0

Đó là tất cả. Điều này làm việc cho tôi

ghi bàn. 2

Sau khi cài đặt "PyMySQL", bạn cũng cần cập nhật

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 //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 //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.
1, thêm
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 //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 //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.
2 và thay thế MySQLdb thành pymysql trong
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 //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 //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.
3

Làm cách nào để cài đặt PyMySQL trong python3?

Gõ "cmd" vào thanh tìm kiếm và nhấn Enter để mở dòng lệnh. Cái này là cái gì? . Điều này cài đặt pymysql cho cài đặt Python mặc định của bạn. Type “ pip install pymysql ” [without quotes] in the command line and hit Enter again. This installs pymysql for your default Python installation.

Làm cách nào để cài đặt PyMySQL trong Mã VS?

Để cài đặt pymysql trong Visual Studio Code. .
Nhấn CTRL + ` [Backtick] trên bàn phím của bạn để mở thiết bị đầu cuối
Chạy lệnh pip install pymysql để cài đặt mô-đun pymysql

PyMySQL trong Python là gì?

PyMySQL là giao diện để kết nối với máy chủ cơ sở dữ liệu MySQL từ Python . Nó triển khai API cơ sở dữ liệu Python v2. 0 và chứa thư viện máy khách MySQL thuần Python. Mục tiêu của PyMySQL là thay thế cho MySQLdb.

Nhập PyMySQL là gì?

PyMySQL là thư viện máy khách MySQL thuần Python, dựa trên PEP 249 . Hầu hết các API công khai đều tương thích với mysqlclient và MySQLdb. PyMySQL hoạt động với MySQL 5. 5+ và MariaDB 5. 5+. MySQL là hệ quản trị cơ sở dữ liệu mã nguồn mở hàng đầu. Nó là một hệ thống quản lý cơ sở dữ liệu đa người dùng, đa luồng.

Chủ Đề