Last modified: May 28, 2025 By Alexander Williams
Install Python Package from .tar.gz File
Installing Python packages from a .tar.gz file is common. This guide will help you do it easily.
Table Of Contents
What is a .tar.gz File?
A .tar.gz file is a compressed archive. It contains Python package source code. You need to extract and install it.
Prerequisites
Before starting, ensure you have:
- Python installed
- pip installed
- Basic terminal knowledge
Step 1: Download the .tar.gz File
Download the package file from the official source. Save it in a known location.
Step 2: Extract the File
Use the tar
command to extract the file. Open your terminal and run:
tar -xzf package_name.tar.gz
This will extract the contents into a folder.
Step 3: Navigate to the Extracted Folder
Use the cd
command to enter the folder:
cd package_name
Step 4: Install the Package
Run the following command to install the package:
pip install .
This will install the package using setup.py. Learn more about installing with setup.py.
Alternative Method: Direct Installation
You can also install directly from the .tar.gz file. Use this command:
pip install package_name.tar.gz
This method skips manual extraction.
Common Issues and Fixes
Sometimes, you may face errors. Here are common fixes:
- Missing dependencies: Install them first.
- Permission errors: Use
sudo
or virtual environments. - Corrupted file: Re-download the package.
For more on dependencies, see installing with requirements.txt.
Example: Installing a Sample Package
Let's install a sample package step by step.
# Download the package
wget https://example.com/sample_package.tar.gz
# Extract
tar -xzf sample_package.tar.gz
# Navigate
cd sample_package
# Install
pip install .
Output:
Successfully installed sample-package-1.0
Using Virtual Environments
Always use a virtual environment. It keeps your system clean. Learn how in our local directory guide.
Conclusion
Installing Python packages from .tar.gz files is simple. Follow these steps for success. Happy coding!