using the ``setup.py`` script. The C extensions as well as Python 3 builds are supported.
* **Standard Setuptools** - When using `setuptools <http://pypi.python.org/pypi/setuptools/>`_,
SQLAlchemy can be installed via ``setup.py`` or ``easy_install``, and the C
- extensions are supported. setuptools is not supported on Python 3 at the time
- of this writing.
-* **Distribute** - With `distribute <http://pypi.python.org/pypi/distribute/>`_,
- SQLAlchemy can be installed via ``setup.py`` or ``easy_install``, and the C
- extensions as well as Python 3 builds are supported.
+ extensions are supported.
* **pip** - `pip <http://pypi.python.org/pypi/pip/>`_ is an installer that
rides on top of ``setuptools`` or ``distribute``, replacing the usage
of ``easy_install``. It is often preferred for its simpler mode of usage.
This command will download the latest version of SQLAlchemy from the `Python
Cheese Shop <http://pypi.python.org/pypi/SQLAlchemy>`_ and install it to your system.
+.. note::
+
+ Beta releases of SQLAlchemy may not be present on Pypi, and may instead
+ require a direct download first.
+
Installing using setup.py
----------------------------------
dealing with result sets. Currently, the extensions are only supported on the
2.xx series of cPython, not Python 3 or Pypy.
-setup.py will automatically build the extensions if an appropriate platform is
+``setup.py`` will automatically build the extensions if an appropriate platform is
detected. If the build of the C extensions fails, due to missing compiler or
other issue, the setup process will output a warning message, and re-run the
build without the C extensions, upon completion reporting final status.
To run the build/install without even attempting to compile the C extensions,
-pass the flag ``--without-cextensions`` to the ``setup.py`` script::
+the ``DISABLE_SQLALCHEMY_CEXT`` environment variable may be specified. The
+use case for this is either for special testing circumstances, or in the rare
+case of compatibility/build issues not overcome by the usual "rebuild"
+mechanism::
- python setup.py --without-cextensions install
+ # *** only in SQLAlchemy 0.9.4 / 0.8.6 or greater ***
+ export DISABLE_SQLALCHEMY_CEXT=1; python setup.py install
-Or with pip::
+.. versionadded:: 0.9.4,0.8.6 Support for disabling the build of
+ C extensions using the ``DISABLE_SQLALCHEMY_CEXT`` environment variable
+ has been added. This allows control of C extension building whether or not
+ setuptools is available, and additionally works around the fact that
+ setuptools will possibly be **removing support** for command-line switches
+ such as ``--without-extensions`` in a future release.
- pip install --global-option='--without-cextensions' SQLAlchemy
+ For versions of SQLAlchemy prior to 0.9.4 or 0.8.6, the
+ ``--without-cextensions`` option may be used to disable the attempt to build
+ C extensions, provided setupools is in use, and provided the ``Feature``
+ construct is supported by the installed version of setuptools::
-.. note::
+ python setup.py --without-cextensions install
+
+ Or with pip::
+
+ pip install --global-option='--without-cextensions' SQLAlchemy
- The ``--without-cextensions`` flag is available **only** if ``setuptools``
- or ``distribute`` is installed. It is not available on a plain Python ``distutils``
- installation. The library will still install without the C extensions if they
- cannot be built, however.
Installing on Python 3
----------------------------------
from distutils.command.build_ext import build_ext
from distutils.errors import (CCompilerError, DistutilsExecError,
DistutilsPlatformError)
+
+has_feature = has_setuptools = False
try:
- from setuptools import setup, Extension, Feature
+ from setuptools import setup, Extension
has_setuptools = True
+ try:
+ # see
+ # https://bitbucket.org/pypa/setuptools/issue/65/deprecate-and-remove-features,
+ # where they may remove Feature.
+ from setuptools import Feature
+ has_feature = True
+ except ImportError:
+ pass
except ImportError:
- has_setuptools = False
from distutils.core import setup, Extension
Feature = None
try: # Python 3
except ImportError: # Python 2
from distutils.command.build_py import build_py
-cmdclass = {}
-pypy = hasattr(sys, 'pypy_version_info')
-jython = sys.platform.startswith('java')
+py25 = sys.version_info < (2, 6)
+
+if py25:
+ pypy = hasattr(sys, 'pypy_version_info')
+ jython = sys.platform.startswith('java')
+ cpython = not pypy and not jython
+else:
+ import platform
+ cpython = platform.python_implementation() == 'CPython'
+
py3k = False
+
+cmdclass = {}
extra = {}
if sys.version_info < (2, 4):
raise Exception("SQLAlchemy requires Python 2.4 or higher.")
def run_setup(with_cext):
kwargs = extra.copy()
if with_cext:
- if Feature:
+ if has_feature:
kwargs['features'] = {'cextensions': Feature(
"optional C speed-enhancements",
standard=True,
if hasattr(RefactoringTool, 'old_refactor_string'):
RefactoringTool.refactor_string = RefactoringTool.old_refactor_string
-if pypy or jython or py3k:
+if not cpython or py3k:
if py3k:
# monkeypatch our preprocessor onto the 2to3 tool.
monkeypatch2to3()
# unmonkeypatch to not stomp other setup.py's that are compiled
# and exec'd and which also require 2to3 fixing
unmonkeypatch2to3()
+
status_msgs(
"WARNING: C extensions are not supported on " +
"this Python platform, speedups are not enabled.",
"Plain-Python build succeeded."
)
+elif os.environ.get('DISABLE_SQLALCHEMY_CEXT'):
+ run_setup(False)
+ status_msgs(
+ "DISABLE_SQLALCHEMY_CEXT is set; not attempting to build C extensions.",
+ "Plain-Python build succeeded."
+ )
+
else:
try:
run_setup(True)