Module Installation#

How to install Python packages in different scenarios.

1. Set Proxy#

If you are behind a corporate proxy, configure it before installing packages:

Windows (CMD):

SET HTTPS_PROXY=http://username:password@proxy.example.com:8080
SET HTTP_PROXY=http://username:password@proxy.example.com:8080

Windows (PowerShell):

$env:HTTPS_PROXY = "http://username:password@proxy.example.com:8080"
$env:HTTP_PROXY = "http://username:password@proxy.example.com:8080"

Linux / macOS:

export HTTPS_PROXY=http://username:password@proxy.example.com:8080
export HTTP_PROXY=http://username:password@proxy.example.com:8080

Permanent pip configuration (create or edit pip.ini on Windows or pip.conf on Linux):

[global]
proxy = http://username:password@proxy.example.com:8080

Location:

  • Windows: %APPDATA%\pip\pip.ini

  • Linux: ~/.config/pip/pip.conf

2. Activate Python#

Before installing, make sure the correct Python environment is active.

System Python:

python --version

Virtual environment (venv):

# Create
python -m venv .venv

# Activate (Windows)
.venv\Scripts\activate

# Activate (Linux/macOS)
source .venv/bin/activate

Conda environment:

conda activate myenv

3. Installation Methods#

3a. Via pip (online)#

The standard method for installing packages from PyPI:

pip install numpy
pip install numpy==1.26.4        # specific version
pip install numpy>=1.25,<2.0     # version range
pip install -r requirements.txt  # from a file

Useful options:

pip install --upgrade numpy      # upgrade to latest
pip install --user numpy         # install for current user only
pip list                         # list installed packages
pip show numpy                   # show package info

3b. Using pip + git#

Install directly from a Git repository:

# From the main branch
pip install git+https://github.com/user/repo.git

# From a specific branch
pip install git+https://github.com/user/repo.git@branch-name

# From a specific tag/release
pip install git+https://github.com/user/repo.git@v1.2.3

3c. Cloning a git repository#

For packages not on PyPI, or when you need to modify the source:

git clone https://github.com/user/repo.git
cd repo
pip install .

For development mode (changes to the source are immediately available):

pip install -e .

3d. Using wheel files (.whl)#

Pre-built binary packages, useful when pip cannot compile from source. A good repository for Windows wheels:

pip install C:\Downloads\GDAL-3.8.4-cp312-cp312-win_amd64.whl

Note

Wheel filenames encode compatibility info: {package}-{version}-{python}-{abi}-{platform}.whl. Make sure the Python version (cp312 = Python 3.12) and platform (win_amd64) match your environment.

3e. Using zip/tar files#

For packages distributed as source archives:

# Download and extract the archive, then:
cd package-folder
pip install .

Or directly without extracting:

pip install package-1.0.tar.gz
pip install package-1.0.zip

Legacy method (still works but pip is preferred):

cd package-folder
python setup.py install

Verify Installation#

>>> import numpy
>>> numpy.__version__
'1.26.4'
>>> numpy.__file__
'C:\\Python312\\Lib\\site-packages\\numpy\\__init__.py'