Set up an isolated, reproducible Python tooling environment on Linux for security scripting — per-engagement virtual environments, pinned dependencies, and a clean system interpreter.
Part of the [[Readme|Python for Security Professionals]] course.
Before writing a single scanner or exploit, a security professional needs a dependable Python setup: a supported Python 3 interpreter, a comfortable editor with a debugger, and — most importantly — isolation so each engagement gets its own pinned toolchain that never pollutes the OS interpreter. This module walks from installing Python through IDE choice, virtual environments, package management, and project layout. The security throughline is reproducibility and isolation: a per-engagement venv with a pinned requirements.txt reruns identically on a retest, and keeps loot, secrets, and dependencies from leaking.
By the end of this module you will be able to:
- Install and verify a supported Python 3 interpreter on Linux.
- Manage multiple interpreter versions with
pyenv. - Choose and configure an IDE with a debugger and the correct interpreter.
- Create, activate, and manage per-project virtual environments.
- Install, pin, and reproduce dependencies with
pipandrequirements.txt. - Lay out a Python project so it can grow into an installable tool.
- A Linux system (Kali, Debian, Ubuntu, Fedora, or similar) with
sudoaccess. - Basic shell familiarity — navigating directories, editing files, running commands.
- No prior Python experience is assumed; this is the first module of the course.
Work through these in order:
- [[Python-Overview|Python Overview]] — why Python for security, the language at a glance
- [[Installing-Python-on-Linux]] — installing and verifying Python 3 across distros
- [[Python-Versions]] — Python 2 vs 3, version selection, checking versions, EOL
- [[Pyenv]] — installing and switching between multiple Python versions
- [[Selecting-an-IDE]] — choosing between VS Code, PyCharm, Jupyter, and terminal editors
- [[VS-Code-Setup]] — VS Code + Python extension, venv selection, debugging
- [[PyCharm-Setup-and-Configuration]] — project interpreter, venv, and debugger config
- [[Jupyter-Notebook-Setup]] — interactive notebooks for analysis and PoC exploration
- [[Managing-Virtual-Environments]] — venv/virtualenv, activate/deactivate, why isolation matters
- [[Pip-Package-Manager]] — pip, pipx, requirements.txt, install/upgrade/freeze
- [[Project-Structure-Best-Practices]] — src layout,
__init__.py, requirements, README, .gitignore
Start with [[Installing-Python-on-Linux]] and [[Python-Versions]] to get a working interpreter, pick and configure an editor, then make [[Managing-Virtual-Environments]] and [[Pip-Package-Manager]] second nature — they underpin every later module. Finish with [[Project-Structure-Best-Practices]] before you begin building real tools.
- Install Python 3 and confirm the version with
python3 --versionandsys.version_info. - Install
pyenvand switch between two interpreter versions in the same shell. - Configure your editor to use a project's virtual environment rather than the system interpreter.
- Create a venv, install
requestsinto it, and confirm the system Python cannot import it. - Freeze the environment to
requirements.txt, delete the venv, and rebuild it from the file. - Lay out a project with a
src/directory,pyproject.toml,README.md, and.gitignore. - Add
.venv/,*.log, and an engagement output directory to.gitignoreand verify withgit status.
- Per-engagement venvs — one isolated environment per client/engagement so toolchains never collide.
- Pinned dependencies — a frozen
requirements.txtmakes scans and exploits reproducible on retest and in CI. - Clean system interpreter — never
sudo pip install; keep the OS Python (and Kali's own tooling) unbroken. - No leaked artifacts —
.gitignorekeeps venvs, secrets, and engagement loot out of version control.
sudo pip install— writes into the system interpreter, can break distribution tooling (Kali ships many Python-based tools), and mixes engagement dependencies into the OS.- Forgetting to activate the venv — packages install globally and the script runs against the wrong interpreter.
- Running
pythoninstead ofpython3— on many systemspythonis absent or points somewhere unexpected. - Committing the virtual environment to version control instead of
requirements.txt. - Unpinned dependencies — a retest months later silently uses different library versions.
- Committing engagement artifacts — loot, scan output, and
.envfiles leaking into a repository. - Editor using the wrong interpreter, so imports resolve in the IDE but fail on the command line.
- One virtual environment per project or engagement; never share one.
- Never use
sudo pip; use a venv, orpipxfor standalone command-line tools. - Pin dependencies with
pip freeze > requirements.txtand commit that file. - Keep
.venv/,__pycache__/,.env, and output directories in.gitignore. - Target Python 3.9 or newer and record the minimum in
pyproject.toml. - Point your editor at the project venv explicitly, and verify with
which python. - Adopt the
src/layout from the start so the project can be packaged later.
- What is the difference between a system-wide package install and a virtual environment install?
- When should you use
pipxrather thanpipinside a venv? - What security issue can occur if engagement output or a
.envfile is committed to a repository? - How would you troubleshoot a script that imports a package successfully in your IDE but fails from the terminal?
- Why is
sudo pip installparticularly risky on Kali Linux? - Write the commands to create a venv, install a package, and freeze the dependency list.
# Verify the interpreter
python3 --version
which python3
python3 -c "import sys; print(sys.version_info[:3])"
# Create and activate a per-project virtual environment
python3 -m venv .venv
source .venv/bin/activate
which python # should now point inside .venv
# Install and pin dependencies
python3 -m pip install --upgrade pip
python3 -m pip install requests
python3 -m pip freeze > requirements.txt
# Rebuild the environment elsewhere
python3 -m pip install -r requirements.txt
# Leave the environment
deactivate- Python docs —
venv - Python docs — Installing Python Modules
- Python Packaging User Guide
- pyenv — simple Python version management
- pipx documentation
- [[Python-Overview|Python Overview]]
- [[Readme|Python for Security Professionals]] — course home
- Home: [[Readme|Course Home]]
- Next: [[Python-Objects-and-Data-Structure-Basics/Readme|2. Python Objects & Data Structure Basics]]