Skip to content

Instantly share code, notes, and snippets.

@lennax
Created April 21, 2012 00:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lennax/2432815 to your computer and use it in GitHub Desktop.
Save lennax/2432815 to your computer and use it in GitHub Desktop.
Conditional NumPyPy import
"""
This is located inside a fake numpy, and could allow "import numpy"
to work invisibly on both Python and PyPy.
Not quite sure how to get files to find it.
In any case, NumPyPy is only a partial implementation of NumPy,
so it's probably not ready for unintended/untested/automatic use.
"""
import sys
# Delete current directory from module search path
del sys.path[0]
import platform
try:
if platform.python_implementation() == "PyPy":
from numpypy import *
else:
import imp
_name = "numpy"
# Find and load real numpy
imp.load_module(_name, *imp.find_module(_name))
except ImportError as err:
print err, "(problem importing NumPy or NumPyPy)"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment