virtualenv(python3.4), pip install mysqlclient error - python

I created virtualenv for django 1.9 project. I am trying to pip install mysqlclient or mysql-python but both of them gives me errors.
pip install mysqlclient
pip install mysql-python
both give me the same error message:
Command "python setup.py egg_info" failed with error code 1 in
/private/var/folders/r4/bkv_4t9s4r140pjkgv6lsq8w0000gn/T/pip-build-cdxcssp9/mysqlclient
any suggestions!?

Try to run this before:
Ubuntu:
sudo apt-get install python-dev python3-dev
sudo apt-get install libmysqlclient-dev
pip install pymysql
pip install mysqlclient
In OSX:
sudo xcodebuild -license accept
brew install mysql-connector-c

This is probably due to your mysql_config being broken.
As of 2019, here is how to run smoothly pip install mysqlclient on MacOS:
brew info openssl and follow the commands at the bottom
echo 'export PATH="/usr/local/opt/openssl/bin:$PATH"' >> ~/.zshrc
export LDFLAGS="-L/usr/local/opt/openssl/lib"
export CPPFLAGS="-I/usr/local/opt/openssl/include"
Other approaches:
brew install/upgrade/reinstall mysql : did not fix the issue for me, but has the nice side effect to make sure your installation is clean.
brew install mysql-connector-c : to make that work you have to unlink mysql, which ruins your setup and it did not fix the issue for me.

If you're using Anaconda (which I highly suggest you) then run these two commands
conda install -c anaconda mysql-connector-python
and
conda install -c bioconda mysqlclient

Download the MySQL APT repository config tool (you can see more details here: http://dev.mysql.com/downloads/repo/apt/)
wget http://dev.mysql.com/get/mysql-apt-config_0.7.3-1_all.deb
Install the MySQL APT repository config tool
dpkg -i mysql-apt-config_0.7.3-1_all.deb
You will be asked to select product and version that you want to install. In the first step, select Server and next select either mysql-5.6 or mysql-5.7. Then click Apply.
Update APT
apt-get update
Install the server
sudo apt-get install mysql-community-server
sudo apt-get install python-dev python3-dev
sudo apt-get install libmysqlclient-dev
pip install pymysql
pip install mysqlclient

If you are using Python 2.x, and already have installed:
MySQL Server
Python Connector
Then the problem is when you run:
Windows:
(your environment) SomePath> pip install mysqlclient
Mac OS:
$ pip install mysqlclient
Actually it is asking to install package for Python 3.x not 2.x. So it is throwing an error.
Solution is to run:
Windows:
(your environment) SomePath> pip install mysqlclient==1.3.9
Mac OS:
$ pip install mysqlclient==1.3.9
P.S The mysqlclient==1.3.9 version is the latest version for Python 2.x

For Ubuntu 18.04
sudo apt-get install python-dev python3-dev
sudo apt-get install libmysqlclient-dev
pip install pymysql
pip install mysqlclient
and setup
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'DB_NAME',
'USER': 'DB_USER',
'PASSWORD': 'DB_PASSWORD',
'HOST': 'localhost', # Or an IP Address that your DB is hosted on
'PORT': '3306',
}
}

This worked for on Ubuntu 18.04
sudo apt-get install python3.6-dev
sudo apt-get install mysql-client
sudo apt-get install libsqlclient-dev
sudo apt-get install libssl-dev

Related

"sql.h: No such file or directory" error trying to install pyodbc on raspberry pi [duplicate]

