Installing Python modules without root access
Use --user
the -p option to install Python modules without root access, for example pip install requests --user
. --user
The -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 requests
replace <package> with the name of the package we are trying to install.
--user
option 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-pip
script.
We can also https://bootstrap.pypa.io/get-pip.py
install pip by downloading the script from:
- Click on the link.
- Right-click and select "Save As" in your browser.
get-pip.py
Open 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.py
The script uses the bootstrap logic to install pip.
Now, we can pip install <package-name> --user
install 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:
- Create a virtual environment.
- Activate the virtual environment.
-
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.
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
Python pandas.pivot_table() 函数
Publish Date:2024/04/24 Views:84 Category:Python
-
Python Pandas pivot_table()函数通过对数据进行汇总,避免了数据的重复。
在 Python 中将 Pandas 系列的日期时间转换为字符串
Publish Date:2024/04/24 Views:920 Category:Python
-
了解如何在 Python 中将 Pandas 系列日期时间转换为字符串
在 Python Pandas 中使用 str.split 将字符串拆分为两个列表列
Publish Date:2024/04/24 Views:1147 Category:Python
-
本教程介绍如何使用 pandas str.split() 函数将字符串拆分为两个列表列。
在 Pandas 中将 Timedelta 转换为 Int
Publish Date:2024/04/23 Views:232 Category:Python
-
可以使用 Pandas 中的 dt 属性将 timedelta 转换为整数。
Python 中的 Pandas 插入方法
Publish Date:2024/04/23 Views:113 Category:Python
-
本教程介绍了如何在 Pandas DataFrame 中使用 insert 方法在 DataFrame 中插入一列。
使用 Python 将 Pandas DataFrame 保存为 HTML
Publish Date:2024/04/21 Views:108 Category:Python
-
本教程演示如何将 Pandas DataFrame 转换为 Python 中的 HTML 表格。