2017-02-17 72 views
0

我正在运行运行Red Hat Enterprise Linus - 6+的强大群集。当父目录已经拥有该库的旧版本时,Python从另一个目录导入更新的库

我需要从另一个目录中导入一个库(Say Tensorflow),但主目录已经包含一个旧版本的tensorflow。

结构 -

I Don't have Admin privileges for these libraries 

Anaconda-directory 
|--- tensorflow 0.7 
|--- other libraries which I need 

Other Directory 
|--- tensorflow 0.11 

My Home Directory (I have privileges here) 
Local directory of anaconda 
|--- Keras 

所以,我需要使用Anaconda目录,但我想用的tensorflow (0.11)更新版本,我也想用Keras

我曾尝试下面的命令 -

METHOD - 1 
# Load Anaconda module 
module load apps/anaconda/4.1.1/gnu 
# Has tensorflow 0.7 installed 
jupyter notebook 
--> Works, but with tensorflow 0.7 (Which is incompatible with keras) 

METHOD - 2 
# Load new version of tensorflow 
# It automatically python module located at compiler/python/2.7.10/compilervars along with CUDAnn and others 
module load apps/tensorflow/0.11/gnu 

# Point to my local installation of anaconda where I have installed Keras 
export PYTHONPATH=/home/-path-to-my-home-dir/anaconda2/lib/python2.7/site-packages/:$PYTHONPATH 

echo $PYTHONPATH 
/home/-path-to-my-home-dir/anaconda2/lib/python2.7/site-packages/:/home/apps/TENSOR_GPU/0.11/gnu/lib/python2.7/site-packages/ 

--> Works well in python shell, but I want to use IPython Notebook 

jupyter notebook 
--> Doesn't work in Ipython Notebook, which I guess is due to the reason that it uses jupyter notebook from my home dir (Not an Admin) 


### WHAT I WANT ### 
Anaconda Distribution --> From Server Module Directory (Not my local Directory) 
Jypyter --> From above anaconda dist (Not my local anaconda dist) 
Tensorflow --> From another module (Newer Version) 
Keras --> Installed in my local anaconda distribution 

# Any Other additional packages 
# either not available on server (I can't install on server) 
# or older versions available 
# For such libraries, I should be able to use just that package 
# from my home directory (I can have anaconda installed on my home dir) 

回答

0

我会尝试这一点。

  • 打开Jupyter笔记本。
  • import sys
  • sys.path[0:0] = ["/path/to/new/tensorflow"]
  • 进口tensorflow,检查版本。
  • 从Anaconda导入库。

第三步可以延伸到你的口味,包括其他东西离开你的正常PYTHONPATH

+0

刚刚尝试过 'sys.path [0:0] = [“/home/apps/TENSOR_GPU/0.11/gnu/lib/python2.7/site-packages/tensorflow”] 但仍然使用较旧的张量流版本 'tensorflow .__ version__ '0.7.1'' –

+0

'>>> sys.path' = '['/'/home/apps/TENSOR_GPU/0.11/gnu/lib/python2.7/site-packages/tensorflow ','','/home/apps/TENSOR_GPU/lib/python27.zip','/home/apps/TENSOR_GPU/lib/python2.7','/home/apps/TENSOR_GPU/lib/python2.7/plat -linux2','/home/apps/TENSOR_GPU/lib/python2.7/lib-tk','/home/apps/TENSOR_GPU/lib/python2.7/lib-old','/ home/apps/TENSOR_GPU/lib/python2.7/lib-dynload','/home/apps/TENSOR_GPU/lib/python2.7/site-packages','/home/apps/TENSOR_GPU/lib/python2.7/site-packages/Sphinx- 1.4.1-py2.7.egg','/ home /apps/TENSOR_GPU/lib/python2.7/site-packages/setuptools-23.0.0-py2.7.egg']' –

+0

我只能怀疑你的笔记本初始化已经导入tensorflow。 'sys.modules.keys()'在新打开的笔记本中是否包含“tensorflow”?顺便尝试'重新加载(“tensorflow”)';也许它会重新加载它从一个新的路径。 (并不是说我喜欢这种方法。) – 9000