Created
April 21, 2012 00:28
-
-
Save lennax/2432815 to your computer and use it in GitHub Desktop.
Conditional NumPyPy import
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
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