How to use virtualenv with Python?

I plan to install a virtual environment for Python so that the individual Python packages are separated. One of the reasons for this is also the presence of two versions of Python on my machine (Ubuntu 14.04). I have the following wonders:

  • In what order should Python, PIP, and virtualenv be installed? Does it matter at all?
  • Once I have finished, how can I save two versions of python separately from virtualenv?
  • Suppose I am working on separate projects, is it recommended to save each project in a separate folder created by virtualenv or not?

I would like to know the opinion of experts to do everything correctly and wisely.

+4
source share
5 answers

virtualenv Python. , :

+3

, Python Ubuntu 14.04 python2.7 python3, "python" python2.7.

Pip,

sudo apt-get install python-pip python3-pip

, pip py2 pip py3 , .

VirtualEnv pip virtualenv:

pip install virtualenv

pip python2


, , :

mkdir -p project_name/source
cd project_name
virtualenv env

env , , , "env", , VirtualEnv , - :

(env)yser@machine:/home/user/cool_projects/project_name$

, ( ), .

virtualenv:

cd project_name
source env/bin/activate

pip VirtualEnv. , VirtualEnv :

deactivate

, !

+4

, python virtualenv

1, python venv:

>>> cd [your project path]
>>> virtualenv venv

2- :

>>> source ./venv/bin/active

3- pip:

>>> pip install -r <your requirements file>
>>> or pip install <python module>

>>> ./venv/bin/pip install <python module>

4- python script :

>>> python <.py file>

env:

 >>> ./venv/bin/python <.py file>

python env,

+2

pyenv. Pythons (cpython, thon, anaconda,...), . Python system.

+1

Python, PIP virtualenv? ?

1. Install python
2. Install pip
3. Install virtualenv (with `pip install virtualenv`)
4. Create new virtualenv

python virtualenv?

python python :

    virtualenv -p /usr/bin/python2.7 <path/to/new/virtualenv/>

, , , virtualenv ?

. , python , .

Python! !

python 2.7.2 Ubuntu? Pip Ubuntu , ...

+1

Source: https://habr.com/ru/post/1626017/


All Articles