1

I am dynamically importing the numpy package into a python environment of another proprietary system. The top level numpy package gets imported from the right place, but the numpy.random package is pointing to the standard library. Why is this happening?

Code

import sys

LIB_PATH = 'T:\\Some\\Path\\'

if LIB_PATH not in sys.path:
    sys.path.insert(0, LIB_PATH)

import numpy

print numpy
print numpy.random

Output

<module 'numpy' from 'T:\Some\Path\numpy\__init__.pyc'>
<module 'random' from 'C:\Python26x64\Lib\random.pyc'>

Why is numpy.random pointing to C:\Python26x64\Lib\random.pyc. When I run this from my standard python interpreter at C:\Python26x64\, then random is indeed the one in the numpy package

4

1 回答 1

0

这是对我有用的解决方案。它认为它不是一个好的解决方案,因为它需要更改包中的一行代码numpy。尽管如此,它允许我们在专有软件中使用pandas嵌入式numpyPython 解释器,只需将文件夹添加到sys.path.

文件已更改

T:\Some\Path\numpy\__init__.py

行前

线路:171 -import random

此行假定random将从中加载T:\Some\Path\numpy\random\

线后

线路:171 -from numpy import random

这迫使它使用randomnumpy而不是标准包

我以为我会留在那里,直到有人能想出更好的解决方案,才能得到一个不被接受的答案。

于 2013-08-21T13:35:46.703 回答