using the ``setup.py`` script. The C extensions as well as Python 3 builds are supported.
* **Setuptools or Distribute** - 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.
+ 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.
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.
The C extensions now compile on Python 3 as well as Python 2.
-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 = False
try:
- from setuptools import setup, Extension, Feature
- has_setuptools = True
+ from setuptools import setup, Extension
+ 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
-cmdclass = {}
-pypy = hasattr(sys, 'pypy_version_info')
-jython = sys.platform.startswith('java')
+try:
+ import platform
+except ImportError:
+ pypy = hasattr(sys, 'pypy_version_info')
+ jython = sys.platform.startswith('java')
+ cpython = not pypy and not jython
+else:
+ cpython = platform.python_implementation() == 'CPython'
+
py3k = False
+
+cmdclass = {}
extra = {}
if sys.version_info < (2, 6):
raise Exception("SQLAlchemy requires Python 2.6 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,
**kwargs
)
-if pypy or jython:
+if not cpython:
run_setup(False)
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)