1

I installed an application in the /opt directory and added its root to the PATH (for all users who want to use it). 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. 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?

Eli Korvigo
  • 10,265
  • 6
  • 47
  • 73
  • 2
    The name of the script `ragout.py` clashes with the name of the `regout` package. You just need to rename the script. – Klaus D. Feb 14 '17 at 11:38
  • I think `from ragout.main import main` tries to import `main` from your `ragout.py` which is not defined there. It prints the line twice because basically you built an [infinite import loop](http://stackoverflow.com/q/3558842/3005167) but Python is too smart to get locked up. – MB-F Feb 14 '17 at 11:40
  • @kazemakase then why does it work for my user? – Eli Korvigo Feb 14 '17 at 11:41
  • @KlausD. Yeah, I've tried that already to no avail. – Eli Korvigo Feb 14 '17 at 11:43
  • @kazemakase and I've tried renaming `ragout.py`, too. It seems to make no difference at all. – Eli Korvigo Feb 14 '17 at 11:45
  • @EliKorvigo so it works on your machine but not on your users'? That's damn hard to debug :) Try to print `sys.path` on both machines. If `"."` or `""` is in the path of only one of them this may be the reason why the script tries to import itself. – MB-F Feb 14 '17 at 11:56
  • Nevermind, you put the path to ragout in front anyway. – MB-F Feb 14 '17 at 12:00
  • @kazemakase it is the same machine and the same installation just different users. – Eli Korvigo Feb 14 '17 at 12:07
  • Do the other users have the correct permissions to see the location? – Alan Feb 14 '17 at 13:15
  • What are the directory contents ? – Mr_and_Mrs_D Feb 14 '17 at 14:37

1 Answers1

2

I think this is a permissions issue. See this Stack Overflow question where the user reports a very similar issue.

  • You created the location, therefore you have permissions for it and can import it.
  • The other users do not have permission and cannot import from a folder they can't read.

Solution: make sure the all appropriate users are in a user group with at least read permission to the folder.

Community
  • 1
  • 1
Alan
  • 2,914
  • 2
  • 14
  • 26
  • Yes, you are right. The users have rights to access the root directory containing `ragout.py` itself, but not the subdirectories. – Eli Korvigo Feb 14 '17 at 15:25