I'm trying to get the MySQL-python lib installed on centos 5.5. I ran
sudo yum install MySQL-python
but then when I tried:
import MySQLdb
I get this error:
Traceback (most recent call last):
File "<stdin>", line 1, in ?
File "MySQLdb/__init__.py", line 22, in ?
raise ImportError("this is MySQLdb version %s, but _mysql is version %r" %
ImportError: this is MySQLdb version (1, 2, 3, 'final', 0), \ # added linebreak
but _mysql is version (1, 2, 1, 'final', 1)
any clues on how to fix this?
Step 1 - Install package
# yum install MySQL-python
Loaded plugins: auto-update-debuginfo, langpacks, presto, refresh-packagekit
Setting up Install Process
Resolving Dependencies
--> Running transaction check
---> Package MySQL-python.i686 0:1.2.3-3.fc15 will be installed
--> Finished Dependency Resolution
Dependencies Resolved
================================================================================
Package Arch Version Repository Size
================================================================================
Installing:
MySQL-python i686 1.2.3-3.fc15 fedora 78 k
Transaction Summary
================================================================================
Install 1 Package(s)
Total download size: 78 k
Installed size: 220 k
Is this ok [y/N]: y
Downloading Packages:
Setting up and reading Presto delta metadata
Processing delta metadata
Package(s) data still to download: 78 k
MySQL-python-1.2.3-3.fc15.i686.rpm | 78 kB 00:00
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
Installing : MySQL-python-1.2.3-3.fc15.i686 1/1
Installed:
MySQL-python.i686 0:1.2.3-3.fc15
Complete!
Step 2 - Test working
import MySQLdb
db = MySQLdb.connect("localhost","myusername","mypassword","mydb" )
cursor = db.cursor()
cursor.execute("SELECT VERSION()")
data = cursor.fetchone()
print "Database version : %s " % data
db.close()
Ouput:
Database version : 5.5.20
I have Python 2.7.5, MySQL 5.6 and CentOS 7.1.1503.
For me it worked with the following command:
# pip install mysql-python
Note pre-requisites here:
Install Python pip:
# rpm -iUvh http://dl.fedoraproject.org/pub/epel/7/x86_64/e/epel-release-7-5.noarch.rpm
# yum -y update
Reboot the machine (if kernel is also updated)
# yum -y install python-pip
Install Python devel packages:
# yum install python-devel
Install MySQL devel packages:
# yum install mysql-devel
For centos7 I required:
sudo yum install mysql-devel gcc python-pip python-devel
sudo pip install mysql-python
So, gcc and mysql-devel (rather than mysql) were important
You probably did not install MySQL via yum? The version of MySQLDB in the repository is tied to the version of MySQL in the repository. The versions need to match.
Your choices are:
Install the RPM version of MySQL.
Compile MySQLDB to your version of
MySQL.
mysql-python NOT support Python3, you may need:
sudo pip3 install mysqlclient
Also, check this post for more alternatives.
Related
I am trying to install mysqlclient in a centos system. These are some of the issues I am facing:
mysqlclient needs to be compiled in the installation system
to compile it, according to the official sources, we need python-devel and mysql-devel
what if I am installing mysqlclient in a virtualenv with python36? Do I need python36-devel instead of python-devel? Why is this not mentioned in the documentation?
will python36-devel match the python36 of my virtualenv? What if I am using my self-compiled python37 instead of the centos python36, will that match python36-devel? It's not like I have infinite options regarding the centos packages I can install ...
And some problems unrelated to mysqlclient, but related to centos:
centos does not have python36 by default. It seems something called epel-release must be installed.
python36-devel installs 36 (!!) dependencies:
--
Installed:
python36-devel.x86_64 0:3.6.8-1.el7
Dependency Installed:
dwz.x86_64 0:0.11-3.el7 groff-base.x86_64 0:1.22.2-8.el7 perl.x86_64 4:5.16.3-294.el7_6 perl-Carp.noarch 0:1.26-244.el7 perl-Encode.x86_64 0:2.51-7.el7 perl-Exporter.noarch 0:5.68-3.el7
perl-File-Path.noarch 0:2.09-2.el7 perl-File-Temp.noarch 0:0.23.01-3.el7 perl-Filter.x86_64 0:1.49-3.el7 perl-Getopt-Long.noarch 0:2.40-3.el7 perl-HTTP-Tiny.noarch 0:0.033-3.el7 perl-PathTools.x86_64 0:3.40-5.el7
perl-Pod-Escapes.noarch 1:1.04-294.el7_6 perl-Pod-Perldoc.noarch 0:3.20-4.el7 perl-Pod-Simple.noarch 1:3.28-4.el7 perl-Pod-Usage.noarch 0:1.63-3.el7 perl-Scalar-List-Utils.x86_64 0:1.27-248.el7 perl-Socket.x86_64 0:2.010-4.el7
perl-Storable.x86_64 0:2.45-3.el7 perl-Text-ParseWords.noarch 0:3.29-4.el7 perl-Time-HiRes.x86_64 4:1.9725-3.el7 perl-Time-Local.noarch 0:1.2300-2.el7 perl-constant.noarch 0:1.27-2.el7 perl-libs.x86_64 4:5.16.3-294.el7_6
perl-macros.x86_64 4:5.16.3-294.el7_6 perl-parent.noarch 1:0.225-244.el7 perl-podlators.noarch 0:2.5.1-3.el7 perl-srpm-macros.noarch 0:1-8.el7 perl-threads.x86_64 0:1.87-4.el7 perl-threads-shared.x86_64 0:1.43-6.el7
python-rpm-macros.noarch 0:3-24.el7 python-srpm-macros.noarch 0:3-24.el7 python3-rpm-macros.noarch 0:3-24.el7 redhat-rpm-config.noarch 0:9.1.0-87.el7.centos zip.x86_64 0:3.0-11.el7
Utterly broken, if you ask me.
I am trying to retrieve data from Kudu. But I am not able to install kudu-python package in anaconda or my server. Can I get some help with it? The documentation on the internet is not really clear.
#Karthik, did you encounter any errors? I just installed kudu-python client on Anaconda on Centos 6.9. There was one gotcha with versioning, but otherwise it was straightforward. The only error I ran into was
kudu/client.cpp:589:30: fatal error: kudu/util/int128.h: No such file or directory
there is a solution for it here: https://community.cloudera.com/t5/Data-Ingestion-Integration/can-not-install-kudu-python/td-p/67496
Otherwise, the steps are:
1. Install kudu client libraries as described on Kudu website (https://kudu.apache.org/docs/installation.html#_install_on_rhel_or_centos_hosts):
wget http://archive.cloudera.com/kudu/redhat/6/x86_64/kudu/cloudera-kudu.repo
sudo mv cloudera-kudu.repo /etc/yum.repos.d/
sudo yum update
sudo yum install kudu kudu-client0 kudu-client-devel
install a bunch of dev dependencies if you don't have them already:
sudo yum install autoconf automake libtool make gcc gcc-c++
install Cython and kudu-python
pip install Cython kudu-python==1.2.0
Once you have this installed, you can find examples in https://github.com/apache/kudu/tree/master/examples/python
i had no ability to install kudu-client (windows os is not supported) so i used the cluster's Impala to get Kudu's tables:
from impala.dbapi import connect
conn = connect('<Impala Daemon>', port=21050)
cursor = conn.cursor()
cursor.execute('SELECT * FROM mytable LIMIT 100')
print(cursor.description) # prints the result set's schema
results = cursor.fetchall()
https://github.com/cloudera/impyla
Trying to follow a Django tutorial but I cannot install mysqlclient.
The tutorial claims that I can do so with the following command:
pip install mysqlclient
but this generates this error:
Collecting mysqlclient Using cached mysqlclient-1.3.12.tar.gz
Complete output from command python setup.py egg_info:
/bin/sh: 1: mysql_config: not found
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/tmp/pip-build-rrolctwh/mysqlclient/setup.py", line 17, in <module>
metadata, options = get_config()
File "/tmp/pip-build-rrolctwh/mysqlclient/setup_posix.py", line 44, in get_config
libs = mysql_config("libs_r")
File "/tmp/pip-build-rrolctwh/mysqlclient/setup_posix.py", line 26, in mysql_config
raise EnvironmentError("%s not found" % (mysql_config.path,))
OSError: mysql_config not found
---------------------------------------- Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-build-rrolctwh/mysqlclient/
I have the most up-to-date pip and virtualenv installed.
I would like to be able to install mysqlclient so that I may continue with the tutorial.
You should also install the mysql and python development headers and libraries:
https://github.com/PyMySQL/mysqlclient-python#prerequisites
I was facing the same problems, but following the instructions in the Official mysqlclient documentation fixed it for me
but just to clarify I was running python 3.5 from a virtual environment
and after installing the prerequisites, it all worked fine
The following solved it for me :
You may need to install the Python 3 and MySQL development headers and libraries like so:
$ sudo apt-get install python3-dev default-libmysqlclient-dev build-essential # Debian / Ubuntu
% sudo yum install python3-devel mysql-devel # Red Hat / CentOS
Then you can install mysqlclient via pip now:
$ pip install mysqlclient
Source : https://github.com/PyMySQL/mysqlclient#prerequisites
I had also similar issue on Centos 6, where there was a problem with mysql migration to maria, I had some conflicts, but finally I installed:
yum list installed |grep MariaDB
MariaDB-client.x86_64 10.2.7-1.el6 #bull
MariaDB-common.x86_64 10.2.7-1.el6 #bull
MariaDB-compat.x86_64 10.2.7-1.el6 #bull
MariaDB-devel.x86_64 10.2.7-1.el6 #bull
MariaDB-server.x86_64 10.2.7-1.el6 #bull
And the issue was resolved.
I'm working on this python-cassandra tutorial.
When I'm running this command
cluster = Cluster(
contact_points=['127.0.0.1'],
load_balancing_policy=
TokenAwarePolicy(DCAwareRoundRobinPolicy(local_dc='datacenter1')),
default_retry_policy = RetryPolicy()
)
session = cluster.connect('demo')
I'm getting the following error:
>>> session = cluster.connect('mykeyspace')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python2.7/dist-packages/cassandra/cluster.py",
line 700, in connect
self.load_balancing_policy.check_supported()
File "/usr/local/lib/python2.7/dist-packages/cassandra/policies.py",
line 345, in check_supported
(self.__class__.__name__, self._cluster_metadata.partitioner))
Exception: TokenAwarePolicy cannot be used with the cluster partitioner
(org.apache.cassandra.dht.Murmur3Partitioner) because the relevant C extension
for this driver was not compiled. See the installation instructions for details
on building and installing the C extensions.
However, when I run the below command that's supposed to rebuild the C extensions as it said in the document, I'm getting the confirmation that everything is right.
user1#mybox-VirtualBox:~$ sudo apt-get install gcc python-dev
[sudo] password for user1:
Reading package lists... Done
Building dependency tree
Reading state information... Done
gcc is already the newest version.
python-dev is already the newest version.
0 upgraded, 0 newly installed, 0 to remove and 254 not upgraded.
Am I missing anything?
After you've installed gcc and python-dev, you need to go back and reinstall the Cassandra Python driver. Here's what the whole sequence would look like, assuming you also install the support for compiling libev:
$ sudo apt-get install gcc python-dev
$ sudo apt-get install libev4 libev-dev
$ sudo pip uninstall cassandra-driver
$ sudo pip install cassandra-driver
On the 2nd install, the C extensions should compile correctly.
I'm trying to install sqlalchemy to interact with mysql database for my python 3.x with ubuntu 12.04, but then when I import the sqlalchemy it says no module named sqlalchemy. This is what i did with installation:
aoi#aoi:~$ sudo apt-get install python3-sqlalchemy
[sudo] password for aoi:
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following packages were automatically installed and are no longer required:
libgio-cil libmono-corlib4.0-cil libmono-system-security4.0-cil libmono-system-xml4.0- cil libmono-i18n-west4.0-cil cli-common guile-1.8-libs
libmono-system-configuration4.0-cil librhythmbox-core5 mono-runtime libgdu-gtk0 libavahi-ui-gtk3-0 mono-4.0-gac mono-gac
linux-headers-3.5.0-23-generic libglib2.0-cil linux-headers-3.5.0-23 libming1 thunderbird-globalmenu libmusicbrainz3-6 libmono-i18n4.0-cil
libmono-security4.0-cil libmono-system4.0-cil
Use 'apt-get autoremove' to remove them.
Suggested packages:
python-sqlalchemy-doc
The following NEW packages will be installed:
python3-sqlalchemy
0 upgraded, 1 newly installed, 0 to remove and 81 not upgraded.
Need to get 450 kB of archives.
After this operation, 2,808 kB of additional disk space will be used.
Get:1 http://ph.archive.ubuntu.com/ubuntu/ precise-updates/main python3-sqlalchemy all 0.7.4-1ubuntu0.1 [450 kB]
Fetched 450 kB in 40s (11.0 kB/s)
Selecting previously unselected package python3-sqlalchemy.
(Reading database ... 346102 files and directories currently installed.)
Unpacking python3-sqlalchemy (from .../python3-sqlalchemy_0.7.4-1ubuntu0.1_all.deb) ...
Setting up python3-sqlalchemy (0.7.4-1ubuntu0.1) ...
Did I do something wrong?
This gets ya sqlalchemy version 0.8.4 for python 2.x
ubuntu is a lot slow in keeping packages up to date
sudo apt-get install python3-sqlalchemy
So for Python 3 / Ubuntu peeps here is how to install the latest version of sqlalchemy
sudo apt-get install python3-pip
# Now you have pip3
sudo apt-get install python3-all-dev
# Required for sqlalchemy's c extensions to be installed
sudo pip3 install SQLAlchemy
# note using pip, not pip3, will install for Python 2.7
:~$ python3
>>> import sqlalchemy
>>> sqlalchemy.__version__
>>> '0.9.8'
>>> print("Who's the man?")
>>> You are baby!
>>> quit()
By using apt-get you have installed sqlalchemy in the default directory for Ubuntu's default Python 3, which is 3.2. If you search in the directory /usr/lib/python3/dist-packages you'll find the sqlalchemy module (or just type locate sqlalchemy). However, this isn't where a custom Python will look for its modules. You'll need to download the source and compile it with the correct Python, something like /opt/python3.3/bin/python3.3 setup.py install in the source directory for sqlalchemy. See the instructions here: http://docs.python.org/3.3/install
It seems that the python3-sqlalchemy is outdated. You can try to use pip3 to get the latest version instead.
sudo pip3 install sqlalchemy
should do the trick.