Как установить модуль Python MySQLdb с помощью pip?
Как я могу установить MySQLdb модуль для Python с использованием pip?
16 ответов
это легко сделать, но трудно запомнить правильное написание:
Если вам нужно 1.2.X версии (только устаревший Python), используйте pip install MySQL-python
Примечание: некоторые зависимости, возможно, должны быть на месте при выполнении вышеуказанной команды. Некоторые советы о том, как установить их на различных платформах:
Ubuntu 14, Ubuntu 16, Debian 8.6 (jessie)
Fedora 24:
Mac OS
если это не удается, попробуй!—7—>
начиная с новой системы Ubuntu 14.04.2, эти две команды были необходимы:
просто выполнение «pip install» само по себе не сработало.
у меня были проблемы с установкой 64-битной версии MySQLdb на Windows через Pip (источники компиляции проблем) [32-битная версия установлена ok]. Удалось установить скомпилированный MySQLdb из .файл whl доступен изhttp://www.lfd.uci.edu /
например, если вы экономите в C:/ вы можно установить через
pip install c:/MySQL_python-1.2.5-cp27-none-win_amd64.whl
Последующие действия: если у вас установлена 64-битная версия Python, то вы хотите установить 64-битную версию AMD MySQLdb по ссылке выше [т. е. даже если у вас есть процессор Intel]. Если вы вместо этого попытаетесь установить 32-разрядную версию, я думаю, вы получите неподдерживаемую ошибку колеса в комментариях ниже.
хорошо это сработало для меня:
затем поместите код ниже в init.py (имя_проекта/init.py)
моя среда (python3.5, django1.10) и это работает для меня!
Я пробовал все варианты, но не смог заставить его работать на платформе Redhat. Я сделал следующее, чтобы заставить его работать: —
после установки пакета удалось импортировать модуль следующим образом в интерпретаторе: —
перейти к pycharm потом идут по умолчанию настройки — > Пип (двойной клик) — pymsqldb..— > установить-после установки использовать в программе, как это
вы можете пойти на это сайт скачать пакет.
у меня тоже такая же проблема.Выполните следующие действия, если вы находитесь на Windows. Идти к: 1.Мой Компьютер 2.системное свойство 3.Предварительные Настройки Системы 4. На вкладке «Дополнительно» нажмите кнопку с надписью «Переменные среды» 5. Затем в разделе системные переменные вы должны добавить / изменить следующие переменные: PYTHONPATH и Path. Вот вставка того, как выглядят мои переменные: путь python:
посмотреть этот ссылке для ссылка
Если вы используете Raspberry Pi [Raspbian OS]
сначала необходимо установить команду pip
Так что просто установите последовательно
Если вы не можете установить mysqlclient вы также можете установить pymysql:
pip install pymysql
это работает так же, как MySqldb. После этого используйте pymysql вместо MySQLdb
приведенный выше ответ велик, но могут возникнуть некоторые проблемы, когда мы используем pip для установки MySQL-python в Windows
например, ему нужны некоторые файлы, связанные с Визуальный Stdio .Одним из решений является установка VS2008 или 2010. Очевидно, это стоило слишком дорого.
другой способ-это ответ @bob90937 . Я здесь, чтобы кое-что добавить.
gohlke / pythonlibs, У может загрузите много двоичных файлов Windows многих научных пакетов расширения с открытым исходным кодом для официального распространения CPython языка программирования Python.
вернемся к теме,мы можем выбрать MySQL-python (py2) или Mysqlclient(py3) и использовать pip install установить. это дает нам большое удобство!
pip install mysql-connector-python как отмечается в документации:
Installing MySQLdb for Python 3 in Windows
My favorite Python connector for MySQL or MariaDB is MySQLdb, the problem with this connector is that it is complicated to install on Windows!
I am creating this article for those who want to install MySQLdb for Python 3 for Windows. Especially me, since each time I am doing a Python project that needs to connect to MariaDB or MySQL I always look on how to install MySQLdb.
If you are interested why I prefer MySQLdb compared to other MySQL connectors you may want to read the comparison of MySQL-connector and MySQLdb from Charles Nagy.
Problems with installing MySQLdb on Windows
You can actually install MySQLdb using pip. See pypi documentation here.
Unfortunately, the pypi documentation is already out of date with the latest release was on Jan 3, 2014.
You can still run the command above but it will look for Microsoft Visual C++ Build Tools, which if you install it in your Windows machine for the purpose of only using MySQLdb will become a program that occupies space but you will never ever use again.
Running pip install MySQL-python
So how do we install MySQLdb for Python on Windows? You can follow the steps below.
Installing MySQLdb on Windows
To install MySQLdb on Windows go to this link – https://www.lfd.uci.edu/
Screenshot of list of precompiled MySQLdb connectors for Python. You can even see when the .whl file was compiled if you hover the mouse over it.
Download the appropriate .whl for your Python version.
I am currently using Python 3.6.8, so I downloaded mysqlclient‑1.3.13‑cp36‑cp36m‑win_amd64.whl .
On windows command prompt, install the .whl file using pip. – pip install [.whl filename]
In my case the command is
Note: The file on the command will be different if you use a different Python version or if there is an update on the version of the mysqlclient (MySQLdb).
Once pip says that you have Successfully installed mysqlclient you are good to go on using MySQLdb as your MySQL connector for Python.
Testing MySQLdb Installation
Below is the code I use if my MySQLdb connector has been properly installed in Windows.
You can change the following parameters to check if it can connect to your MySQL database or MariaDB database.
If all is well, then when you run the code above it would print Succesfully Connected to database using MySQLdb!
If MySQLdb is not yet installed then it will raise a ModuleNotFoundError like the screenshot below.
I hope this helped you install MySQLdb for Python on your Windows computer easier.
If there are any questions, errors or suggestions comment them down below so that I could check them out too.
How to install Python MySQLdb module using pip?
How can I install the MySQLdb module for Python using pip?
20 Answers 20
It’s easy to do, but hard to remember the correct spelling:
If you need 1.2.x versions (legacy Python only), use pip install MySQL-python
Note: Some dependencies might have to be in place when running the above command. Some hints on how to install these on various platforms:
Ubuntu 14, Ubuntu 16, Debian 8.6 (jessie)
Fedora 24:
Mac OS
Starting from a fresh Ubuntu 14.04.2 system, these two commands were needed:
Just doing the «pip install» by itself did not work.
Then put the code below into __init__.py ( projectname/__init__.py )
My environment is (python3.5, django1.10) and this solution works for me!
I had problems installing the 64-bit version of MySQLdb on Windows via Pip (problem compiling sources) [32bit version installed ok]. Managed to install the compiled MySQLdb from the .whl file available from http://www.lfd.uci.edu/
For example if you save in C:/ the you can install via
pip install c:/MySQL_python-1.2.5-cp27-none-win_amd64.whl
Follow-up: if you have a 64bit version of Python installed, then you want to install the 64-bit AMD version of MySQLdb from the link above [i.e. even if you have a Intel processor]. If you instead try and install the 32-bit version, I think you get the unsupported wheel error in comments below.
gohlke/pythonlibs/#mysql-python to download whl file (I dl’d 64 bit to match my 64 bit Python install). Saved file into c:/ directory and ran pip install c:/MySQL_python-1.2.5-cp27-none-win_amd64.whl It installed in seconds and was good to go. Too easy! – curtisp Oct 11 ’16 at 18:43
well this worked for me:
this is for python 3.x
I tried all the option but was not able to get it working on Redhat platform. I did the following to make it work:-
Once the package was installed was able to import module as follows in the interpreter:-
Go to pycharm then go to default setting —> pip (double click) — pymsqldb..— > install —after installing use in a program like this
If you are unable to install mysqlclient you can also install pymysql:
pip install pymysql
This works same as MySqldb. After that use pymysql all over instead of MySQLdb
If you are use Raspberry Pi [Raspbian OS]
There are need to be install pip command at first
So that just install Sequently
You can go to this website to download the package.
I had the same problem too.Follow these steps if you are on Windows. Go to: 1.My Computer 2.System Properties 3.Advance System Settings 4. Under the «Advanced» tab click the button that says «Environment Variables» 5. Then under System Variables you have to add / change the following variables: PYTHONPATH and Path. Here is a paste of what my variables look like: python path:
See this link for reference
Many of the given answers here are quite confusing so I will try to put it simply. It helped me to install this
and then use the following command in the python file
This way you can use MySQLdb without any problems.
The above answer is great, but there may be some problems when we using pip to install MySQL-python in Windows
for example,It needs some files that are associated with Visual Stdio .One solution is installing VS2008 or 2010……Obviously,it cost too much.
Another way is the answer of @bob90937 . I am here to do something to add.
gohlke/pythonlibs, u can download many Windows binaries of many scientific open-source extension packages for the official CPython distribution of the Python programming language.
Back to topic,we can choose the MySQL-python(py2) or Mysqlclient(py3) and use pip install to install. it gives us Great convenience!