Easy Steps To Install Anaconda Python on Debian 12 Bookworm
In this guide, you will learn to Install Anaconda Python on Debian 12 Bookworm from Command-Line. Anaconda is a package manager that is commonly used for machine learning and artificial intelligence applications. It provides libraries and dependencies in Python programming language. You can follow this tutorial on the Orcacore website to Install Anaconda Python on Debian 12 Bookworm.
To Install Anaconda Python on Debian 12 Bookworm, you must have access to your server as a non-root user with sudo privileges. To do this, you can follow this guide on Initial Server Setup with Debian 12 Bookworm.
Now proceed to the following steps to Install Anaconda Python on Debian 12 Bookworm.
Step 1 – Download Anaconda Python Installer on Debian 12
First, you must run the system update from your terminal with the command below:
sudo apt update
Then, you must visit the Anaconda Downloads page and get the latest Python installer for Linux.
[Insert Anaconda Downloads page image here]
You need to switch to your /tmp directory and use the following wget command to download the Anaconda Python installer:
# cd /tmp
# sudo wget https://repo.anaconda.com/archive/Anaconda3-2023.07-2-Linux-x86_64.sh
Step 2 – Run Anaconda Python Installer
When your download is completed, you can run your Anaconda installer on Debian 12 with the command below:
bash Anaconda3-2023.07-2-Linux-x86_64.sh
When you run the installer, you will see the following output:
**Output**
Welcome to Anaconda3 2023.07
In order to continue the installation process, please review the license
agreement.
Please, press **ENTER** to continue
>>>
Press Enter to continue. And Press Yes to accept the license agreement.
Do you accept the license terms? [yes|no]
[no] >>> yes
Then, you must specify the installation location. You can press Enter to accept the default.
Anaconda3 will now be installed into this location:
/root/anaconda3
- Press ENTER to confirm the location
- Press CTRL-C to abort the installation
- Or specify a different location below
Next, you will be asked to initialize Anaconda3 and press Yes to continue.
Do you wish the installer to initialize Anaconda3
by running conda init? [yes|no]
[no] >>> yes
Wait to finish the process. You will get the following output:
**Output**
Thank you for installing Anaconda3!
Step 3 – Activate Anaconda Python Installer on Debian 12
At this point, you can activate your Anaconda installation with the following command:
source ~/.bashrc
You will see the base in your prompt shell:
(base) root@deb:/tmp#
Also, you can test your installation by running the following conda command:
conda info
**Output**
active environment : base
active env location : /root/anaconda3
shell level : 1
user config file : /root/.condarc
populated config files :
conda version : 23.7.2
conda-build version : 3.26.0
python version : 3.11.4.final.0
virtual packages : __archspec=1=x86_64
__glibc=2.36=0
__linux=6.1.0=0
__unix=0=0
base environment : /root/anaconda3 (writable)
conda av data dir : /root/anaconda3/etc/conda
conda av metadata url : None
channel URLs : https://repo.anaconda.com/pkgs/main/linux-64
https://repo.anaconda.com/pkgs/main/noarch
https://repo.anaconda.com/pkgs/r/linux-64
https://repo.anaconda.com/pkgs/r/noarch
package cache : /root/anaconda3/pkgs
/root/.conda/pkgs
envs directories : /root/anaconda3/envs
/root/.conda/envs
platform : linux-64
user-agent : conda/23.7.2 requests/2.31.0 CPython/3.11.4 Linux/6.1.0-11-amd64 debian/12 glibc/2.36
UID:GID : 0:0
netrc file : None
offline mode : False
Step 4 – Update Conda and Anaconda on Debian 12
Every time you want to update your Anaconda, first, you must update the conda utility with the command below:
conda update conda
Then, use the following command to update the Anaconda package:
conda update anaconda
To deactivate the base Anaconda environment, you can run the following command:
(base) root@deb:~# conda deactivate
Step 5 – Create a Test Environment with Anaconda
At this point, you can create a test environment with Python 3 with the following command on Debian 12:
conda create --name test_environment python=3
Then, you can activate your environment with the command below:
conda activate test_environment
This will change your prompt shell to your environment. Now you have a shell environment with Python3 and you can start working with it.
Conclusion
At this point, you have learned to Install Anaconda Python on Debian 12 Bookworm from Command-Line. Also, you have learned to test your installation and create a test environment with Python. Hope you enjoy it.
Also, you may like to read the following articles:
Installing Apache Guacamole on Ubuntu 24.04
Discover StartOS Linux Download and Reviews
Install Mozilla Firefox in Ubuntu Using Terminal
Best Termux Commands For Android Devices
Alternative Solutions for Installing Python on Debian 12 Bookworm
While Anaconda is a popular choice, especially for data science and machine learning, there are alternative ways to install and manage Python environments on Debian 12 Bookworm. These methods offer different advantages and might be more suitable depending on your specific needs and preferences.
Here are two alternative approaches:
1. Using the System Package Manager (apt) and venv
This approach leverages Debian’s built-in package manager (apt
) to install the system-wide Python interpreter and then utilizes venv
(Python’s built-in virtual environment module) to create isolated environments for different projects.
Explanation:
- System-Wide Python: Installing Python directly through
apt
provides a base Python installation that’s managed by the operating system. This is generally a stable and well-tested version. venv
for Isolation: Thevenv
module allows you to create isolated Python environments. Each environment has its own independent set of installed packages, preventing conflicts between projects that require different versions of the same libraries. This is crucial for maintaining project stability and reproducibility.
Steps:
-
Install Python: First, install Python 3 using
apt
:sudo apt update sudo apt install python3 python3-venv
This installs the Python 3 interpreter and the
venv
module. -
Create a Virtual Environment: Navigate to your project directory (or create one) and create a virtual environment:
mkdir my_project cd my_project python3 -m venv .venv # Creates a virtual environment in the .venv directory
-
Activate the Virtual Environment: Activate the virtual environment to use it:
source .venv/bin/activate
Your shell prompt will change to indicate that the environment is active (e.g.,
(.venv) user@debian:~/my_project$
). -
Install Packages: Install the necessary packages for your project using
pip
:pip install requests numpy pandas
These packages will be installed only within the
.venv
environment. -
Deactivate the Environment: When you’re finished working on the project, deactivate the environment:
deactivate
Your shell prompt will return to normal.
Code Example:
Here’s a simple example demonstrating the use of venv
:
# my_project/main.py
import requests
def fetch_data(url):
try:
response = requests.get(url)
response.raise_for_status() # Raise an exception for bad status codes
return response.text
except requests.exceptions.RequestException as e:
print(f"Error fetching data: {e}")
return None
if __name__ == "__main__":
data = fetch_data("https://www.example.com")
if data:
print("Data fetched successfully!")
# Process the data here
else:
print("Failed to fetch data.")
To run this, you’d first create and activate a virtual environment as described above, then install the requests
library within the environment:
pip install requests
python main.py
Advantages:
- Lightweight:
venv
is simpler and less resource-intensive than Anaconda. - Standard Library: It’s part of Python’s standard library, so no additional installation is required (beyond the initial
apt install python3-venv
). - Clean System: Keeps your system’s base Python installation clean and uncluttered.
Disadvantages:
- Manual Management: Requires more manual management of dependencies and environments compared to Anaconda.
- No Conda Packages: Cannot use Conda packages, which may be necessary for some scientific computing libraries.
2. Using pipenv
pipenv
is a tool that aims to bring the best of both worlds: the simplicity of pip
and the environment isolation of virtual environments, with improved dependency management.
Explanation:
- Automated Virtual Environment Management:
pipenv
automatically creates and manages virtual environments for your projects. - Dependency Locking: It uses a
Pipfile
andPipfile.lock
to track and lock dependencies, ensuring that everyone working on the project uses the same versions of packages. - Simplified Workflow:
pipenv
simplifies the process of installing, updating, and managing dependencies.
Steps:
-
Install
pipenv
: Installpipenv
usingpip
(from the system-wide Python or a previously created virtual environment):pip install --user pipenv
It’s recommended to install it with the
--user
flag to avoid conflicts with system packages. You might need to add~/.local/bin
to yourPATH
ifpipenv
is not found after installation. You can do so by addingexport PATH="$PATH:$HOME/.local/bin"
to your.bashrc
or.zshrc
file and then sourcing it (e.g.,source ~/.bashrc
). -
Navigate to Your Project Directory: Go to your project directory (or create one).
-
Install Dependencies: Install the project’s dependencies using
pipenv install
:cd my_project pipenv install requests numpy pandas
This will create a
Pipfile
andPipfile.lock
in your project directory, and automatically create and activate a virtual environment. -
Activate the Environment (if needed): If the environment isn’t automatically activated, you can activate it using:
pipenv shell
-
Run Your Code: Run your Python code as usual.
-
Exit the Environment: To exit the
pipenv
environment, typeexit
in the terminal.
Code Example:
The same main.py
example from the venv
section will work with pipenv
. The key difference is how you manage the environment and dependencies.
# my_project/main.py
import requests
def fetch_data(url):
try:
response = requests.get(url)
response.raise_for_status() # Raise an exception for bad status codes
return response.text
except requests.exceptions.RequestException as e:
print(f"Error fetching data: {e}")
return None
if __name__ == "__main__":
data = fetch_data("https://www.example.com")
if data:
print("Data fetched successfully!")
# Process the data here
else:
print("Failed to fetch data.")
To run this, you’d first install requests
using pipenv install requests
, then run the script using python main.py
(while the pipenv
shell is active or by using pipenv run python main.py
).
Advantages:
- Simplified Dependency Management:
pipenv
automates virtual environment creation and dependency locking. - Reproducible Builds: The
Pipfile.lock
ensures that everyone on the project uses the same versions of packages. - Easy to Use: Provides a user-friendly command-line interface.
Disadvantages:
- Third-Party Tool: Requires installing an additional tool (
pipenv
). - Can be Slower: Potentially slower than
venv
for simple tasks.
Choosing the right approach depends on your specific needs. If you need a full-fledged data science environment with a wide range of pre-installed packages, Anaconda is a good choice. If you prefer a more lightweight and flexible solution, venv
or pipenv
might be better options. Both offer solid alternatives to Install Anaconda Python on Debian 12 Bookworm.