0

In my perl program which runs the python script

I have provided the PYTHONPATH env param with the path for the lib and i have run the python script. I am getting

ImportError: No module named "....."

  my $script = "/path/pythonscript.py";
     $ENV{'PYTHONPATH'} = "/path/lib";
      system("python $script"); 

Whereas when i run the same python script on command line in the same directory where the script executes in my perl program, it is working.

Can anyone give me some pointers on why this is happening.

1

2 Answers 2

1

Try printing the contents of sys.path and compare the difference e.g. change your python script to

import sys

print(sys.path)

Most likely there is a difference here and this is causing the module to not be found.

Sign up to request clarification or add additional context in comments.

2 Comments

I have tried this already and i see the path is there in both cases of the lib
Are the paths identical? Is all the python code in the lib dir? or is some of the code in the working directory? could you perhaps paste the output here? The python interpreter searches for modules differently when running python /path/script compared to python script
0

I once had a similar problem. I solved it by creating an executable script (chmod) and making that script run instead of the python script. The script simply contained a cd to the directory and a python3 program. py

3 Comments

Why do you think adding another process between Perl and Python will solve anything?
'Cause if launched independently from cmd-line the python script MUST start
That's just superstition. If the shell script can run Python then so can Perl.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.