Beginner's - creating virtual environment on ubuntu for python
ruchikaatwal
Posted on June 27, 2022
Installing virtual environment
- Update your system
$ sudo apt-get update && sudo apt-get upgrade
- Install Virtual Environment package with below command :
$ sudo apt install virtualenv -y
- Create a python virtual environment directory for different.
$ mkdir ~/python-environments && cd ~/python-environments
Explanation :
mkdir -> is used a create folder/directory in ubuntu from
terminal
cd -> is used to change path for folder/directory path
&& -> is used to join and run 2 commands in terminal
together at once
You can run make directory and change directory command in separate line too :
$ mkdir ~/python-environments
$ cd ~/python-environments
- Now create python virtual environment :
$ virtualenv --python=python3.8 env_python38
After running create virtual enviornment commant output in terminal would be like this :
created virtual environment CPython3.8.10.final.0-64 in 80ms
creator CPython3Posix(dest=/home/ruchika/python-environments/env_python38, clear=False, global=False)
seeder FromAppData(download=False, pip=latest, setuptools=latest, wheel=latest, pkg_resources=latest, via=copy, app_data_dir=/home/ruchika/.local/share/virtualenv/seed-app-data/v1.0.1.debian.1)
activators BashActivator,CShellActivator,FishActivator,PowerShellActivator,PythonActivator,XonshActivator
- type ls command to check list of file, folder in current directory :
ls
you can your created virtual environment directory :
env_python38
- Check your environment is installed with the python version is proper :
$ ls env_python38/lib
Activate and deactivate virtual environment
- Activate your virtual environment
$ source env_python38/bin/activate
After activating you see your virtual env name in rounf bracket :
(env_python38) yoursystemname:~/python-environments$
- Deactiavte (close) your virtual environment:
$ deactivate
💖 💪 🙅 🚩
ruchikaatwal
Posted on June 27, 2022
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.