gslab-econ / gslab_python

Python tools for GSLab
MIT License
13 stars 11 forks source link

reading windows paths #162

Closed jmshapir closed 6 years ago

jmshapir commented 6 years ago

I'm getting the error that LyX isn't on my path even though it is. (Example below.)

It could be an issue with how my path is set up. (I am on Windows.)

Can you give me a rough sense of the logic that the is_in_path function is using to find whether "lyx" is on path?

That might give us a clue about the source of the issue.


C:\Users\jshapir1\Documents\GitHub\Skills\paper_slides>python run.py
scons: Reading SConscript files ...
PrerequisiteError: Cannot find executable for lyx in PATH.:
  File "C:\Users\jshapir1\Documents\GitHub\Skills\paper_slides\SConstruct", line 12:
    [mode, cache_dir, CONFIG, executable_names, prereqs, pythonpath] = configuration(ARGUMENTS)
  File "../config\configuration.py", line 55:
    gslab_vers = CONFIG['global']['gslab_version'])
  File "C:\Python27\lib\site-packages\gslab_scons\check_prereq.py", line 22:
    raise PrerequisiteError(message)

C:\Users\jshapir1\Documents\GitHub\Skills\paper_slides>lyx

C:\Users\jshapir1\Documents\GitHub\Skills\paper_slides>
DavidRitzwoller commented 6 years ago

@jmshapir In the config_global.yaml in \Users\jshapir1\Documents\GitHub\Skills\paper_slides\, can you try changing the executable_names for lyx to lyx? E.g

screen shot 2018-09-20 at 1 36 26 pm
jmshapir commented 6 years ago

@DavidRitzwoller

image

DavidRitzwoller commented 6 years ago

Thanks @jmshapir. Returning to the logic of is_in_path, lets see if os is able to interact with your path environment variable in the way we expect it to.

Would you mind opening an interactive python or ipython session and sending the output of the following two scripts?

  1. First, lets see if os is able to access your path environment variable, and further what it looks like.
import os

user_path = os.environ['PATH'].split(os.pathsep)
print user_path

When I execute this I see screen shot 2018-09-21 at 10 03 50 am

  1. Second, if we see that lyx is in your path, lets see if we are able to parse it how we expect we should be able to.
    exe = []
    for path in os.environ['PATH'].split(os.pathsep):
    path = path.strip("'")
    exe_temp = os.path.join(path, "lyx")
    if os.access(exe_temp, os.X_OK):
        exe.append(exe_temp)
    print exe

When I execute this I see screen shot 2018-09-21 at 10 05 44 am

jmshapir commented 6 years ago

@DavidRitzwoller 1.


>>> import os
>>>
>>> user_path = os.environ['PATH'].split(os.pathsep)
>>> print user_path
['C:\\Program Files (x86)\\Intel\\iCLS Client\\', 'C:\\Program Files\\Intel\\iCLS Client\\', 'C:\\WINDOWS\\system32', 'C:\\WINDOWS', 'C:\\WINDOWS\\System32\\Wbem', 'C:\\WINDOWS\\System32\\WindowsPowerShell\\v1.0\\', 'C:\\Program Files\\Intel\\WiFi\\bin\\', 'C:\\Program Files\\Common Files\\Intel\\WirelessCommon\\', 'C:\\Program Files (x86)\\PuTTY\\', 'C:\\Program Files (x86)\\MiKTeX 2.9\\miktex\\bin\\', 'C:\\Program Files (x86)\\LyX 2.2\\Perl\\bin', 'C:\\Program Files (x86)\\Putty', 'C:\\Program Files (x86)\\LyX 2.2\\bin\\', 'C:\\Program Files (x86)\\MikTex 2.9\\', 'C:\\Python27\\', 'C:\\Program Files\\Git\\cmd', 'C:\\Program Files\\MiKTeX 2.9\\miktex\\bin\\x64\\', 'C:\\Program Files (x86)\\LyX 2.3\\Perl\\bin', 'C:\\Program Files (x86)\\Intel\\Intel(R) Management Engine Components\\DAL', 'C:\\Program Files\\Intel\\Intel(R) Management Engine Components\\DAL', 'C:\\Program Files (x86)\\Intel\\Intel(R) Management Engine Components\\IPT', 'C:\\Program Files\\Intel\\Intel(R) Management Engine Components\\IPT', 'C:\\Python27\\Scripts', 'C:\\Users\\jshapir1\\AppData\\Local\\Microsoft\\WindowsApps', 'C:\\Users\\jshapir1\\AppData\\Local\\GitHubDesktop\\bin']

2.


>>> exe = []
>>> for path in os.environ['PATH'].split(os.pathsep):
...     path = path.strip("'")
...     exe_temp = os.path.join(path, "lyx")
...     if os.access(exe_temp, os.X_OK):
...         exe.append(exe_temp)
... print exe
  File "<stdin>", line 6
    print exe
        ^
SyntaxError: invalid syntax
DavidRitzwoller commented 6 years ago

Thanks @jmshapir.

  1. Sorry, there was a white space error in the second script that throws an error when not using ipython. Do you mind trying this corrected version?
    
    import os

exe = [] for path in os.environ['PATH'].split(os.pathsep): path = path.strip("'") exe_temp = os.path.join(path, "lyx") if os.access(exe_temp, os.X_OK): exe.append(exe_temp)

