How to install Virtual environment (virtualenv) and requirements.txt in python3


Install virtual environment and use requirements.txt


Step 1.

Install python 3

sudo apt-get update

sudo apt-get install python3.6

you can check python version

python3 -V


Step 2

Now install 

sudo apt install python3-pip

Please check pip version

pip3 -V  

it's should be >= pip 20.0.0

Step 3

Install virtualenv

pip3 install virtualenv


Step 4

Now select a directory where you want to setup virtualenv Like

cd /directory/path

Step 5

In that directory setup virtualenv with python3

virtualenv -p python3 ./dir_name

it will create a dir_name folder (dir), You can change it whatever you like (dir_name you should write anything whatever you like)


Step 6

Now active it 

source dir_name/bin/activate

now you console look like this

(dir_name) computer$

if you write down "python" and  then enter, your python3 will be run 

Step 7

pip3 install install-requires

Now we have 2 ways to create requirements.txt

(i) install any packages

pip3 install django

and then run a command 

pip3 freeze > requirements.txt

it will create a requirements.txt with all the packages list


(ii) second way:

create a requirements.txt manully and write down this

Django==2.2.15

and instal this with this command 

pip3 install -r requirements.txt


If you virtualenv activate then you all pip packages install in you virtualenv, You can see them 


dir_name/lib/python3.5/site-packages


install your virtualenv on your live server and just copy your requirements.txt over there and run this with they help of this command 

pip3 install -r requirements.txt

all require packages install on your server with same version.




Comments

Popular posts from this blog

SQLAlchemy Create Table and Insert Data

SQLAlchemy ForeignKey Constraints