Skip to main content
  1. Errors/

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

194 words·1 min
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

Related

Awesome Command Line
416 words·2 mins
command
View Listening Ports # ss -tulnp | grep <port_number> Format Json # Unformatted json data
MySQL Error
45 words·1 min
MySQL
utf8mb4 # XShelll 数据库查询,中文变成问号
Setting up SSH tunnel
60 words·1 min
ssh
Error 提示 # VSCode remote ssh 连接服务器,卡在> Setting up SSH Host xx;:Setting up SSH tunnel
git commit & push failed
50 words·1 min
Git
git push 延迟问题 # 清除本地缓存。重新提交上传
Upgrade openssh version 9.0 on centos7
200 words·1 min
Linux
Upgrade OpenSSH to 9.