0

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
2
  • you could wrap it in a module, place the module in the script folder or add the path to the module to the python path and import it. Commented Aug 2, 2017 at 12:11
  • Have you tried adding the full path to the 'workon' binary ? Or if it's an alias for something else like virtualenv activate then do os.system('/usr/bin/virtualenv activate cv') ? Commented Aug 2, 2017 at 12:15

2 Answers 2

1

workon is not a program but a shell function from virtualenvwrapper. You cannot call it in a subprocess because it changes the current shell environment.

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

Comments

0

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()

Comments

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.