1827806 Members
2246 Online
109969 Solutions
New Discussion

locating python modules

 
SOLVED
Go to solution
John Tannahill
Frequent Advisor

locating python modules

We have Python code in multiple directories that make up package constructs (i.e., use the __init__.py feature). If I execute a Python script from within these directories, the imports work just fine. If I define an OpenVMS symbol that calls the script so that I can execute it from anywhere, and do so outside of the directory where the code resides, the imports are not found. I am looking for an easy way to solve this issue. On a UNIX system, I think I would just create one alias with two commands in it: one that moved me to the exlicit directory prior to calling the script, the other would then execute it. When finished, I would be back in my original directory. I don't think that I can do this with OpenVMS symbols?

I also do have a pythonpath entry that points to the top directory of the Python code, but I am not sure exactly what this is getting me? I really would rather not play around with the paths as the code is in a configuration management system and can be dropped anywhere. What I wish would happen is that when I execute the script, its environment would be where it exists, not where it is called from, but it does not look like this is going to happen.

Ideas?

John
5 REPLIES 5
Karl Rohwedder
Honored Contributor

Re: locating python modules

To simulate the UNIX way you may use pipe:

$ prog == "pipe (set default xx ; prog)

refards kalle
Jean-François Piéronne
Trusted Contributor
Solution

Re: locating python modules

John,

if you invoke your script using a Unix syntax the directory of the the script is automatically added to the path used by Python to locate module.
For example
python /dev/dir/myscript.py
instead of
python dev:[dir]myscript.py

I will lift this restriction sometime...

JF
John Tannahill
Frequent Advisor

Re: locating python modules

JF,

Thanks! Your solution worked for me. I was hoping there would be an easy solution. I had no idea I could even use unix style paths when I was invoking python!

Thanks again,
John
John Tannahill
Frequent Advisor

Re: locating python modules

Karl,

Thanks for the excellent info. Although JF's solution is the way we will go, I had no idea I could emulate this type of unix alias in openvms. There may be places down the road where we will make use of it.

John
John Tannahill
Frequent Advisor

Re: locating python modules

See previous responses.