Search code examples
pythonopencvvirtualenvvirtualenvwrapper

open python script in virtualenv from python script


I want to open a python script from an other python scrip but in the virtualenv I tried os.system and subprocess.call but they couldn't open the virtualenv

os.system("workon cv") warning:

sh: 1: workon: not found

cmd = 'workon cv'

subprocess.call(cmd.split())     error:

    OSError: [Errno 2] No such file or directory

Solution

  • I solved the problem:

    1. the python script where I want to call the other python script should be opened in the virtualenv

    2. put all the code in main function and import the file: import FileName

    then call the main function: FileName.main()