Python’s installation directory on Linux typically appears at /usr/bin/python when you check with the which command. If you’re wondering where is python installed linux, the answer depends on how you installed it and which version you’re using. This guide walks you through every common location and method to find it.
Knowing where Python lives on your system helps with scripting, debugging, and setting up virtual environments. Let’s start with the basics and then dive into the specifics.
Understanding Python Installation Paths On Linux
Linux systems often come with Python pre-installed. The default location is usually /usr/bin/python or /usr/bin/python3. But depending on your distribution and installation method, it can vary.
Most modern Linux distros have Python 3 installed by default. Python 2 is legacy and rarely found on new systems. You’ll typically find the executable in one of these standard directories:
- /usr/bin/python
- /usr/bin/python3
- /usr/local/bin/python
- /usr/local/bin/python3
These paths are part of the system’s PATH environment variable. When you type python in the terminal, the shell looks through each directory in PATH until it finds the executable.
Where Is Python Installed Linux: Common Locations
Let’s answer the core question directly. The exact location depends on your installation method. Here are the most common places:
System Python Installation
If Python came with your Linux distribution, it’s usually in /usr/bin/. Run this command to confirm:
which python3
This returns something like /usr/bin/python3. If you have multiple versions, you might see /usr/bin/python3.10 or /usr/bin/python3.11.
User-Installed Python Via Package Manager
When you install Python using apt, yum, or dnf, it typically goes to /usr/bin/ as well. For example:
sudo apt install python3
After installation, check with:
whereis python3
This shows both the binary location and the man page path.
Python Installed From Source
If you compiled Python from source code, it often installs to /usr/local/bin/. The default prefix is /usr/local, so the executable ends up at /usr/local/bin/python3.
You can specify a custom prefix during compilation with the –prefix option. For instance:
./configure --prefix=/opt/python
This would place Python in /opt/python/bin/python3.
Python Installed Via Pyenv
Pyenv is a popular tool for managing multiple Python versions. It installs Python in a hidden directory under your home folder:
~/.pyenv/versions/
Each version gets its own subdirectory, like ~/.pyenv/versions/3.11.4/bin/python.
Python In Virtual Environments
When you create a virtual environment, Python is copied or symlinked into the environment’s directory. For example:
python3 -m venv myenv
This creates myenv/bin/python, which points to the system Python.
How To Find Python Installation Directory On Linux
You don’t need to guess. Use these reliable methods to pinpoint Python’s location.
Method 1: Using The Which Command
The simplest way. Open your terminal and type:
which python3
If you have Python 2 installed, try:
which python
This shows the first executable found in your PATH.
Method 2: Using The Whereis Command
This command searches for binary, source, and manual page files:
whereis python3
Output example: python3: /usr/bin/python3 /usr/lib/python3 /etc/python3 /usr/share/man/man1/python3.1.gz
Method 3: Using The Type Command
The type command tells you how the shell interprets a command:
type python3
It returns something like: python3 is /usr/bin/python3
Method 4: Using Python Itself
Python can tell you its own location. Run:
python3 -c "import sys; print(sys.executable)"
This prints the full path to the Python interpreter.
Method 5: Check The PATH Variable
Your PATH variable lists directories where executables are stored. View it with:
echo $PATH
Look for directories like /usr/bin, /usr/local/bin, or custom paths.
Where Is Python Installed Linux: Distribution-Specific Paths
Different Linux distributions may place Python in slightly different locations. Here’s a breakdown.
Ubuntu And Debian
On Ubuntu and Debian, Python 3 is at /usr/bin/python3. You’ll also find version-specific symlinks like /usr/bin/python3.10. The standard library modules are in /usr/lib/python3/.
Fedora And Red Hat
Fedora and RHEL use /usr/bin/python3 as well. However, they often have both python and python3 commands. The python command may point to Python 2 on older systems.
Arch Linux
Arch Linux places Python in /usr/bin/python. It’s usually a symlink to the latest version, like /usr/bin/python3.11.
OpenSUSE
OpenSUSE follows the same pattern: /usr/bin/python3. The system also has /usr/bin/python for compatibility.
Alpine Linux
Alpine uses musl libc and has a minimal footprint. Python is at /usr/bin/python3. The package manager installs it to /usr/bin/.
How To Check Python Version And Path Together
Sometimes you need both the version and location. Use this command:
python3 --version && which python3
Or combine them in a single Python command:
python3 -c "import sys; print(f'Version: {sys.version}\nPath: {sys.executable}')"
This outputs something like:
Version: 3.11.4 (main, Jun 20 2023, 14:32:21)
Path: /usr/bin/python3
What If Python Is Not Found?
If you get “command not found” when typing python3, Python may not be installed. Install it using your package manager:
- Ubuntu/Debian: sudo apt install python3
- Fedora: sudo dnf install python3
- Arch: sudo pacman -S python
- Alpine: sudo apk add python3
After installation, check the path again.
Understanding Python Symlinks On Linux
Many Linux systems use symlinks for Python. The actual executable might be at /usr/bin/python3.11, and /usr/bin/python3 is a symlink pointing to it. This allows multiple versions to coexist.
To see symlinks, use:
ls -l /usr/bin/python*
You’ll see output like:
lrwxrwxrwx 1 root root 9 Jun 20 14:32 /usr/bin/python3 -> python3.11
-rwxr-xr-x 1 root root 5.5M Jun 20 14:32 /usr/bin/python3.11
The arrow shows the target of the symlink.
Where Is Python Installed Linux: Custom Installations
If you installed Python manually, it could be anywhere. Here are common custom locations:
Home Directory Installation
Some users install Python in their home directory to avoid system conflicts. For example:
~/python3.11/bin/python3
This is common when you don’t have root access.
Opt Directory Installation
System administrators sometimes install software in /opt/. You might find:
/opt/python3.11/bin/python3
This keeps third-party software separate from system files.
Containerized Installations
In Docker containers or Flatpak, Python’s location depends on the base image. Typically, it’s still /usr/bin/python3 inside the container.
How To Add Python To Your PATH
If Python is installed but not in your PATH, you can add it manually. Edit your shell configuration file (~/.bashrc, ~/.zshrc, or ~/.profile) and add:
export PATH="/path/to/python/bin:$PATH"
Then reload with:
source ~/.bashrc
Now you can run python3 from anywhere.
Finding Python Libraries And Modules
Knowing where the Python interpreter is helps, but you might also need library paths. Use:
python3 -c "import sys; print(sys.path)"
This shows a list of directories where Python looks for modules. Typical paths include:
- /usr/lib/python3.11/
- /usr/local/lib/python3.11/dist-packages/
- ~/.local/lib/python3.11/site-packages/
Where Is Python Installed Linux: Troubleshooting Tips
Sometimes things go wrong. Here are common issues and fixes:
Multiple Python Versions Confusion
If you have several Python versions, the wrong one might run. Use the full path to specify:
/usr/bin/python3.10 script.py
Or use pyenv to manage versions cleanly.
Permission Denied Errors
If you can’t access the Python binary, check permissions:
ls -l /usr/bin/python3
It should be executable. If not, use chmod:
sudo chmod +x /usr/bin/python3
Broken Symlinks
A symlink might point to a non-existent file. Check with:
file /usr/bin/python3
If it says “broken symbolic link”, reinstall Python or recreate the symlink.
Using Python In Scripts With Correct Path
When writing shell scripts, use the shebang line to specify the Python interpreter:
#!/usr/bin/env python3
This is portable and finds Python in the user’s PATH. Alternatively, hardcode the path:
#!/usr/bin/python3
Where Is Python Installed Linux: Virtual Environments
Virtual environments create isolated Python installations. They’re essential for project-specific dependencies.
Creating A Virtual Environment
Run:
python3 -m venv myproject
This creates a folder myproject with its own bin/python. Activate it with:
source myproject/bin/activate
Now which python3 shows the virtual environment’s path.
Finding The System Python From A Virtual Environment
Inside a virtual environment, you can still access the system Python with:
deactivate
Or use the full path to the system interpreter.
Where Is Python Installed Linux: Advanced Methods
For power users, here are more advanced ways to locate Python.
Using Ldconfig
Python shared libraries are sometimes in /usr/lib/. Use ldconfig to find them:
ldconfig -p | grep python
This lists shared libraries like libpython3.11.so.1.0.
Using Find Command
Search the entire filesystem for Python executables:
sudo find / -name "python3*" -type f 2>/dev/null
This can take time but finds everything.
Using Locate Command
If you have mlocate installed, use:
locate python3 | grep bin/python
This is faster than find because it uses a database.
Where Is Python Installed Linux: Summary Table
Here’s a quick reference for common Python locations:
- System default: /usr/bin/python3
- User compiled: /usr/local/bin/python3
- Pyenv: ~/.pyenv/versions/3.x.x/bin/python
- Virtual env: /path/to/venv/bin/python
- Custom prefix: /opt/python/bin/python3
Frequently Asked Questions
How Do I Find Where Python Is Installed On Linux?
Use the which python3 or whereis python3 command in the terminal. You can also run python3 -c “import sys; print(sys.executable)”.
Why Is Python Installed In /Usr/bin/ On Linux?
/usr/bin/ is the standard directory for user executables on Linux. It’s part of the system PATH, making Python accessible from anywhere.
Can I Change Where Python Is Installed On Linux?
Yes, by compiling from source with a custom prefix or using tools like pyenv. You can also install Python in your home directory.
What Is The Difference Between /Usr/bin/python And /Usr/local/bin/python?
/usr/bin/ is for system-managed packages, while /usr/local/bin/ is for locally compiled software. System Python usually goes to /usr/bin/.
How Do I Find All Python Installations On My Linux System?
Run sudo find / -name “python*” -type f 2>/dev/null or use locate python. This lists all Python executables across the filesystem.
Now you know exactly where Python is installed on your Linux system. Whether it’s in /usr/bin/, /usr/local/bin/, or a custom location, these methods will help you find it every time. Use the which command for a quick check, or dive deeper with Python’s sys.executable for the full path. Happy coding!