Python is a high-level, interpreted programming language widely used in various fields. When working with Python, there are a few key concepts you should understand:
1. Virtual Environment: A virtual environment is an isolated workspace for Python projects. It allows you to manage dependencies for your project without interfering with the global Python installation or other projects. venv is the name of the stdlib module that creates one of the possible kinds of virtual environment — see the Virtual Environments chapter for the other options (Conda, uv).
2. Interpreter: The Python interpreter is the program that reads and executes Python code. Depending on your setup, the interpreter could refer to the system Python, a version you installed manually, or one inside a virtual environment.
3. Script: A script is a standalone Python file (with a .py extension) designed to perform a specific task when executed.
4. Jupyter Notebook: A Jupyter Notebook is an interactive web-based Python environment (with a .ipynb extension). Jupyter Notebooks are divided into cells, which can contain different types of content like Python code, Markdown text, Shell commands etc. Each cell runs independently, but variables persist throughout the notebook session. Cells can be run in any order, but dependencies between them must be managed carefully.
5. Module: A module is a Python file that contains reusable code, such as functions or classes, which can be imported into other Python files.
6. Package: A package is a collection of modules organized into a directory structure.
Below is a table summarizing essential Python commands and their differences across macOS, Linux, and Windows:
| Purpose | macOS | Linux | Windows |
|---|---|---|---|
| Check installed Python version | python3 --version or python3 -V |
python3 --version or python3 -V |
py --version |
| Find the path of the active Python interpreter | which python3 |
which python3 |
where python |
| Locate all installed paths of Python 3 | which -a python3 |
which -a python3 |
where python |
| Run a Python script | python3 your_script.py |
python3 your_script.py |
py your_script.py |
Note:
whereis a Windows command; on macOS/Linux the shell builtinwhereonly exists inzsh, notbash. Usewhich -a(works in both) to list every match on thePATH.
Python 2 and Python 3 are distinct versions of the Python programming language, with Python 3 being the latest and actively supported version. Here are the key differences and considerations:
- Python 2: Use the command
python2to access Python 2 (if installed). - Python 3: Use the command
python3to access Python 3.
On modern systems python might not be available. To ensure compatibility, always specify python3 when working with Python 3.
- macOS and Linux systems often include a system-managed version of Python for internal operations (e.g., Python 2.x or 3.x). Do not modify or remove it — the OS itself (package managers, system scripts) may depend on it. See the
⚠️ system Python warning below.
To check the version of Python installed:
- For Python 2:
python2 --version - For Python 3:
python3 --version
If you want python to refer to Python 3, you can create an alias in your shell configuration file (e.g., ~/.bashrc or ~/.zshrc):
alias python='python3'After adding this, apply the changes by restarting the terminal or running:
source ~/.zshrc # or source ~/.bashrc, matching whichever file you editedBe cautious with this change, as some older scripts may require python to refer to Python 2. Personally, I don't suggest to do that.
It is recommended to avoid using the system Python for development. Instead, install a separate version of Python to avoid conflicts. Python can be installed on macOS, Linux, and Windows using different methods.
- Visit python.org/downloads.
- Download the macOS installer for the desired Python version.
- Follow the installation prompts.
- After installation, verify with:
python3 --version
- Ensure Homebrew is installed. If not, install it:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" - Install Python:
brew install python
- Verify installation:
python3 --version
- Update the package manager and install Python, along with
venvandpip(on Debian/Ubuntu these are separate packages, not bundled withpython3):sudo apt update sudo apt install python3 python3-venv python3-pip
- Verify installation:
python3 --version
Note: to install a specific Python version not shipped by your distro (e.g. a newer release on an older Ubuntu LTS), use the deadsnakes PPA:
sudo add-apt-repository ppa:deadsnakes/ppa, thensudo apt install python3.12 python3.12-venv.
- Download the source code from python.org.
- Extract the archive and compile Python:
tar -xvzf Python-<version>.tgz cd Python-<version> ./configure --enable-optimizations make -j "$(nproc)" sudo make altinstall
- Verify installation:
python3.x --version
⚠️ Never runsudo make installhere — it overwrites the system's own/usr/bin/python3, which the OS package manager and system scripts depend on. Always usemake altinstall, which installs aspython3.xwithout touching the system binary.
- Visit python.org/downloads.
- Download the Windows installer for the desired Python version.
- During installation, select "Add Python to PATH."
- Verify installation:
py --version
- Open the Microsoft Store and search for "Python."
- Select and install the desired Python version.
- Verify installation:
py --version
Python includes pip, the default package installer, which simplifies the process of managing additional libraries and dependencies. Typically, pip is installed alongside Python, but if it's missing, you can install it manually:
To install pip, download and run the get-pip.py script from the official site:
curl -O https://bootstrap.pypa.io/get-pip.py
python3 get-pip.pyor try:
python3 -m ensurepip --upgradeNote: on Debian/Ubuntu,
ensurepipmay be stripped from the system Python; in that case use theapt install python3-piproute shown above instead.
Here are some commonly used pip commands to manage Python packages:
| Command | Purpose |
|---|---|
pip3 --version or pip3 -V |
Check the installed version of pip. |
pip3 list |
List all installed Python packages. |
pip3 install <package_name> |
Install a specific Python package. |
pip3 uninstall <package_name> |
Uninstall a specific Python package. |
pip3 show <package_name> |
Show detailed information about a package. |
pip3 install --upgrade pip |
Upgrade pip to the latest version. |
which pip3 |
Locate the pip3 executable path (macOS/Linux). |
where pip3 |
Locate the pip3 executable path (Windows). |
- Avoid using the system-installed Python for development (macOS and Linux already come with a Python interpreter used by the operating system), as it may conflict with system operations.
- If managing multiple projects with different package versions, consider using virtual environments to isolate dependencies. When a package is installed, it will be stored alongside the Python interpreter, unless a virtual environment is created and activated first.
- Inside an activated virtual environment, use the plain
python/pipcommands (no3suffix needed) — the environment's own interpreter is already the one onPATH.pipships bundled with everyvenv/uvenvironment automatically; there's no separate install step.
If you installed Python using the Python.org installer, manually remove it:
sudo rm -rf /Library/Frameworks/Python.framework/Versions/<your_version>Check for symlinks:
ls -l /usr/local/bin | grep pythonRemove symlinks:
sudo rm -f /usr/local/bin/python3.13
sudo rm -f /usr/local/bin/python3
sudo rm -f /usr/local/bin/pip3Verify removal:
python3 --version
which -a python3List installed Python versions:
brew list | grep pythonUninstall:
brew uninstall python@<version>Remove remaining symlinks:
rm -f /usr/local/bin/python3
rm -f /usr/local/bin/pip3Check if installed in /opt/homebrew/bin:
rm -f /opt/homebrew/bin/python3
rm -f /opt/homebrew/bin/pip3Verify:
brew list | grep python
python3 --version
which -a python3If installed via the Python.org installer:
- Open Control Panel ➡️ Programs ➡️ Programs and Features.
- Locate Python X.X.
- Click Uninstall.
Alternatively, remove it via PowerShell/cmd:
winget uninstall Python.Python.3.xCheck Python installation path:
where.exe pythonManually remove folders (if necessary):
Remove-Item -Recurse -Force "C:\Users\<YourUsername>\AppData\Local\Programs\Python"
Remove-Item -Recurse -Force "C:\Program Files\Python*"Note:
wherealone is a PowerShell alias forWhere-Object, not the file-finder — usewhere.exeexplicitly, orGet-Command pythonas a PowerShell-native alternative.
⚠️ Warning: these commands only apply to a Python version you installed yourself (e.g. via deadsnakes,pyenv, or from source). Never runapt remove/purgeon the distro's ownpython3package (usually the lowest version number, e.g.python3.x-minimalor matching your OS's default) —aptand many system scripts are themselves written in Python and depend on it. Removing it can break your package manager and require a system reinstall.
For Debian-based systems (Ubuntu, Debian), removing a version installed from deadsnakes/PPA:
sudo apt-get remove --purge python3.x
sudo apt autoremoveFor Red Hat-based systems (Fedora, CentOS):
sudo dnf remove python3.xCheck if Python is still installed:
python3 --version
which -a python3For a single one-off switch, you can prepend the desired version's directory to PATH (macOS/Linux):
export PATH="/usr/local/opt/python@3.9/bin:$PATH"The path must point to the directory containing the
python3binary, not to the binary itself — otherwisePATHresolution silently fails and the old version keeps being used.
Apply changes:
source ~/.zshrc # or source ~/.bashrcVerify the change:
python3 --versionOn Windows, modify the system environment variables:
- Search "Environment Variables".
- Edit PATH and move the desired Python version's folder to the top.
- Restart the terminal and check with:
python --version💡 Better approach: manually juggling
PATHdoesn't scale past two versions and is easy to get wrong. For managing several Python versions side by side, use a dedicated version manager instead —pyenv(macOS/Linux) oruv python install <version>/uv python pin <version>(cross-platform, see the uv workflow below), which let you install multiple versions and switch per-project without touchingPATHby hand.
Virtual environments allow you to create isolated Python environments for projects, ensuring that dependencies do not conflict with each other or with the system Python installation. This is especially useful when working on multiple projects with different package requirements.
There are three common tools to create them. They solve the same problem with different tradeoffs — pick one per project, don't mix them in the same project.
venv + pip |
Conda | uv | |
|---|---|---|---|
| Extra install needed | None (Python stdlib) | Miniconda/Anaconda (~400 MB+) | one-line install script |
| Can install Python itself | ❌ (needs a Python already present) | ✅ | ✅ |
| Non-Python binary deps (CUDA, GDAL, ITK, MKL) | ❌ | ✅ (its whole reason to exist) | ❌ |
| Lockfile for reproducibility | manual (pip freeze) |
conda env export |
✅ automatic uv.lock |
| Speed (create env / install) | baseline | slow | 10–100× faster than pip |
| Best for | simple pure-Python projects, quick scripts | Data Science / Deep Learning stacks needing compiled non-Python libraries | new projects, CI, anything where speed and reproducibility matter |
The same seven actions, one row per tool — use this as a cheat sheet once you've picked one:
| Step | venv + pip |
Conda | uv |
|---|---|---|---|
| 1. Create | python3 -m venv .venv |
conda create -n myenv python=3.12 |
uv venv --python 3.12 (or uv init for a full project) |
| 2. Activate | source .venv/bin/activate |
conda activate myenv |
source .venv/bin/activate |
| 3. Install a package | pip install numpy |
conda install -c conda-forge numpy |
uv add numpy |
| 4. Record dependencies | pip freeze > requirements.txt (or pipreqs ., see Deploying Python Code) |
conda env export --from-history > environment.yaml |
automatic — written to uv.lock on every uv add |
| 5. Reproduce elsewhere | pip install -r requirements.txt |
conda env create -f environment.yaml |
uv sync |
| 6. Run code | python script.py |
python script.py |
uv run script.py (no activation needed) |
| 7. Delete | rm -rf .venv |
conda env remove -n myenv |
rm -rf .venv |
Convention: name
venv/uvfolders.venv(leading dot). It's the tool-standard name auto-detected by VS Code, PyCharm, anduvitself, and is easy to exclude with a single.gitignoreline. Conda environments aren't project folders — they live in a central location and are addressed by--name, so this convention doesn't apply to them.
Navigate to your project directory and create the environment:
python3 -m venv .venvFor a specific Python version:
python3.x -m venv .venvNote: you can search for any
venv/uvenvironment on your computer withfind ~ -name "pyvenv.cfg" 2>/dev/null— it will output all the paths topyvenv.cfgfiles, marking everyvenv-style folder on your device (uvenvironments also produce this file). It does not include system interpreters or Conda environments, which use a different layout.
To use the virtual environment, activate it:
- macOS/Linux:
source .venv/bin/activate - Windows (PowerShell):
.\.venv\Scripts\Activate.ps1
If this fails with a script-execution error, PowerShell's execution policy is blocking it. Run once per user:
Set-ExecutionPolicy -Scope CurrentUser RemoteSigned. - Windows (cmd.exe):
.\.venv\Scripts\activate.bat
Once activated, the terminal prompt will change to include the name of the virtual environment (e.g., (.venv)):
(.venv) user@machine:~$With the virtual environment activated, you can use pip to install packages. All the packages will be stored inside the active environment and they will not be visible from the other virtual environments:
pip install <package_name>When you are done working, deactivate the environment:
deactivateThis returns the terminal to the global environment.
Anaconda and Miniconda are the two common Conda distributions.
- Anaconda: A larger distribution that includes Python, conda, and many pre-installed data science libraries.
- Miniconda: A minimal installation that includes Python and conda, with fewer pre-installed libraries, providing more flexibility.
Reach for Conda specifically when your project needs non-Python binary dependencies (CUDA toolkits, GDAL, compiled scientific libraries) that pip can't build for you.
macOS/Linux:
-
Download the miniconda installer:
# Linux wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh # macOS (Apple Silicon) curl -O https://repo.anaconda.com/miniconda/Miniconda3-latest-MacOSX-arm64.sh # macOS (Intel) curl -O https://repo.anaconda.com/miniconda/Miniconda3-latest-MacOSX-x86_64.sh
To download a different version check here and use:
# Replace <FILENAME> with the installer Filename you copied from the archive curl -O https://repo.anaconda.com/miniconda/<FILENAME>
-
Check file integrity:
# Linux sha256sum <FILE_NAME> # macOS shasum -a 256 <FILE_NAME>
Compare the hash value you see with the value here. Remember to verify the hash corresponding to your downloaded miniconda version.
-
Install miniconda:
bash ~/Miniconda3-latest-<platform>.sh
Follow the instruction by pressing
Enterand writeyes. -
Apply modifications: Close and re-open your terminal window for the installation to fully take effect, or use the following command to refresh the terminal:
# Bash shell (Linux) source ~/.bashrc # Zsh shell (macOS) source ~/.zshrc
More about the procedure for different systems and shells here.
Windows:
- Download the installer from the official site.
- Run the installer and follow the instructions.
- Anaconda recommends against adding conda to the system PATH during install (it can conflict with other software); use the "Anaconda Prompt" it creates instead, or run
conda initafterward from that prompt if you want conda available in your regular terminal.
- Create a directory for Miniconda:
mkdir -p ~/miniconda3 - Download the Miniconda installer and save it as specified:
wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh -O ~/miniconda3/miniconda.sh - Execute the script in non-interactive mode, updating an existing install if one is already there, with install prefix (target directory) set to
~/miniconda3:bash ~/miniconda3/miniconda.sh -b -u -p ~/miniconda3
- Remove the installer:
rm -rf ~/miniconda3/miniconda.sh - Register conda with your shell (edits
~/.bashrc/~/.zshrc— still requires reopening the terminal orsource-ing the file to take effect):~/miniconda3/bin/conda init bash # or: conda init zsh
| Purpose | Command | Description |
|---|---|---|
| Create an environment | conda create --name myenv or conda create --name myenv python=3.12 |
Creates a new environment named myenv. python=, no Python interpreter is installed in it at all — always specify a version. |
| Activate an environment | conda activate myenv |
Activates the environment myenv. |
| Deactivate an environment | conda deactivate |
Deactivates the currently active environment. |
| Remove an environment | conda env remove --name myenv |
Deletes the environment myenv completely. |
| Install a package | conda install -c conda-forge <package_name> |
Installs a specific package into the active environment (conda-forge has broader, more current coverage than the defaults channel). |
| Check conda version | conda --version |
Displays the currently installed version of conda. |
| List installed packages | conda list |
Lists all packages installed in the active environment. |
| List all environments | conda env list |
Displays all available environments and their locations. |
pipalready ships inside every Conda environment that specifiespython=, no separateconda install pipstep needed in that case.
By default, the base environment in Conda is activated whenever you open a new terminal.
(base) user@machine:~$Here are commands to manage this behavior:
-
Prevent Conda Base Activation by Default: To prevent the
baseenvironment from being activated automatically:conda config --set auto_activate_base falseThis ensures that Conda doesn't activate the
baseenvironment automatically in new terminals. -
Show or Hide the
(base)Prefix: You can customize whether the(base)prefix appears in your terminal prompt. To hide the prefix:conda config --set changeps1 falseTo show the prefix:
conda config --set changeps1 true
uv is a newer, Rust-based tool from Astral that replaces the combination of pyenv + venv + pip + pip-tools with a single, much faster binary. It manages Python versions, virtual environments, and dependencies with an automatic lockfile.
# macOS/Linux
curl -LsSf https://astral.sh/uv/install.sh | sh
# macOS (Homebrew alternative)
brew install uv# Windows (PowerShell)
powershell -ExecutionPolicy ByPass -c "irm https://astral.sh/uv/install.ps1 | iex"uv can download and manage Python interpreters itself — no separate pyenv needed:
uv python install 3.12 # download and install a Python version
uv python list # list installed/available versions
uv python pin 3.12 # pin the version for the current projectuv init my_project # scaffolds pyproject.toml, .python-version, .venv/
cd my_projectThis creates a pyproject.toml — the modern, PEP 621 config file that replaces requirements.txt as the source of truth for dependencies (see also PyPI-Guide.md §5 for packaging with pyproject.toml).
For an existing project, uv venv alone just creates a bare .venv without the project scaffolding.
uv add numpy # adds to pyproject.toml, updates uv.lock, installs it
uv add --dev pytest # dev-only dependency
uv remove numpy # removes it from both files
uv sync # installs exactly what uv.lock specifies (reproducible)uv run script.py # runs inside the project's env — no manual activation needed
uv run python # drop into a REPL with the project's envuv run transparently syncs the environment to match the lockfile before every run, so it's always in sync — you don't have to remember to uv sync yourself.
uvx ruff check . # run a tool in a throwaway env, without installing it into your projectuvx is uv's equivalent of pipx.
If you're not ready to move to pyproject.toml, uv also offers a drop-in faster replacement for the classic pip workflow:
uv venv .venv # same as python3 -m venv .venv, much faster
source .venv/bin/activate
uv pip install -r requirements.txt # same as pip install -r requirements.txt
uv pip compile requirements.in -o requirements.txt # pip-tools-style lockfile generation- Dependency Management: Avoid conflicts between dependencies required by different projects.
- Isolation: Prevent system-wide changes by containing all packages within the virtual environment.
- Reproducibility: Simplify sharing and collaboration for others to recreate the environment.
By using virtual environments, you maintain clean and organized project setups, reducing the risk of dependency issues.
When sharing or deploying Python projects, it is essential to specify dependencies. This ensures that anyone using the code has the correct libraries installed. This chapter covers the detailed generation of dependency files — see the Workflow Comparison table above for the one-liner used per tool.
A requirements.txt file lists the necessary Python packages and their versions. There are multiple tools to generate this file, each with different approaches:
pipreqs analyzes your project's import statements to generate a minimal requirements.txt with only the packages your code actually uses.
Installation:
pip install pipreqsUsage:
# Navigate to your project directory
cd /path/to/your/project
# Generate requirements.txt
pipreqs . --forceAdvantages:
- Only includes packages that are actually imported in your code
- Scans your project files to determine dependencies
- Creates a clean, minimal requirements file
- Useful for projects where you don't want to include all environment packages
Options:
pipreqs . --force # Overwrite existing requirements.txt
pipreqs . --savepath custom.txt # Save to a different filename
pipreqs . --ignore venv/,tests/ # Ignore specific directoriespip freeze captures all packages installed in your current Python environment, including their exact versions.
Usage:
pip freeze > requirements.txtAdvantages:
- Simple and built into pip (no installation needed)
- Captures exact versions for reproducibility
- Includes all dependencies and sub-dependencies
Disadvantages:
- Includes ALL packages in your environment, even those not used by your project
- Can create bloated requirements files
- May include system packages or development tools
Best Practices:
- Use within a virtual environment to avoid capturing system packages
- Consider using
pip list --format=freezefor similar output - Manually review and clean up the generated file if needed
Example Output:
certifi==2023.7.22
charset-normalizer==3.2.0
idna==3.4
numpy==1.24.3
pandas==2.0.3
python-dateutil==2.8.2
pytz==2023.3
requests==2.31.0
six==1.16.0
urllib3==2.0.4
pigar is an advanced tool that analyzes your Python files to automatically generate requirements.txt, and can also check for missing or unused packages.
Installation:
pip install pigarUsage:
# Generate requirements.txt in current directory
pigar generate
# Specify a different path
pigar generate -f /path/to/requirements.txt
# Include per-package source comments (see example below)
pigar generate --with-referenced-commentsAdvantages:
- Analyzes actual imports in your code
- Provides comments showing where each package is used
- Can detect packages that are imported but not installed
- Can find packages installed but not imported
Additional Commands:
# Check for missing or redundant packages
pigar check
# Search for available package versions
pigar search numpyExample Output with Comments:
# requirements.txt generated by pigar
# project/data_processing.py: 1,5
numpy==1.24.3
# project/analysis.py: 3
# project/data_processing.py: 2
pandas==2.0.3
# project/api.py: 7
requests==2.31.0
In summary:
| Tool | Scope | Speed | Accuracy | Comments | Built-in |
|---|---|---|---|---|---|
| pip freeze | Entire environment | Fast | ❌ No | ✅ Yes | |
| pipreqs | Project imports | Medium | ✅ Only used packages | ❌ No | ❌ No |
| pigar | Project imports | Medium | ✅ Only used packages | ✅ Yes | ❌ No |
- Use
pip freezewhen you want an exact snapshot of your working environment - Use
pipreqsfor clean project deployment with minimal dependencies - Use
pigarwhen you want detailed tracking of where packages are used and need additional package management features - Use
uv add(see the uv workflow above) if starting fresh — it maintainspyproject.toml/uv.lockautomatically as you go, so there's nothing to "generate" after the fact
If writing dependencies manually, ensure you:
- Specify package names and versions to avoid compatibility issues
- Keep each dependency on a new line
- Use version constraints (
==,>=,<=,~=) to define exact or flexible versions:
numpy>=1.21.0,<2.0.0 # Any version from 1.21.0 up to (but not including) 2.0.0
scipy==1.5.4 # Exact version 1.5.4
matplotlib>=3.0 # Version 3.0 or later
pandas~=1.3.0 # Compatible release (>=1.3.0, <1.4.0)
requests # Any version (not recommended for production)Note:
requirements.txtlists package dependencies only — it is not the place to pin the Python version itself. To require a Python version range, userequires-pythoninpyproject.toml(seePyPI-Guide.md§5), or.python-versionforpyenv/uv.
Version Specifier Guide:
==: Exact version>=: Greater than or equal<=: Less than or equal>: Greater than<: Less than~=: Compatible release (e.g.,~=1.3.0means>=1.3.0, <1.4.0)!=: Exclude specific version
A .yaml (or .yml) file is used to define dependencies in Conda environments.
To generate an environment file:
# Export current environment
conda env export > environment.yaml
# Export without build specifications (more portable)
conda env export --no-builds > environment.yaml
# Export only explicitly installed packages
conda env export --from-history > environment.yamlTo recreate an environment:
# Create environment from file
conda env create -f environment.yaml
# Update existing environment
conda env update -f environment.yamlExample environment.yaml:
name: my_project_env
channels:
- conda-forge
- defaults
dependencies:
- python=3.10
- numpy=1.24.3
- pandas=2.0.3
- matplotlib>=3.5
- scipy
- pip
- pip:
- requests==2.31.0
- beautifulsoup4To install dependencies from a requirements.txt file:
pip install -r requirements.txt
# Or with pip3
pip3 install -r requirements.txt
# Upgrade all packages to specified versions
pip install --upgrade -r requirements.txt- Use virtual environments to isolate project dependencies
- Pin critical package versions to ensure reproducibility
- Document your dependency generation method in your project README
- Regularly update your requirements file as your project evolves
- Test your requirements file in a fresh environment before deployment
- Consider using
requirements-dev.txtfor development-only dependencies - Add comments to explain why specific versions are pinned
Regularly update your dependencies to patch security vulnerabilities:
# Check for outdated packages
pip list --outdated
# Use pip-audit (PyPA-maintained, free, no account needed) to check for known vulnerabilities
pip install pip-audit
pip-audit -r requirements.txt
safety check/safety scanis a well-known alternative, but thesafetyCLI has moved toward a paid/account-gated model —pip-auditis the actively free, PyPA-endorsed option. If you useuv,uv auditcovers the same need natively.
Jupyter Notebooks and JupyterLab are popular tools for interactive programming in Python, especially for data analysis, visualization, and exploration.
- Verify your Python and
pipinstallation:python3 --version pip3 --version pip3 install --upgrade pip
- Install Jupyter Notebook:
pip3 install notebook
- To uninstall:
pip3 uninstall notebook
Launch Jupyter Notebook with:
cd /path/to/your/project
source .venv/bin/activate
jupyter-notebookThis starts a local web server and opens the Jupyter interface in your default browser, allowing you to create, edit, and run Python files.
Launching jupyter-notebook/jupyter-lab from an activated environment only makes that environment's packages available if Jupyter itself was installed inside it. A notebook doesn't run against "whatever env launched the server" — it runs against a kernel, a registered pointer to a specific Python interpreter, chosen independently from the Kernel menu inside the notebook UI.
To make an environment selectable as a kernel from any Jupyter install:
source .venv/bin/activate # or conda activate myenv / uv run —
pip install ipykernel # (uv: uv add --dev ipykernel)
python -m ipykernel install --user --name .venv --display-name "Python (.venv)"Now "Python (.venv)" appears in the Kernel menu regardless of which environment launched the Jupyter server itself. List/remove registered kernels with:
jupyter kernelspec list
jupyter kernelspec uninstall <name>- Verify your Python and
pipinstallation:python3 --version pip3 --version pip3 install --upgrade pip
- Install JupyterLab using
pip:pip3 install jupyterlab
- To uninstall:
pip3 uninstall jupyterlab
Launch Jupyter Lab with:
cd /path/to/your/project
source .venv/bin/activate
jupyter-labThis starts a local web server and opens the Jupyter interface in your default browser, allowing you to create, edit, and run Python files. As above, use the Kernel menu to pick the environment you actually want to run against.
- Jupyter Notebook: Simple interface for smaller projects and quick prototyping.
- JupyterLab: Ideal for larger, more complex workflows requiring multiple tools in one interface.
Follow the tutorial: PyCharm Download
-
Navigate to the Directory:
- Ensure you're in the directory where the
.tar.gzfile is located. Use:cd /path/to/directory/
Replace
/path/to/directory/with the actual path where your.tar.gzfiles are located.
Download PyCharm archive here - Ensure you're in the directory where the
-
Extract the Tarball:
- Run the following command to extract the PyCharm tarball to the
/optdirectory:sudo tar xzf pycharm-community-<version>.tar.gz -C /opt/
- Run the following command to extract the PyCharm tarball to the
-
Run PyCharm:
- Navigate to the extracted folder:
cd /opt/pycharm-community-<version>/
- Launch PyCharm using the following command:
Note: Launch
./bin/pycharm
pycharminstead ofpycharm.sh. More about that here
- Navigate to the extracted folder:
-
Open a Terminal:
- Use the following command to open a new
.desktopfile with Nano:sudo nano /usr/share/applications/pycharm.desktop
- Use the following command to open a new
-
Add the Desktop Entry Content:
- Paste the following content into the file (adjust the paths as necessary):
Replace
[Desktop Entry] Name=PyCharm Comment=Python IDE Exec=/path/to/pycharm/bin/pycharm Terminal=false Type=Application Icon=/path/to/pycharm/bin/pycharm.png Categories=Development;IDE;/path/to/pycharmwith the actual path where PyCharm is installed.
Note: Connectpycharminstead ofpycharm.sh. More about that here
- Paste the following content into the file (adjust the paths as necessary):
-
Save and Exit Nano:
- Press
Ctrl + O(Write Out) to save. - Press
Enterto confirm the file name. - Press
Ctrl + Xto exit Nano.
- Press
-
Verify the Icon:
- Open your applications menu to ensure the PyCharm icon is visible.
-
Open the
bashrcFile:- Open a terminal and type the following command to edit your
bashrcfile:nano ~/.bashrc
- Open a terminal and type the following command to edit your
-
Add the Alias:
- Scroll to the bottom of the file and add the following line:
Replace
alias pycharm="/path/to/pycharm/bin/pycharm"
/path/to/pycharmwith the actual path where PyCharm is installed on your system.
Note: Connectpycharminstead ofpycharm.sh. More about that here
- Scroll to the bottom of the file and add the following line:
-
Save and Exit Nano:
- Press
Ctrl + Oto save the changes. - Press
Enterto confirm the file name. - Press
Ctrl + Xto exit Nano.
- Press
-
Apply the Changes:
- Reload your
bashrcfile with the following command:source ~/.bashrc
- Reload your
-
Test the Shortcut:
- In the terminal, type:
PyCharm should launch.
pycharm
- In the terminal, type:
- Open PyCharm and select New Project.
- In the project creation wizard:
- Under Location, specify the project directory.
- Check New environment using Virtualenv or Conda.
- Configure the Base Interpreter (choose a Python executable).
- Optionally, check Inherit global site-packages to access globally installed packages in the virtual environment.
- Click Create. PyCharm will set up the virtual environment in the project directory (e.g.,
my_project/.venv).
PyCharm automatically activates the virtual environment in its terminal. To manually activate it in the terminal:
- macOS/Linux:
source /path/to/project/.venv/bin/activate - Windows:
.\path\to\project\.venv\Scripts\Activate.ps1
Install packages in the activated virtual environment using the Terminal tab or PyCharm's package manager.
- Open PyCharm and select New Project.
- In the project creation wizard:
- Under Location, specify the project directory.
- Check Previously configured interpreter.
- Select a global interpreter from the list (e.g., system Python or Conda).
- Click Create. The project will use the global interpreter.
Follow the tutorial: Visual Studio Code Download
Debian/Ubuntu (recommended — installs via apt and stays updated through it):
sudo apt update
sudo apt install wget gpg
wget -qO- https://packages.microsoft.com/keys/microsoft.asc | gpg --dearmor > packages.microsoft.gpg
sudo install -D -o root -g root -m 644 packages.microsoft.gpg /usr/share/keyrings/packages.microsoft.gpg
sudo sh -c 'echo "deb [arch=amd64,arm64,armhf signed-by=/usr/share/keyrings/packages.microsoft.gpg] https://packages.microsoft.com/repos/code stable main" > /etc/apt/sources.list.d/vscode.list'
sudo apt update
sudo apt install codeFedora/RHEL (.rpm-based) — same package repo, or a manual download:
- Navigate to the directory where the
.rpmfile is located:Download Visual Studio Codecd /path/to/directory/.rpmhere - Install the
.rpmPackage:Replacesudo rpm -ivh code-<version>.rpm
<version>with the actual version you downloaded.
Verify Installation (any distro):
code --version- Create a Virtual Environment in your project directory:
python3 -m venv .venv
- In Visual Studio Code, open the Command Palette (Ctrl+Shift+P or Cmd+Shift+P).
- Search for Python: Select Interpreter.
- Select the interpreter for your virtual environment (e.g.,
./.venv/bin/python3) — VS Code auto-detects a.venvfolder in the project root and lists it at the top. - When you open a new terminal in VS Code, activate the virtual environment:
- macOS/Linux:
source .venv/bin/activate - Windows:
Now your code will be executed with the activated environment
.\.venv\Scripts\Activate.ps1
- Open a folder in VS Code that contains your project.
- Select a global interpreter using Python: Select Interpreter from the Command Palette.
- All packages installed will use the global Python installation.












