Skip to content

Allow importing pandas without setuptools #8409

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 29, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions doc/source/install.rst
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,8 @@ Optional Dependencies
* Google's `python-gflags <http://code.google.com/p/python-gflags/>`__
and `google-api-python-client <http://github.com/google/google-api-python-client>`__
* Needed for :mod:`~pandas.io.gbq`
* `setuptools <https://pypi.python.org/pypi/setuptools/>`__
* Needed for :mod:`~pandas.io.gbq` (specifically, it utilizes `pkg_resources`)
* `httplib2 <http://pypi.python.org/pypi/httplib2>`__
* Needed for :mod:`~pandas.io.gbq`
* One of the following combinations of libraries is needed to use the
Expand Down
69 changes: 40 additions & 29 deletions pandas/io/gbq.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import uuid

import numpy as np
import pkg_resources

from distutils.version import LooseVersion
from pandas import compat
Expand All @@ -20,46 +19,54 @@
_GOOGLE_FLAGS_INSTALLED = False
_GOOGLE_FLAGS_VALID_VERSION = False
_HTTPLIB2_INSTALLED = False
_SETUPTOOLS_INSTALLED = False

if not compat.PY3:

try:
from apiclient.discovery import build
from apiclient.http import MediaFileUpload
from apiclient.errors import HttpError
import pkg_resources
_SETUPTOOLS_INSTALLED = True
except ImportError:
_SETUPTOOLS_INSTALLED = False

if _SETUPTOOLS_INSTALLED:
try:
from apiclient.discovery import build
from apiclient.http import MediaFileUpload
from apiclient.errors import HttpError

from oauth2client.client import OAuth2WebServerFlow
from oauth2client.client import AccessTokenRefreshError
from oauth2client.client import flow_from_clientsecrets
from oauth2client.file import Storage
from oauth2client.tools import run
_GOOGLE_API_CLIENT_INSTALLED=True
_GOOGLE_API_CLIENT_VERSION = pkg_resources.get_distribution('google-api-python-client').version
from oauth2client.client import OAuth2WebServerFlow
from oauth2client.client import AccessTokenRefreshError
from oauth2client.client import flow_from_clientsecrets
from oauth2client.file import Storage
from oauth2client.tools import run
_GOOGLE_API_CLIENT_INSTALLED=True
_GOOGLE_API_CLIENT_VERSION = pkg_resources.get_distribution('google-api-python-client').version

if LooseVersion(_GOOGLE_API_CLIENT_VERSION >= '1.2.0'):
_GOOGLE_API_CLIENT_VALID_VERSION = True
if LooseVersion(_GOOGLE_API_CLIENT_VERSION >= '1.2.0'):
_GOOGLE_API_CLIENT_VALID_VERSION = True

except ImportError:
_GOOGLE_API_CLIENT_INSTALLED = False
except ImportError:
_GOOGLE_API_CLIENT_INSTALLED = False


try:
import gflags as flags
_GOOGLE_FLAGS_INSTALLED = True
try:
import gflags as flags
_GOOGLE_FLAGS_INSTALLED = True

_GOOGLE_FLAGS_VERSION = pkg_resources.get_distribution('python-gflags').version
_GOOGLE_FLAGS_VERSION = pkg_resources.get_distribution('python-gflags').version

if LooseVersion(_GOOGLE_FLAGS_VERSION >= '2.0.0'):
_GOOGLE_FLAGS_VALID_VERSION = True
if LooseVersion(_GOOGLE_FLAGS_VERSION >= '2.0.0'):
_GOOGLE_FLAGS_VALID_VERSION = True

except ImportError:
_GOOGLE_FLAGS_INSTALLED = False
except ImportError:
_GOOGLE_FLAGS_INSTALLED = False

try:
import httplib2
_HTTPLIB2_INSTALLED = True
except ImportError:
_HTTPLIB2_INSTALLED = False
try:
import httplib2
_HTTPLIB2_INSTALLED = True
except ImportError:
_HTTPLIB2_INSTALLED = False


logger = logging.getLogger('pandas.io.gbq')
Expand Down Expand Up @@ -296,10 +303,14 @@ def _test_imports():
_GOOGLE_FLAGS_INSTALLED
_GOOGLE_FLAGS_VALID_VERSION
_HTTPLIB2_INSTALLED
_SETUPTOOLS_INSTALLED

if compat.PY3:
raise NotImplementedError("Google's libraries do not support Python 3 yet")

if not _SETUPTOOLS_INSTALLED:
raise ImportError('Could not import pkg_resources (setuptools).')

if not _GOOGLE_API_CLIENT_INSTALLED:
raise ImportError('Could not import Google API Client.')

Expand Down