Many times we do not have root privileges on Linux servers, the key is that there is no pip yet, and the necessary third package cannot be installed. At this time, you need to install pip and third-party packages in a non-root way.
install pip
wget https://bootstrap.pypa.io/get-pip.py
python get-pip.py --user
If the python in the environment is 2.7, install pip2, and if it is 3, install pip3.
Be sure to add --user
options, otherwise there will be no permissions.
After the installation is complete, a .local
folder will be generated in the home directory, which contains bin and lib, and the bin contains the pip and easy_install we need.
If you want to use it directly, add bin to the PATH
environment variable:
export PATH=~/.local/bin:$PATH
install other packages
With pip, you can easily install other packages
pip install --user virtualenv #包名称
In this way, the packages you need will be installed under the ~/.local directory, so you also need to add --user
options, otherwise the installation will not be successful.
virtual environment virtualenv
Many times different projects require different versions of packages, and sometimes the packages that you don’t want to install are too messy. At this time, we can use virtualenv to make an independent ecosystem, and we can install the packages needed in this system in different virtualenvs without Influence each other.
# 安装virtualenv
pip install --user virtualenv
# 建立虚拟环境env
virtualenv env #在当前目录会多一个env目录
#进入这个虚拟环境
sourece env/bin/activate
# 退出env这个虚拟环境
deactivate
Each virtual environment will create a directory with its own name, and then there will be packages installed under this directory. We can create folders of different virtual environments through the above commands, and then enter and leave different virtual environments to develop projects for different purposes.