[英]Can't import local module
I installed an application in the /opt
directory and added its root to the PATH (for all users who want to use it). 我在
/opt
目录中安装了一个应用程序,并将其根目录添加到PATH(适用于所有想要使用它的用户)。 Now, when I invoke the master script from my user, it works fine, but other users report the same error: 现在,当我从用户调用主脚本时,它可以正常工作,但其他用户报告相同的错误:
user@server:~$ 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
Here is the master script: 这是主脚本:
#!/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())
I figured the script could face some problems expanding ragout_root
and lib_absolute
, so I added print(ragout_root, lib_absolute)
just before the from ragout.main import main
to see, what's happening. 我认为脚本在扩展
ragout_root
和lib_absolute
可能会遇到一些问题,因此我在from ragout.main import main
之前添加了print(ragout_root, lib_absolute)
来查看发生了什么。 Now, when I run the app from my user, I get this: 现在,当我从用户运行应用程序时,我得到了:
me@server:~$ 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
...
and the users get this 和用户得到这个
user@server:~$ 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
For whatever reason it prints twice and – although the paths are correct – it still can't import from the local module. 无论出于何种原因,它都会打印两次,并且-尽管路径正确-但仍然无法从本地模块导入。 Any ideas?
有任何想法吗?
I think this is a permissions issue. 我认为这是一个权限问题。 See this Stack Overflow question where the user reports a very similar issue.
请参阅此堆栈溢出问题 ,用户报告一个非常相似的问题。
Solution: make sure the all appropriate users are in a user group with at least read permission to the folder. 解决方案:确保所有适当的用户都在一个对该文件夹至少具有读取权限的用户组中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.