Just got back to Debian Linux after years not using it. I have a very personal use custom package of tools that I want to install to use to import into my Python scripts. On Win11, I just added the package to site-packages and boom done and usable. Not so on Debian 12.11. It's not in a repo, so I can't apt-get install it. How do I go about this?
If you're returning to Debian and trying to use a custom Python package that isn't available via apt
or PyPI, there are several clean and proper ways to make it importable system-wide or locally. Here's how to do it correctly:
pip install -e .
)This is ideal if you're actively developing or modifying the package.
Make sure python3-pip
is installed:
sudo apt update
sudo apt install python3-pip
Navigate to your package root directory (where setup.py
is):
cd /path/to/your/custom-package
Install the package in editable mode:
pip install -e .
Now, you can freely import the package from any Python script.
✅ Requires a valid
setup.py
orpyproject.toml
.
To avoid affecting system-wide packages:
pip install --user .
This installs your package into ~/.local/lib/pythonX.Y/site-packages
, which is already in Python’s search path.
If you're sure this package should be available globally:
sudo pip install .
⚠️ Avoid unless necessary — can interfere with system tools relying on specific versions of libraries.
PYTHONPATH
For fast testing without installation:
export PYTHONPATH=/path/to/your/package:$PYTHONPATH
To persist across sessions, add it to your shell config:
echo 'export PYTHONPATH=/path/to/your/package:$PYTHONPATH' >> ~/.bashrc
source ~/.bashrc
❌ Not ideal for long-term usage; better for quick tests.
setup.py
TemplateIf your package lacks a setup.py
, create one at the root of your project:
from setuptools import setup, find_packages
setup(
name='your_custom_package',
version='0.1',
packages=find_packages(),
)
Then run:
pip install -e .
Open a Python shell and try importing your module:
import your_custom_package
No errors? You're all set!
Use virtual environments for isolated development:
python3 -m venv ~/myenv
source ~/myenv/bin/activate
pip install -e .
Prefer --user
or virtual environments over global installs.
Always consider packaging your code properly with setup.py
or pyproject.toml
.