How to Install the wget Package for File Downloads in Python
Learn how to resolve the ModuleNotFoundError and install the Python wget package using pip or conda for downloading files in scripts, IDEs, and notebooks.
The wget Python package provides a simple way to download files from the web, inspired by the command-line GNU Wget utility. It allows you to fetch files via HTTP, HTTPS, or FTP directly within your Python scripts. If you try to import wget without first installing the package, or if it's installed in a different Python environment than your script is using, you'll encounter the ModuleNotFoundError: No module named 'wget'.
This guide provides comprehensive instructions on how to install the wget package using pip and conda across various platforms and IDEs, and how to troubleshoot the ModuleNotFoundError.
What is the Python wget Package?
The Python wget package is a third-party library that simplifies the process of downloading files from web URLs. It's not the same as the GNU Wget command-line utility but offers similar functionality within a Python script. You can use it to download files and optionally display progress bars.
Solving ModuleNotFoundError: No module named 'wget'
This error means Python's import system cannot locate the wget package in its current search paths.
Cause: Package Not Installed or Incorrect Environment
The most common reasons are:
You haven't installed the wget Python package yet.
You installed wget in a different Python environment (e.g., global Python) than the one your current script or IDE is using (e.g., a virtual environment).
Solution: Install wget using Pip or Conda (Primary Methods)
Using pip (Standard Python Package Installer):
Open your terminal or command prompt. If using a virtual environment, ensure it's activated.
Using conda (If using Anaconda/Miniconda):wget is often available from the default Anaconda channel or conda-forge.
conda install -c anaconda wget
After successful installation, your import wget statement should work.
import wgettry: url = 'http://www.futurecrew.com/skaven/song_files/mp3/razorback.mp3' # Example URL print(f"Attempting to download from {url}...") filename = wget.download(url) print(f"Downloaded file: {filename}")except Exception as e: print(f"An error occurred during download: {e}")
Platform-Specific Installation Instructions
The core installation command is usually pip install wget or conda install ... wget, but accessing the terminal varies.
Windows (Command Prompt / PowerShell)
Open Command Prompt (type cmd in search) or PowerShell.
Run:
pip install wget
For global installs with permission issues (not recommended), run as Administrator or use pip install wget --user. Virtual environments are preferred.
macOS / Linux (Terminal)
Open your Terminal application.
Run:
pip3 install wget # Usually best for Python 3
For global installs with permission issues (not recommended), use sudo pip3 install wget or pip3 install wget --user. Virtual environments are strongly preferred.
IDE and Notebook Specific Installation
Visual Studio Code (Integrated Terminal)
Open the integrated terminal (Ctrl+` or View -> Terminal).
Ensure the correct Python interpreter (especially your virtual environment's) is selected for your workspace. VS Code shows this in the bottom status bar.
Run: pip install wget
PyCharm (Terminal / Package Manager GUI)
Terminal: Open the Terminal tool window (Alt+F12). Ensure it's using your project's configured interpreter. Run: pip install wget.
Click the + icon. Search for wget. Select it and click "Install Package".
Anaconda / Conda Environments
Open Anaconda Prompt or your terminal (with Conda in PATH).
Activate your target environment: conda activate your_env_name
Install using conda or pip within the conda environment:
conda install -c anaconda wget # Check if available on default/anaconda channel
Jupyter Notebook / Lab
Method 1 (Recommended - Install Before Starting): Activate the correct Python environment (venv or conda) in your terminal, run pip install wget (or conda install ...), then start Jupyter.
The ModuleNotFoundError: No module named 'wget' typically means the Python wget package is not installed in the active Python environment or there's a configuration issue.
The primary solution is to install wget using pip or conda:
pip install wgetconda install -c anaconda wget
Crucially, ensure this installation happens within the correct, active Python environment, preferably an isolated virtual environment. If issues persist, meticulously verify your Python/pip paths, IDE interpreter settings, and ensure no local files or variables are shadowing the wget package name.