Sunday, 29 November 2020

python virtual environment for windows

Here we'll create virtual env, activate, deactivate and copy requirement  

* Go to anaconda prompt and type: mkdir my_project

here we created folder my_project. now we want to create virtual environment into our project.

* python -m venv my_project\venv

here we created virtual env name 'venv' in our project.

* my_project\venv\Scripts\activate.bat

here we activated our virtual environment



Now we can see that our virtual env is activated.

to deactivate virtual env just type deactivate

* to transfer all system packages in our new created environment (at time of creation):
python -m venv my_project\venv --system-site-packages

this transfer all system packages to our virtual env

* to activate : my_project>venv\Scripts\activate.bat

now our new environment has system packages and newly installed packages by us. so to know only our installed packages. 
pip list --local

pip freeze --local



* How to setup jupyter kernel?

once you activated your virtual enviroment. install ipykernel.


here we have created test_venv virtual environment and activated.
> pip install ipykernel (install ipykernel)

after it gets install, we activate ipynb kernel.
> ipython kernel install --user --name=test_venv_kernel

here test_venv_kernel is kernel's name.

and open jupyter notebook.





here we can see that new kernel has been added in kernel list. 



No comments:

Post a Comment