Obtener "Error al cargar el módulo MySQLdb: Ningún módulo llamado MySQLdb" - ha probado soluciones publicadas anteriormente
Este es un problema muy discutido para los usuarios de OSX 10.6, pero no he sido capaz de encontrar una solución que funcione. Aquí está mi configuración:
Python 2.6.1 64bit Django 1.2.1 MySQL 5.1.47 osx10. 6 64bit
Creo un virtualenvwrapper con packages no-site-packages, luego instalo Django. Cuando active virtualenv y ejecute python manage.py syncdb, me sale este error:
Traceback (most recent call last):
File "manage.py", line 11, in <module>
execute_manager(settings)
File "/Users/joerobinson/.virtualenvs/dj_tut/lib/python2.6/site-packages/django/core/management/__init__.py", line 438, in execute_manager
utility.execute()
File "/Users/joerobinson/.virtualenvs/dj_tut/lib/python2.6/site-packages/django/core/management/__init__.py", line 379, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/Users/joerobinson/.virtualenvs/dj_tut/lib/python2.6/site-packages/django/core/management/__init__.py", line 257, in fetch_command
klass = load_command_class(app_name, subcommand)
File "/Users/joerobinson/.virtualenvs/dj_tut/lib/python2.6/site-packages/django/core/management/__init__.py", line 67, in load_command_class
module = import_module('%s.management.commands.%s' % (app_name, name))
File "/Users/joerobinson/.virtualenvs/dj_tut/lib/python2.6/site-packages/django/utils/importlib.py", line 35, in import_module
__import__(name)
File "/Users/joerobinson/.virtualenvs/dj_tut/lib/python2.6/site-packages/django/core/management/commands/syncdb.py", line 7, in <module>
from django.core.management.sql import custom_sql_for_model, emit_post_sync_signal
File "/Users/joerobinson/.virtualenvs/dj_tut/lib/python2.6/site-packages/django/core/management/sql.py", line 5, in <module>
from django.contrib.contenttypes import generic
File "/Users/joerobinson/.virtualenvs/dj_tut/lib/python2.6/site-packages/django/contrib/contenttypes/generic.py", line 6, in <module>
from django.db import connection
File "/Users/joerobinson/.virtualenvs/dj_tut/lib/python2.6/site-packages/django/db/__init__.py", line 75, in <module>
connection = connections[DEFAULT_DB_ALIAS]
File "/Users/joerobinson/.virtualenvs/dj_tut/lib/python2.6/site-packages/django/db/utils.py", line 91, in __getitem__
backend = load_backend(db['ENGINE'])
File "/Users/joerobinson/.virtualenvs/dj_tut/lib/python2.6/site-packages/django/db/utils.py", line 32, in load_backend
return import_module('.base', backend_name)
File "/Users/joerobinson/.virtualenvs/dj_tut/lib/python2.6/site-packages/django/utils/importlib.py", line 35, in import_module
__import__(name)
File "/Users/joerobinson/.virtualenvs/dj_tut/lib/python2.6/site-packages/django/db/backends/mysql/base.py", line 14, in <module>
raise ImproperlyConfigured("Error loading MySQLdb module: %s" % e)
django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module: No module named MySQLdb
También he instalado el adaptador MySQL para Python, pero en vano (tal vez lo instalé incorrectamente?).
¿Alguien ha tratado esto antes?
23 answers
Tuve el mismo error y pip install MySQL-python
lo resolví para mí.
Instalaciones alternativas:
- Si no tienes pip,
easy_install MySQL-python
debería funcionar. - Si su python es administrado por un sistema de empaquetado, es posible que tenga que usar
ese sistema (por ejemplo,
sudo apt-get install ...
)
A continuación, Soli señala que si recibe el siguiente error:
EnvironmentError: mysql_config not found
... entonces tiene un problema adicional de dependencia del sistema. Resolver esto variará de un sistema a otro, pero para los sistemas derivados de Debian sistemas:
sudo apt-get install python-mysqldb
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2012-11-28 21:16:34
Ejecutando Ubuntu, tuve que hacer:
sudo apt-get install python-mysqldb
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2012-07-04 03:42:23
Añadiendo a otras respuestas, lo siguiente me ayudó a terminar la instalación mysql-python:
Virtualenv, mysql-python, pip: ¿alguien sabe cómo?
En Ubuntu...
apt-get install libmysqlclient-dev
apt-get install python-dev
pip install mysql-python
No olvide agregar 'sudo' al principio de los comandos si no tiene los permisos adecuados.
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2017-05-23 11:55:10
Pruebe esto con los siguientes comandos. Ellos trabajan para mí:
brew install mysql-connector-c
pip install MySQL-python
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2015-05-11 08:26:24
mysql_config
debe estar en el camino. En Mac, do
export PATH=$PATH:/usr/local/mysql/bin/
pip install MySQL-python
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2012-06-14 20:04:34
pip install mysql-python
Planteó un error:
EnvironmentError: mysql_config not found
sudo apt-get install python-mysqldb
Solucionado el problema.
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2011-11-30 17:05:25
Cómo lo hice funcionar:
virtualenv -p python3.5 env/test
Después de obtener mi env:
pip install pymysql
pip install django
Entonces, ejecuté el startproject y dentro del manage.py, He añadido esto:
+ try:
+ import pymysql
+ pymysql.install_as_MySQLdb()
+ except:
+ pass
También se ha actualizado esta configuración interna:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'foobar_db',
'USER': 'foobaruser',
'PASSWORD': 'foobarpwd',
}
}
También tengo configparser==3.5.0
instalado en mi virtualenv, no estoy seguro de si eso era necesario o no...
Espero que ayude,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2016-09-19 17:37:22
Lo siguiente funcionó perfectamente para mí, ejecutando Ubuntu 13.10 de 64 bits:
sudo apt-get install libmysqlclient-dev
sudo apt-get install python-dev
Ahora, vaya a su virtualenv (como la carpeta env) y ejecute lo siguiente:
sudo ./bin/pip install mysql-python
Realmente encontré la solución en una pregunta separada y la cito a continuación:
Si ha creado el virtualenv con el interruptor switch no-site-packages (el predeterminado), luego adiciones instaladas en todo el sistema como MySQLdb no están incluidos en el entorno virtual paquete.
Necesita instalar MySQLdb con el comando pip instalado con el virtualenv. O bien activar el virtualenv con el bin / activar script, o use bin / pip desde dentro del virtualenv para instalar el Biblioteca MySQLdb localmente también.
Alternativamente, cree un nuevo virtualenv con system site-packages incluido usando el interruptor system system-site-package.
Creo que esto también debería funcionar con OSX. El único problema sería conseguir un comando equivalente para instalar libmysqlclient-dev
y python-dev
ya que son necesarios para compilar
mysql-python
, supongo.
Espero que esto ayude.
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2017-05-23 11:55:10
Prueba esto: Esto resolvió el problema para mí .
Pip instalar MySQL-python
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2014-03-06 05:42:23
Este problema fue el resultado de una instalación incompleta / incorrecta del adaptador MySQL para Python. Específicamente, tuve que editar la ruta al archivo mysql_config para apuntar a/usr/local / mysql / bin / mysql_config-discutido con mayor detalle en este artículo: http://dakrauth.com/blog/entry/python-and-django-setup-mac-os-x-leopard /
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2010-09-23 22:35:03
Esto funcionó para la versión 6.4 de Red Hat Enterprise Linux Server
sudo yum install mysql-devel
sudo yum install python-devel
pip install mysql-python
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2014-04-26 17:42:32
sudo apt-get install python-mysqldb
funciona perfectamente en ubuntu
pip install mysql-python
genera un Error de Entorno
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2017-03-21 13:17:39
Se puede instalar como pip install mysqlclient
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2017-03-21 13:16:53
Hice la actualización a OSX Mavericks y Pycharm 3 y comencé a obtener este error, usé pip y easy install y obtuve el error:
El comando'/usr/bin/clang' falló con el estado de salida 1.
Así que necesito actualizar a Xcode 5 e intenté de nuevo instalarlo usando pip.
pip install mysql-python
Que solucionan todos los problemas.
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2017-03-21 13:18:53
El error planteado aquí está en la importación del módulo python. Esto se puede resolver añadiendo la carpeta python site-packages a la variable de entorno PYTH PYTHONPATH en OS X. Así que podemos añadir el siguiente comando a la .archivo bash_profile:
export PYTHONPATH="$PYTHONPATH:/usr/local/lib/pythonx.x/site-packages/"
* reemplaza x. x con la versión de python que estás usando
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2014-11-13 05:01:05
Si estás usando python3, entonces prueba esto (Mi sistema operativo es Ubuntu 16.04):
sudo apt-get install python3-mysqldb
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2017-03-21 13:16:31
pip
no funcionó para mí en el sistema Windows 8 64 bits.
easy_install mysql-python
funciona para mí.
Puede usar easy_install
para evitar construir binarios en Windows si pip no funciona.
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2017-03-21 13:18:10
Tuve el mismo problema en OSX 10.6.6. Pero solo un simple easy_install mysql-python
en la terminal no lo resolvió ya que siguió otro contratiempo:
error: command 'gcc-4.2' failed with exit status 1
.
Aparentemente, este problema surge después de actualizar desde XCode3 (que se envía de forma nativa con OSX 10.6) a XCode4. Esta versión más reciente elimina el soporte para construir ppc arch. Si es el mismo caso, intente hacer lo siguiente antes easy_install mysql-python
sudo bash
export ARCHFLAGS='-arch i386 -arch x86_64'
rm -r build
python setup.py build
python setup.py install
Muchas gracias a Ned Deily por esta solución. Marque aquí
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2017-05-23 12:26:35
Para mí el problema se resolvió simplemente reinstalando mysql-python
pip uninstall mysql-python
pip install mysql-python
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2017-01-04 16:07:25
Instalar Herramientas de Línea de comandos Funciona para mí:
xcode-select --install
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2017-03-11 19:42:37
Superé el mismo problema instalando MySQL-python
biblioteca usando pip . Puede ver el mensaje que se muestra en mi consola cuando cambié la configuración de la base de datos por primera vez en settings.py y ejecutó el comando makemigrations (La solución está siguiendo el siguiente mensaje, solo vea eso).
(vir_env) admins-MacBook-Pro-3:src admin$ python manage.py makemigrations
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/Users/admin/Desktop/SetUp1/vir_env/lib/python2.7/site-packages/django/core/management/__init__.py", line 338, in execute_from_command_line
utility.execute()
File "/Users/admin/Desktop/SetUp1/vir_env/lib/python2.7/site-packages/django/core/management/__init__.py", line 312, in execute
django.setup()
File "/Users/admin/Desktop/SetUp1/vir_env/lib/python2.7/site-packages/django/__init__.py", line 18, in setup
apps.populate(settings.INSTALLED_APPS)
File "/Users/admin/Desktop/SetUp1/vir_env/lib/python2.7/site-packages/django/apps/registry.py", line 108, in populate
app_config.import_models(all_models)
File "/Users/admin/Desktop/SetUp1/vir_env/lib/python2.7/site-packages/django/apps/config.py", line 198, in import_models
self.models_module = import_module(models_module_name)
File "/usr/local/Cellar/python/2.7.12_1/Frameworks/Python.framework/Versions/2.7/lib/python2.7/importlib/__init__.py", line 37, in import_module
__import__(name)
File "/Users/admin/Desktop/SetUp1/vir_env/lib/python2.7/site-packages/django/contrib/auth/models.py", line 41, in <module>
class Permission(models.Model):
File "/Users/admin/Desktop/SetUp1/vir_env/lib/python2.7/site-packages/django/db/models/base.py", line 139, in __new__
new_class.add_to_class('_meta', Options(meta, **kwargs))
File "/Users/admin/Desktop/SetUp1/vir_env/lib/python2.7/site-packages/django/db/models/base.py", line 324, in add_to_class
value.contribute_to_class(cls, name)
File "/Users/admin/Desktop/SetUp1/vir_env/lib/python2.7/site-packages/django/db/models/options.py", line 250, in contribute_to_class
self.db_table = truncate_name(self.db_table, connection.ops.max_name_length())
File "/Users/admin/Desktop/SetUp1/vir_env/lib/python2.7/site-packages/django/db/__init__.py", line 36, in __getattr__
return getattr(connections[DEFAULT_DB_ALIAS], item)
File "/Users/admin/Desktop/SetUp1/vir_env/lib/python2.7/site-packages/django/db/utils.py", line 240, in __getitem__
backend = load_backend(db['ENGINE'])
File "/Users/admin/Desktop/SetUp1/vir_env/lib/python2.7/site-packages/django/db/utils.py", line 111, in load_backend
return import_module('%s.base' % backend_name)
File "/usr/local/Cellar/python/2.7.12_1/Frameworks/Python.framework/Versions/2.7/lib/python2.7/importlib/__init__.py", line 37, in import_module
__import__(name)
File "/Users/admin/Desktop/SetUp1/vir_env/lib/python2.7/site-packages/django/db/backends/mysql/base.py", line 27, in <module>
raise ImproperlyConfigured("Error loading MySQLdb module: %s" % e)
django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module: No module named MySQLdb
Finalmente superé este problema de la siguiente manera:
(vir_env) admins-MacBook-Pro-3:src admin$ pip install MySQLdb
Collecting MySQLdb
Could not find a version that satisfies the requirement MySQLdb (from versions: )
No matching distribution found for MySQLdb
(vir_env) admins-MacBook-Pro-3:src admin$ pip install MySQL-python
Collecting MySQL-python
Downloading MySQL-python-1.2.5.zip (108kB)
100% |████████████████████████████████| 112kB 364kB/s
Building wheels for collected packages: MySQL-python
Running setup.py bdist_wheel for MySQL-python ... done
Stored in directory: /Users/admin/Library/Caches/pip/wheels/38/a3/89/ec87e092cfb38450fc91a62562055231deb0049a029054dc62
Successfully built MySQL-python
Installing collected packages: MySQL-python
Successfully installed MySQL-python-1.2.5
(vir_env) admins-MacBook-Pro-3:src admin$ python manage.py makemigrations
No changes detected
(vir_env) admins-MacBook-Pro-3:src admin$ python manage.py migrate
Operations to perform:
Synchronize unmigrated apps: staticfiles, rest_framework, messages, crispy_forms
Apply all migrations: admin, contenttypes, sessions, auth, PyApp
Synchronizing apps without migrations:
Creating tables...
Running deferred SQL...
Installing custom SQL...
Running migrations:
Rendering model states... DONE
Applying PyApp.0001_initial... OK
Applying PyApp.0002_auto_20170310_0936... OK
Applying PyApp.0003_auto_20170310_0953... OK
Applying PyApp.0004_auto_20170310_0954... OK
Applying PyApp.0005_auto_20170311_0619... OK
Applying PyApp.0006_auto_20170311_0622... OK
Applying PyApp.0007_loraevksensor... OK
Applying PyApp.0008_auto_20170315_0752... OK
Applying PyApp.0009_auto_20170315_0753... OK
Applying PyApp.0010_auto_20170315_0806... OK
Applying PyApp.0011_auto_20170315_0814... OK
Applying PyApp.0012_auto_20170315_0820... OK
Applying PyApp.0013_auto_20170315_0822... OK
Applying PyApp.0014_auto_20170315_0907... OK
Applying PyApp.0015_auto_20170315_1041... OK
Applying PyApp.0016_auto_20170315_1355... OK
Applying PyApp.0017_auto_20170315_1401... OK
Applying PyApp.0018_auto_20170331_1348... OK
Applying PyApp.0019_auto_20170331_1349... OK
Applying PyApp.0020_auto_20170331_1350... OK
Applying PyApp.0021_auto_20170331_1458... OK
Applying PyApp.0022_delete_postoffice... OK
Applying PyApp.0023_posoffice... OK
Applying PyApp.0024_auto_20170331_1504... OK
Applying PyApp.0025_auto_20170331_1511... OK
Applying contenttypes.0001_initial... OK
Applying auth.0001_initial... OK
Applying admin.0001_initial... OK
Applying contenttypes.0002_remove_content_type_name... OK
Applying auth.0002_alter_permission_name_max_length... OK
Applying auth.0003_alter_user_email_max_length... OK
Applying auth.0004_alter_user_username_opts... OK
Applying auth.0005_alter_user_last_login_null... OK
Applying auth.0006_require_contenttypes_0002... OK
Applying sessions.0001_initial... OK
(vir_env) admins-MacBook-Pro-3:src admin$
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2017-04-01 06:03:47
Ejecute este comando
sudo pip install mysql-python;
Ahora puedes ejecutar tu comando.
python manage.py startapp filename;
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2017-11-28 06:01:11
Me encontré con situaciones similares como la suya que estoy usando python3.7 y django 2.1 en virtualenv en mac osx. Intente ejecutar el comando:
pip install mysql-python
pip install pymysql
Y edite __init__.py
el archivo en su carpeta de proyecto y agregue lo siguiente:
import pymysql
pymysql.install_as_MySQLdb()
Luego ejecute: python3 manage.py runserver
o python manage.py runserver
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2018-08-05 10:31:16