JIYIK CN >

Current Location:Home > Learning > OPERATING SYSTEM >

Installing Python modules without root access

Author:JIYIK Last Updated:2025/04/06 Views:

Use --userthe -p option to install Python modules without root access, for example pip install requests --user. --userThe -p option installs the package in the user's home directory and helps resolve permission issues.

$ pip install requests --user
$ pip3 install requests --user

$ python -m pip install requests --user
$ python3 -m pip install requests --user

Make sure to requestsreplace <package> with the name of the package we are trying to install.

--useroption to install the package in the user's home directory.

This command basically installs the package scoped to a particular user instead of the entire system. This helps in resolving permission issues.

If the system's PATH environment variable is not available pip, use the user's python -m.

$ python -m pip install requests --user
$ python3 -m pip install requests --user

If we don’t have it installed pip, install it using the following command.

$ wget --no-check-certificate https://bootstrap.pypa.io/get-pip.py && python get-pip.py --user

This command uses the official get-pipscript.

We can also https://bootstrap.pypa.io/get-pip.pyinstall pip by downloading the script from:

  1. Click on the link.
  2. Right-click and select "Save As" in your browser.
  3. get-pip.pyOpen a terminal at the location where you downloaded the file and run the following command.
# 👇️  Linux 或者 MacOS
$ python get-pip.py --user

# 👇️ 使用 python 3
$ python3 get-pip.py --user

# 👇️  Windows
$ py get-pip.py --user

get-pip.pyThe script uses the bootstrap logic to install pip.

Now, we can pip install <package-name> --userinstall modules without root access using the command.

Alternatively, we can use a virtual environment.


Installing Python modules without root access using a virtual environment

To install Python modules without root access:

  1. Create a virtual environment.
  2. Activate the virtual environment.
  3. Run the command while the virtual environment is active pip install.
# 👇️ 创建 VENV 时使用正确版本的 Python
$ python3 -m venv venv

# 👇️ 在 Unix 或 MacOS 上激活
$ source venv/bin/activate

# 👇️ 在 Windows 上激活 (cmd.exe)
$ venv\Scripts\activate.bat

# 👇️ 在 Windows 上激活 (PowerShell)
$ venv\Scripts\Activate.ps1

# 👇️ 在虚拟环境中安装特定的包
$ pip install requests

Make sure to use the correct command to activate our virtual environment, depending on our operating system and shell.

Our virtual environment will use the version of Python used to create it.

Creating a virtual environment and installing the package in it can help, because a virtual environment is an isolated Python installation.

We will not face permission issues because no packages are installed globally.

Instead, the packages are installed in the virtual environment's lib folder.

For reprinting, please send an email to 1244347461@qq.com for approval. After obtaining the author's consent, kindly include the source as a link.

Article URL:

Related Articles

Solve Python3 command not found error in Bash

Publish Date:2025/03/20 Views:116 Category:OPERATING SYSTEM

Python is a high-level, general-purpose programming language. It has two major versions, Python 2.x and Python 3.x. This article will explain how to install Python 3 and resolve errors in Linux Bash bash: python3: command not found . Instal

Introduction to Python Network Programming

Publish Date:2025/03/17 Views:176 Category:NETWORK

This tutorial will introduce sockets in Python and how to use the socket module to build HTTP servers and clients in Python. It will also cover Tornado, a Python networking library that is ideal for long polling, WebSockets, and other networking scena

Pandas 重命名多个列

Publish Date:2024/04/22 Views:200 Category:Python

本教程演示了如何使用 Pandas 重命名数据框中的多个列。

Scan to Read All Tech Tutorials

Social Media
  • https://www.github.com/onmpw
  • qq:1244347461

Recommended

Tags

Scan the Code
Easier Access Tutorial