Last modified: May 28, 2025 By Alexander Williams
Install Python Package from Local Directory
Installing Python packages from a local directory is useful when you need to test or use a package not available on PyPI. This guide will walk you through the process.
Table Of Contents
Prerequisites
Before installing a Python package locally, ensure you have Python and pip installed. Check their versions using the following commands:
python --version
pip --version
If pip is not installed, refer to the official Python documentation for installation instructions.
Step 1: Prepare the Local Package
Ensure your local package has a valid setup.py file. This file defines package metadata and dependencies. Here’s an example:
from setuptools import setup, find_packages
setup(
name="mypackage",
version="0.1",
packages=find_packages(),
)
Save this as setup.py in your package directory.
Step 2: Install the Package Using pip
Navigate to the directory containing your package. Use the following command to install it:
pip install .
The dot (.) tells pip to install the package from the current directory.
Step 3: Verify the Installation
After installation, verify the package is installed correctly:
pip show mypackage
This command displays package details, confirming successful installation.
Alternative: Install from a Compressed File
If your package is in a .tar.gz or .zip file, use this command:
pip install /path/to/package.tar.gz
Replace /path/to/package.tar.gz with the actual file path.
Common Issues and Solutions
If you encounter errors, ensure the setup.py file is correct. Missing dependencies can also cause issues. Install them first.
For more complex packages, refer to guides like How to Install Tkinter in Python or Install Paramiko in Python Easily.
Conclusion
Installing Python packages from a local directory is straightforward. Use pip install .
for directories or pip install /path/to/file.tar.gz
for compressed files. Always verify the installation.
For further reading, check out How to Install PyCrypto in Python.