diff --git a/pygit2/__init__.py b/pygit2/__init__.py
index 151fcaf..6a0e24b 100644
--- a/pygit2/__init__.py
+++ b/pygit2/__init__.py
@@ -25,5 +25,6 @@
 # the Free Software Foundation, 51 Franklin Street, Fifth Floor,
 # Boston, MA 02110-1301, USA.
 
+from .version import __version__
 from _pygit2 import *
 import pygit2.utils
diff --git a/pygit2/version.py b/pygit2/version.py
new file mode 100644
index 0000000..e5179fc
--- /dev/null
+++ b/pygit2/version.py
@@ -0,0 +1,26 @@
+# Copyright 2012 The pygit2 contributors
+#
+# This file is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License, version 2,
+# as published by the Free Software Foundation.
+#
+# In addition to the permissions in the GNU General Public License,
+# the authors give you unlimited permission to link the compiled
+# version of this file into combinations with other programs,
+# and to distribute those combinations without any restriction
+# coming from the use of this file.  (The General Public License
+# restrictions do apply in other respects; for example, they cover
+# modification of the file, and distribution when not linked into
+# a combined executable.)
+#
+# This file is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; see the file COPYING.  If not, write to
+# the Free Software Foundation, 51 Franklin Street, Fifth Floor,
+# Boston, MA 02110-1301, USA.
+
+__version__ = '0.17.2'
diff --git a/setup.py b/setup.py
index 4722427..7a8dce8 100644
--- a/setup.py
+++ b/setup.py
@@ -38,6 +38,11 @@ from distutils.command.build import build
 from distutils.command.sdist import sdist
 from distutils import log
 
+# read version from local pygit2/version.py without pulling in
+# pygit2/__init__.py
+sys.path.insert(0, 'pygit2')
+from version import __version__
+
 
 # Use environment variable LIBGIT2 to set your own libgit2 configuration.
 libgit2_path = os.getenv("LIBGIT2")
@@ -163,7 +168,7 @@ with open('README.rst') as readme:
 setup(name='pygit2',
       description='Python bindings for libgit2.',
       keywords='git',
-      version='0.17.2',
+      version=__version__,
       url='http://github.com/libgit2/pygit2',
       classifiers=classifiers,
       license='GPLv2',