Temporary virtual environment

      Nenhum comentário em Temporary virtual environment

In some moments we need to try a new library or method but we don’t wanna to dirty our workspace!

Well, when we use a pyenv (we talk about it here) and virtualenvwrapper we have a functionality that helps us to do this easily the command mktmpenv.

When we execute this command it creates a temporary virtual environment which we can do all of our tests and when we execute the command deactivate the virtual workspace is destroyed and our workspace is totally clean.

Take an example, I wanna to try the Django Framework. Well, first we need to initialize the temporary virtual environment with the command mktmpenv. We have the following return of the terminal:

➜ ~ mktmpenv
Using base prefix '/home/vicente/.pyenv/versions/3.6.2'
New python executable in /home/vicente/.envs/tmp-28cee0198e47ff3/bin/python3.6
Also creating executable in /home/vicente/.envs/tmp-28cee0198e47ff3/bin/python
Installing setuptools, pip, wheel...done.
virtualenvwrapper.user_scripts creating /home/vicente/.envs/tmp-28cee0198e47ff3/bin/predeactivate
virtualenvwrapper.user_scripts creating /home/vicente/.envs/tmp-28cee0198e47ff3/bin/postdeactivate
virtualenvwrapper.user_scripts creating /home/vicente/.envs/tmp-28cee0198e47ff3/bin/preactivate
virtualenvwrapper.user_scripts creating /home/vicente/.envs/tmp-28cee0198e47ff3/bin/postactivate
virtualenvwrapper.user_scripts creating /home/vicente/.envs/tmp-28cee0198e47ff3/bin/get_env_details
This is a temporary environment. It will be deleted when you run 'deactivate'.
(tmp-28cee0198e47ff3) ➜ tmp-28cee0198e47ff3

To try our workspace we execute the command pip freeze and we get this retrun in the terminal:

(tmp-28cee0198e47ff3) ➜ tmp-28cee0198e47ff3 pip freeze
(tmp-28cee0198e47ff3) ➜ tmp-28cee0198e47ff3

Ok, now we need to install the Django:

(tmp-28cee0198e47ff3) ➜ tmp-28cee0198e47ff3 pip install django
Collecting django
Using cached Django-1.11.5-py2.py3-none-any.whl
Collecting pytz (from django)
Using cached pytz-2017.2-py2.py3-none-any.whl
Installing collected packages: pytz, django
Successfully installed django-1.11.5 pytz-2017.2
(tmp-28cee0198e47ff3) ➜ tmp-28cee0198e47ff3

Now, we use the iPython to verify the Django installation:

>>> import django
>>> print(django.get_version())
1.11.5
>>>

Now we can do some tests we need. And, after all tests we can deactivate the virtualenv and our workspace is totaly clean!

I hope that this tip will be useful for all!

About Prof. Vicente E. R. Marçal

Professor Adjunto do Departamento de Filosofia da Universidade Federal de Rondônia. Doutorando em Psicologia Social pelo Instituto de Psicologia da USP. Mestre em Filosofia pela Universidade Estadual Paulista/Campus Marília. Especialista em Filosofia Moderna e Contemporânea: Aspectos Éticos e Jurídicos pela Universidade Estadual de Londrina. Licenciado em Filosofia pela Universidade Estadual de Londrina. Coordenador do GEPEGRA - Grupo de Estudos e Pesquisa em Epistemologia Genética da Região Amazônica. Com experiência em Filosofia, com ênfase em Epistemologia e Teoria do Conhecimento.

Deixe uma resposta

O seu endereço de e-mail não será publicado. Campos obrigatórios são marcados com *

This site uses Akismet to reduce spam. Learn how your comment data is processed.