2017-02-17 31 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

相關問題