1

I need to run a python script as sudo inside a virtualenv. However, running sudo python will run the global python interpreter and not the one from the virtualenv.

Is there a way to do that?

2
  • Why do you need sudo? Commented Nov 28, 2018 at 19:16
  • 1
    the python script in general does not need sudo, but there is a library used that needs sudo to run some system commands. Commented Nov 28, 2018 at 19:22

1 Answer 1

1

Just specify the absolute path to the interpreter. Which you can discover by running, as normal user:

python -c "import sys; print(sys.executable)"

The "activation" of a virtualenv is nothing more sophisticated than a hack to PATH.

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

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.