Should I install virtualenv with sudo or not?

1311 views python

I have installed pip and pip3 with sudo in my machine. I am new to python and its entire world of virtual environments, hence I am not sure if I should install virtualenv with sudo or not. virtualenv's website isn't clear about it. It states says: [sudo] pip install virtualenv, as if it was optional.

answered question

1 Answer


You only need sudo if you are installing virtualenv into a system Python and your current account can't write into the site-packages directory for that Python install.

You can test with pip -V or with python -m site to see where the python binary looks for packages, and look for the .../site-packages directory. If you can't write in that directory with your current account, you need sudo.

You can also use pip install --user virtualenv to install it only for your own account even with a system-installed Python setup. The virtualenv script is then installed into ~/.local/bin, make sure to include that path into your PATH environment variable, or just use python -m virtualenv as the command-line tool alternative.

posted this

Have an answer?


Please login first before posting an answer.