Skip to main content

Running pip as the 'root' user can result in broken permissions

python

The warning you’re seeing is advising against using pip as the ‘root’ user. This is because installing Python packages as root can potentially overwrite or affect system files, leading to permission issues and conflicts with the system package manager.

A recommended practice is to use a virtual environment, which is a self-contained Python environment. This allows you to install Python packages in an isolated location for a specific project, rather than globally, which can help avoid conflicts between packages and versions.

Here’s how you can create a virtual environment:

  1. First, install the virtualenv package using pip:
pip install virtualenv
  1. Navigate to your project directory and create a virtual environment. Replace myenv with the name you want to give to your virtual environment:
virtualenv myenv
  1. Activate the virtual environment:

    • On Windows:
    myenv\Scripts\activate
    
    • On Unix or MacOS:
    source myenv/bin/activate
    
  2. Now, when you use pip to install packages, they will be installed in the virtual environment, not globally. To confirm this, you can use the which command (or where on Windows) to see the location of Python and pip:

which python
which pip
  1. When you’re done working on your project, you can deactivate the virtual environment:
deactivate