0

I installed pandasql with pip at the linux command prompt, and started ipython notebook:

felix@xanadu ~ $ sudo pip install pandasql
[sudo] password for felix: 
Downloading/unpacking pandasql
  Downloading pandasql-0.6.2.tar.gz
  Running setup.py (path:/tmp/pip_build_root/pandasql/setup.py) egg_info for package pandasql

Installing collected packages: pandasql
  Running setup.py install for pandasql

Successfully installed pandasql
Cleaning up...
felix@xanadu ~ $ ipython notebook

Then tried to import pandas and it in the ipython notebook:

import pandas    
import pandasql

..and it's not happy, have looked around but there doesn't seem to be an answer anywhere. Here is the error message it gave:

--------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
<ipython-input-1-c9fa37159ca4> in <module>()
      1 import pandas
----> 2 import pandasql

/usr/local/lib/python2.7/dist-packages/pandasql/__init__.py in <module>()
----> 1 from .sqldf import sqldf
      2 import os
      3 import pandas as pd
      4 
      5 

/usr/local/lib/python2.7/dist-packages/pandasql/sqldf.py in <module>()
      2 import pandas as pd
      3 import numpy as np
----> 4 from pandas.io.sql import to_sql, read_sql
      5 import re
      6 import os

ImportError: cannot import name to_sql

Does anyone have any ideas? Cheers

cardamom
  • 6,873
  • 11
  • 48
  • 102

1 Answers1

1

You should definitely upgrade to pandas 0.16.0:

sudo pip install -U pandas

I just looked through the source code of pandas/io/sql.py in 0.13.1 and 0.16.0, and the to_sql() and read_sql() methods are not present in the older version, while they exist in the latest version.


To summarize our conversation in the comments, in order to successfully build pandas, you will need to install the gcc, g++, and python-dev packages from your system's package manager (apt-get, yum, zypper, whatever). If you are building for Python 3, the python3-dev package is needed.

If you are using Windows and the standard python.org version of Python, the easiest way to keep your packages up to date is to use Christoph Gohlke's Python Extension Packages for Windows repository. Many packages depend on his MKL-linked version of numpy, including pandas. The nice thing about all of these packages is that they are pre-compiled against both 32- and 64-bit versions of Python, and are generally available for Python 2.7, 3.3, and 3.4 (depending on the package, of course - some haven't been ported to Py3 yet). They are available in .whl format, so installation/upgrading is as easy as

pip install -U name_of_package.whl
MattDMo
  • 100,794
  • 21
  • 241
  • 231
  • It won't :( It runs when I put your command in and looks like it's working.. Downloading, extracting, creating all kinds of stuff. Then gives a couple of errors at the end: – cardamom Apr 20 '15 at 19:04
  • x86_64-linux-gnu-gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -Ipandas/src/klib -Ipandas/src -I/usr/lib/python2.7/dist-packages/numpy/core/include -I/usr/include/python2.7 -c pandas/index.c -o build/temp.linux-x86_64-2.7/pandas/index.o pandas/index.c:8:22: fatal error: pyconfig.h: No such file or directory #include "pyconfig.h" ^ compilation terminated. error: command 'x86_64-linux-gnu-gcc' failed with exit status 1 ---------------------------------------- Rolling back uninstall of pandas Cleaning up... – cardamom Apr 20 '15 at 19:04
  • @Felix what operating system are you running? At the minimum, you need to install the `python-dev` package from your package manager (`apt-get`, `yum`, whatever), as that is what supplies `pyconfig.h` and some other necessary files. – MattDMo Apr 20 '15 at 19:11
  • The operating system is Linux Mint 17.1 I think, but when I put in `uname -a` it gives Linux xanadu 3.13.0-37-generic #64-Ubuntu SMP Mon Sep 22 21:28:38 UTC 2014 x86_64 x86_64 x86_64 GNU/Linux . I took your advice and installed python-dev from the installer on the Mint gui. Then reran the panda upgrade command, which has yielded different errors this time. – cardamom Apr 20 '15 at 19:35
  • x86_64-linux-gnu-gcc: error trying to exec 'cc1plus': execvp: No such file or directory error: command 'x86_64-linux-gnu-gcc' failed with exit status 1 Rolling back uninstall of pandas Cleaning up... Command /usr/bin/python -c "import setuptools, tokenize;__file__='/tmp/pip_build_root/pandas/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /tmp/pip-jznXRo-record/install-record.txt --single-version-externally-managed --compile failed with error code 1 in /tmp/pip_build_root/pandas – cardamom Apr 20 '15 at 19:35
  • When I did this on Windows, I just installed Anaconda which brought over a lot of dependencies for scientific python.. Maybe should work out how to do that on Linux, I suspect that Mint installer installs one bit at a time and leaves important things out. – cardamom Apr 20 '15 at 19:37
  • @Felix if you're not planning on building a lot of packages from scratch, then Anaconda might be the best way for you to go - they have a version for Linux. They're only at 0.15.2 for `pandas`, but that should work for this problem. – MattDMo Apr 20 '15 at 21:02
  • However, if you want to keep plugging ahead, try installing the `g++` package for compiling C++ code - that's what your latest error is complaining about. – MattDMo Apr 20 '15 at 21:04
  • Yes it definitely needed the g++ package. After that one was installed, pandas updated correctly to 0.16.0 – cardamom Apr 21 '15 at 16:55