2017-02-14 111 views
1

我安裝在/opt目錄中的應用程序,並添加其根到PATH(誰想要使用它的所有用戶)。現在,當我從我的用戶調用主腳本,它工作正常,但其他用戶報告了同樣的錯誤:無法導入本地模塊

[email protected]:~$ ragout.py -h 
Traceback (most recent call last): 
    File "/opt/ragout-2.0-linux-x86_64/ragout.py", line 33, in <module> 
    from ragout.main import main 
    File "/opt/ragout-2.0-linux-x86_64/ragout.py", line 33, in <module> 
    from ragout.main import main 
ImportError: No module named main 

這裏是主腳本:

#!/usr/bin/env python2.7 

#(c) 2013-2014 by Authors 
#This file is a part of Ragout program. 
#Released under the BSD license (see LICENSE file) 

""" 
This script does all the necessary preparations 
and invokes Ragout 
""" 

import os 
import sys 

LIB_DIR = "lib" 

#Check Python version 
if sys.version_info[:2] != (2, 7): 
    print("Error: Ragout requires Python version 2.7 ({0}.{1} detected)." 
      .format(sys.version_info[0], sys.version_info[1])) 
    sys.exit(-1) 

#Setting executable paths 
ragout_root = os.path.dirname(os.path.realpath(__file__)) 
lib_absolute = os.path.join(ragout_root, LIB_DIR) 
sys.path.insert(0, lib_absolute) 
sys.path.insert(0, ragout_root) 
os.environ["PATH"] = lib_absolute + os.pathsep + os.environ["PATH"] 


#Ragout entry point 
from ragout.main import main 
sys.exit(main()) 

我想通腳本可能面臨一些問題擴大ragout_rootlib_absolute,所以我加了print(ragout_root, lib_absolute)只是from ragout.main import main之前看到的,發生了什麼。現在,當我從我的用戶運行應用程序時,我得到這個:

[email protected]:~$ ragout.py -h 
('/opt/ragout-2.0-linux-x86_64', '/opt/ragout-2.0-linux-x86_64/lib') 
usage: ragout.py [-h] [-o output_dir] [-s {sibelia,maf,hal}] [--refine] 
       [--solid-scaffolds] [--overwrite] [--repeats] [--debug] 
       [-t THREADS] [--version] 
       recipe_file 
... 

,並得到了用戶這個

[email protected]:~$ ragout.py -h 
('/opt/ragout-2.0-linux-x86_64', '/opt/ragout-2.0-linux-x86_64/lib') 
('/opt/ragout-2.0-linux-x86_64', '/opt/ragout-2.0-linux-x86_64/lib') 
Traceback (most recent call last): 
    File "/opt/ragout-2.0-linux-x86_64/ragout.py", line 33, in <module> 
    from ragout.main import main 
    File "/opt/ragout-2.0-linux-x86_64/ragout.py", line 33, in <module> 
    from ragout.main import main 
ImportError: No module named main 

對於它打印無論何種原因兩次 - 儘管路徑是正確的 - 它仍然無法從本地模塊導入。有任何想法嗎?

+2

腳本'的名稱ragout.py'與'regout'包的名稱衝突。你只需要重命名腳本。 –

+0

我認爲'從ragout.main import main'嘗試從'ragout.py'中導入'main',這個在那裏沒有定義。它打印兩行,因爲基本上你構建了一個[無限導入循環](http://stackoverflow.com/q/3558842/3005167),但Python太聰明瞭,無法鎖定。 – kazemakase

+0

@kazemakase然後爲什麼它爲我的用戶工作? –

回答

2

我認爲這是一個權限問題。請參閱this Stack Overflow question用戶報告非常類似的問題。

  • 您創建的位置,因此,你有權爲它和 可以進口。
  • 其他用戶沒有權限,不能從他們無法讀取文件夾導入。

解決方法:確保所有適當的用戶都在用戶組至少讀取權限的文件夾。

+0

是的,你是對的。用戶有權訪問包含'ragout.py'本身的根目錄,但不能訪問子目錄。 –