I am running Linux (2.6.18-164.15.1.el5.centos.plus) and trying to install pyodbc. I am doing pip install pyodbc and get a very long list of errors, which end in
error: command 'gcc' failed with exit status 1
I looked in /root/.pip/pip.log and saw the following:
InstallationError: Command /usr/local/bin/python -c "import setuptools; file='/home/build/pyodbc/setup.py'; execfile('/home/build/pyodbc/setup.py')" install --single-version-externally-managed --record /tmp/pip-7MS9Vu-record/install-record.txt failed with error code 1
Has anybody had a similar issue installing pyodbc?
On Ubuntu, you'll need to install unixodbc-dev:
sudo apt-get install unixodbc-dev
Install pip by using this command:
sudo apt-get install python-pip
once that is installed, you should be able to install pyodbc successfully:
pip install pyodbc
I resolved my issue by following correct directions on pyodbc - Building wiki which states:
On Linux, pyodbc is typically built using the unixODBC headers, so you will need unixODBC and its headers installed. On a RedHat/CentOS/Fedora box, this means you would need to install unixODBC-devel:
yum install unixODBC-devel
Adding one more answer on this question.
For Linux Debian Stretch release you would need to install the following dependencies:
apt-get update
apt-get install unixodbc-dev
pip install pyodbc
On Debian Slim some users mentioned they needed to add g++
apt-get update
apt-get install g++ unixodbc-dev
pip install pyodbc
Struggled with the same issue
After running:
sudo apt-get install unixodbc-dev
I was able to pip install pyodbc
Follow below steps to install pyodbc in any redhat version
yum install unixODBC unixODBC-devel
yum install gcc-c++
yum install python-devel
pip install pyodbc
I have referenced this question several times, and gone on to actually find the answer I was looking for here:
pyodbc wiki
To avoid gcc error on Ubuntu Linux, I did:
sudo aptitude install g++
I also installed the following 2 packages from Synaptic:
python-dev
tdsodbc
Execute the following commands (tested on centos 6.5):
yum install install unixodbc-dev
yum install gcc-c++
yum install python-devel
pip install --allow-external pyodbc --allow-unverified pyodbc pyodbc
According to official Microsoft docs for Ubuntu 18.04 you should run next commands:
sudo su
curl https://packages.microsoft.com/keys/microsoft.asc | apt-key add -
curl https://packages.microsoft.com/config/ubuntu/18.04/prod.list > /etc/apt/sources.list.d/mssql-release.list
apt-get update
ACCEPT_EULA=Y apt-get install msodbcsql17
exit
If you are using python3.7, it is very important to run:
sudo apt-get install python3.7-dev
A easy way to install pyodbc is by using 'conda'. As conda automatically installs required dependencies including unixodbc.
conda --ugrade all (optional)
then
conda install pyodbc
it will install following packages:
libgfortran-ng: 7.2.0-hdf63c60_3 defaults
mkl: 2018.0.3-1 defaults
mkl_fft: 1.0.2-py36_0 conda-forge
mkl_random: 1.0.1-py36_0 conda-forge
numpy-base: 1.14.5-py36hdbf6ddf_0 defaults
pyodbc: 4.0.17-py36_0 conda-forge
unixodbc: 2.3.4-1 conda-forge
I had the same problem on CentOS 5.5
In addition to installing unixODBC-devel I also had to install gcc-c++
yum install gcc-c++
In my case (Amazon Linux AMI) none of the above worked. The following worked (idea from here):
Find the path to the file cc1plus. For me it was in /usr/libexec/gcc/x86_64-amazon-linux/4.8.5/cc1plus. For you it may vary a bit. Try ls -l /usr/libexec/gcc to find the proper directory name and go ahead.
Find directories in your path: echo $PATH (for me it was /sbin:/bin:/usr/sbin:/usr/bin:/opt/aws/bin)
Put a link to cc1plus in one of the directories in your PATH: sudo ln -s /PATH/TO/cc1plus /DIRinPATH/
For example in my case:
sudo ln -s /usr/libexec/gcc/x86_64-amazon-linux/4.8.5/cc1plus /usr/bin/
I needed all that, but I also needed python devel installed:
sudo yum install python-devel
How about installing pyobdc from zip file? From How to connect to Microsoft Sql Server from Ubuntu using pyODBC:
Download source vs apt-get
The apt-get utility in Ubuntu does have a version of pyODBC. (version 2.1.7).
However, it is badly out-of-date (2.1.7 vs 3.0.6) and may not work well with the newer versions of unixODBC and freetds.
This is especially important if you are trying to connect to later versions of Microsoft Sql Server (2008 onwards).
It is recommended that you use the latest versions of unixODBC, freetds and pyODBC when working with the latest Microsoft Sql Server instead of relying on packages in apt-get.
I know this is an old question, but the maintainer has a pyodbc GitHub Repo.
I also found a very good example for installing FreeTDS and setting up the config files.
Following the instructions on the GitHub docs seems to me to always be the best option. As of February, 2018, for CentOs7 (they have all flavors at the link) they say:
# Add the RHEL 6 library for Centos-7 of MSSQL driver. Centos7 uses RHEL-6 Libraries.
sudo su
curl https://packages.microsoft.com/config/rhel/6/prod.repo > /etc/yum.repos.d/mssql-release.repo
exit
# Uninstall if already installed Unix ODBC driver
sudo yum remove unixODBC-utf16 unixODBC-utf16-devel #to avoid conflicts
# Install the msodbcsql unixODBC-utf16 unixODBC-utf16-devel driver
sudo ACCEPT_EULA=Y yum install msodbcsql
#optional: for bcp and sqlcmd
sudo ACCEPT_EULA=Y yum install mssql-tools
echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bash_profile
echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bashrc
source ~/.bashrc
# optional: for unixODBC development headers
sudo yum install unixODBC-devel
# the Microsoft driver expects unixODBC to be here /usr/lib64/libodbc.so.1, so add soft links to the '.so.2' files
cd /usr/lib64
sudo ln -s libodbccr.so.2 libodbccr.so.1
sudo ln -s libodbcinst.so.2 libodbcinst.so.1
sudo ln -s libodbc.so.2 libodbc.so.1
# Set the path for unixODBC
export ODBCINI=/usr/local/etc/odbc.ini
export ODBCSYSINI=/usr/local/etc
source ~/.bashrc
# Prepare a temp file for defining the DSN to your database server
vi /home/user/odbcadd.txt
[MyMSSQLServer]
Driver = ODBC Driver 13 for SQL Server
Description = My MS SQL Server
Trace = No
Server = 10.100.1.10
# register the SQL Server database DSN information in /etc/odbc.ini
sudo odbcinst -i -s -f /home/user/odbcadd.txt -l
# check the DSN installation with:
odbcinst -j
cat /etc/odbc.ini
# should contain a section called [MyMSSQLServer]
# install the python driver for database connection
pip install pyodbc
For archlinux/manjaro:
sudo pacman -S unixodbc
then:
sudo pip install pyodbc
or:
pip install pyodbc
You can upgrade your pip wheel setuptools before installing pyodbc (it won't affect the pyodbc installation) also with:
sudo python -m pip install --upgrade pip wheel setuptools
or
python -m pip install --upgrade pip wheel setuptools
I used this:
yum install unixODBC.x86_64
Depending on the version of centos could change the package, you can search like this:
yum search unixodbc
I faced with same issue. For python3.6.8 and ubuntu 16.04 none of above did not help me.
sudo apt-get install python3.6-dev
This solved my problem.
These 2 commands from here worked for me in RHEL 8
sudo dnf install redhat-rpm-config gcc-c++ python3-devel unixODBC-devel
pip3 install --user pyodbc
I have unixodbc, unixodbc-dev and python3-dev all installed, but I still get
In file included from src/buffer.cpp:12:
src/pyodbc.h:56:10: fatal error: sql.h: No such file or directory
56 | #include <sql.h>
| ^~~~~~~
compilation terminated.
error: command '/usr/bin/x86_64-unknown-linux-gnu-gcc' failed with exit code 1
gcc and g++ are installed as well.
I'm running pop-os 22.10. I've also checked that odbc.ini and odbcinst.ini exist as well and have FreeTDS installed.

how to install pycurl 7.43 at ubuntu 18.04 64bit

Help me, all
I have some error while installation of pycurl on ubuntu 18,04
I tried follow as:
apt-cache depends python-pycurl
sudo apt install libcurl4-gnutls-dev
apt-cache search gnutl | grep dev
sudo apt-get install libgnutls-dev
sudo apt install python-pycurl
pip install pycurl
but, failed to install.
Thanks!
I fixed it.
sudo apt-get install libssl-dev libcurl4-openssl-dev python3.8-dev
and by referring to these links Error in installation pycurl 7.19.0, https://github.com/pycurl/pycurl/issues/596.
In addtion, my python version is 3.8, so I installed python3.8-dev.

Not able to install setuptools on linux mint

I used this command in terminal
sudo apt-get install python-setuptools
it throws up an error instead of installing -
Package 'python-setuptools' has no installation candidate
THis is a python package so you could use pip to install it
pip3 install setuptools
Try this:
sudo apt-get install python-pip
When pip is installed type in:
pip install setuptools
Hope this helps!

Cannot import installed python package

I'm trying to install python-numpy package on my ubuntu 14.04 machine. I ran sudo apt-get install python-numpy command to install it and it says the package has been installed but when i try to access it, i'm unable to do so.
When you type:
sudo pip install package-name
It will default install python2 version of package-name some packages might be supported in both python3 and python3 some might work might not
I would suggest
sudo apt-get install python3-pip
sudo pip3 install MODULENAME
or can even try this
sudo apt-get install curl
curl https://bootstrap.pypa.io/get-pip.py | sudo python3
sudo pip3 install MODULENAME
Many python packages require also the dev package, so install it too:
sudo apt-get install python3-dev
Also check for the sys.path [ make sure module is in the python path ]

How to install SQLAlchemy on Ubuntu?

I want to install Python and SQLAlchemy on Ubuntu. This is my command:
sudo easy_install sqlalchemy
But it has failed, what should I do?
Aha,sir,I can help you.
First step,you should intall the MySql,like these:
sudo apt-get install mysql-server
sudo apt-get install mysql-client
sudo apt-get install libmysqlclient15-dev
Second step,install the python-mysqldb:
sudo apt-get install python-mysqldb
Third step,install the easy_install:
sudo wget http://peak.telecommunity.com/dist/ez_setup.py
sudo python ez_setup.py
Forth step,install the MySQL-Python:
sudo easy_install MySQL-Python
Finally,sqlalchemy:
sudo easy_install SQLAlchemy
I installed it using pip. After installing mysql-server, mysql-client and libmysqlclient15-dev and I ran following commands to install it.
pip install MySql-Python
pip install SQLAlchemy
sudo pip install flask-sqlalchemy
This installs the SQLAlchemy package for Flask.

Categories