DEV Community

Abdul Awal Nadim
Abdul Awal Nadim

Posted on

Create a Python environment in Linux (Ubuntu) & Windows

apt update
apt install python3.12
python3.12 --version
python3.12 -m pip

pip3.12 -V
python3.12 -m venv --help

sudo apt install python3.12-venv

----create environment Name "python-env-file"---
python3.12 -m venv python-env-file

---------"create requirements.txt file with all dependencies"------
pip freeze > requirements.txt


------------"install all dependencies of requirements.txt"--------
pip3.12 install -r requirements.txt
Enter fullscreen mode Exit fullscreen mode
----old----

--------------Update and Upgrade Packages-------------------------
sudo apt update
sudo apt upgrade

--------------------Install Python------------------------
python3 --version
sudo apt install python3

-----------------------Install pip (Python Package Manager)-------------
pip3 --version
sudo apt install python3-pip

python3 -m venv --help
sudo apt install python3-venv

----create environment Name "python-env-file"---
python3 -m venv python-env-file

-----go to project root directory & Activate the Virtual Environment ----
source python-env-file/bin/activate

----------------Install Python Packages-----------------------
pip install package_name

---------"create requirements.txt file with all dependencies"-------
pip freeze > requirements.txt

------------"install all dependencies of requirements.txt"--------
pip install -r requirements.txt

------Deactivate the Virtual Environment------------
deactivate
Enter fullscreen mode Exit fullscreen mode
How do I create a Python environment in Windows==>

python -m venv <environment-folder-name>
<environment-folder-name>\Scripts\activate

Example==>
python -m venv env
env\Scripts\activate
Enter fullscreen mode Exit fullscreen mode

Top comments (0)