print exe

EDIT:
3. Can you send me screenshots of the contents of the directories?

C:\Program Files (x86)\LyX 2.2\Perl\bin C:\Program Files (x86)\LyX 2.2\bin\ C:\Program Files (x86)\LyX 2.3\Perl\bin

jmshapir commented 6 years ago

@DavidRitzwoller we are now on a different Windows PC. (But it gets the same error when scanning for LyX).

1 and 2:


C:\Users\jshapir1\Documents\GitHub\Skills\paper_slides>python
Python 2.7.13 (v2.7.13:a06454b1afa1, Dec 17 2016, 20:42:59) [MSC v.1500 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import os
>>>
>>> user_path = os.environ['PATH'].split(os.pathsep)
>>> print user_path
['C:\\ProgramData\\Oracle\\Java\\javapath', 'C:\\windows\\SYSTEM32', 'C:\\windows', 'C:\\windows\\SYSTEM32\\WBEM', 'C:\\windo
ws\\System32\\WindowsPowerShell\\v1.0\\', 'C:\\windows\\System32\\WindowsPowerShell\\v1.0\\', 'C:\\Program Files (x86)\\ATI T
echnologies\\ATI.ACE\\Core-Static', 'C:\\Program Files\\Intel\\WiFi\\bin\\', 'C:\\Program Files\\Common Files\\Intel\\Wireles
sCommon\\', 'C:\\Program Files (x86)\\Intel\\OpenCL SDK\\3.0\\bin\\x86', 'C:\\Program Files (x86)\\Intel\\OpenCL SDK\\3.0\\bi
n\\x64', 'C:\\Program Files (x86)\\MiKTeX 2.9\\miktex\\bin\\', 'C:\\Program Files (x86)\\LyX 2.1\\bin', 'C:\\Program Files (x
86)\\LyX 2.1\\Perl\\bin', 'C:\\Python27\\', 'C:\\Python27\\Scripts', 'C:\\Program Files\\Git LFS', 'C:\\windows\\System32\\Wi
ndowsPowerShell\\v1.0\\', 'C:\\Program Files (x86)\\PuTTY', 'C:\\Program Files\\Git\\cmd', 'C:\\Program Files (x86)\\LyX 2.2\
\Perl\\bin', 'C:\\Program Files (x86)\\LyX 2.3\\Perl\\bin', 'C:\\Program Files\\Intel\\WiFi\\bin\\', 'C:\\Program Files\\Comm
on Files\\Intel\\WirelessCommon\\', 'C:\\Program Files (x86)\\PuTTY', 'C:\\Users\\jshapir1\\AppData\\Local\\GitHubDesktop\\bi
n']
>>> import os
>>>
>>> exe = []
>>> for path in os.environ['PATH'].split(os.pathsep):
...     path = path.strip("'")
...     exe_temp = os.path.join(path, "lyx")
...     if os.access(exe_temp, os.X_OK):
...         exe.append(exe_temp)
...
>>> print exe
[]
>>>

3. image

image

image

DavidRitzwoller commented 6 years ago

@jmshapir I think I see whats going on.

On MacOS, we can check that we have access to the executable for lyx by checking if we have access to a file named lyx in each of the directories on our path. On Windows, I believe we will need to search to see if we have access to lyx.exe instead. Can you try the following?

import os

exe = []
for path in os.environ['PATH'].split(os.pathsep):
    path = path.strip("'")
    exe_temp = os.path.join(path, "lyx.exe")
    if os.access(exe_temp, os.X_OK):
        exe.append(exe_temp)

print exe
jmshapir commented 6 years ago

@DavidRitzwoller


>>> import os
>>>
>>> exe = []
>>> for path in os.environ['PATH'].split(os.pathsep):
...     path = path.strip("'")
...     exe_temp = os.path.join(path, "lyx.exe")
...     if os.access(exe_temp, os.X_OK):
...         exe.append(exe_temp)
...
>>> print exe
['C:\\Program Files (x86)\\LyX 2.1\\bin\\lyx.exe']
DavidRitzwoller commented 6 years ago

@jmshapir Great! I'll edit is_in_path to loop over both lyx and lyx.exe. That should get things working.

DavidRitzwoller commented 6 years ago

@jmshapir Here's a short term fix until the branchdev_4.1.3 is merged to master.

In the config_global.yaml in paper_slides, set prereq_checks: for lyx to No. E.g

screen shot 2018-09-21 at 5 11 05 pm

If you don't want to turn off the prereq_check, the function is_in_path can be changed to

def is_in_path(program):
    '''
    This general helper function checks whether `program` exists in the 
    user's path environment variable.
    '''
    if os.access(program, os.X_OK):
        return program
    else:
        for path in os.environ['PATH'].split(os.pathsep):
            path = path.strip("'")
            exe = os.path.join(path, program)
            if os.access(exe, os.X_OK):
                return exe
            exe = os.path.join(path, program + ".exe")
            if os.access(exe, os.X_OK):
                return exe

    return False

and error should be resolved.

jmshapir commented 6 years ago

Thanks @DavidRitzwoller. Already turned off lyx-checking in the global config as a short-term fix. Thanks!

DavidRitzwoller commented 6 years ago

Summary: In this issue, gslab_python was augmented to search for prerequisites on Windows operating systems. PR at #163.