Activating a conda environment modifies the PATH and shell variables to point to the specific isolated Python set-up you created.
1. virtualenv
virtualenv is a very popular tool that creates isolated Python environments for Python libraries. It works by installing a bunch of files in a directory (eg: env/), and then modifying the PATH environment variable to prefix it with a custom bin directory (eg: env/bin/). An exact copy of the python or python3 binary is placed in this directory, but Python is programmed to look for libraries relative to its path first, in the environment directory.
Once activated, you can install packages in the virtual environment using pip.
Install virtualenv:
$ pip install virtualenv
Create a virtual environment:
$ virtualenv yourenvname
Activate the virtual environment:
$ source yourenvname/bin/activate
To leave my virtual environment:
$ deactivate
To install all the required packages specified by the file requirements.txt:
$pip install -r requirements.txt
$ pip freeze > requirements.txt
To delete a virtual environmrent
$ rm -r /path/to/yourenvname
2. conda
The conda command is the preferred interface for managing installations and virtual environments with the Anaconda Python distribution.
To see a list of available python versions:
$ conda search "^python$"Create a virtual environment with python version x.x for your project
$ conda create -n yourenvname python=x.x anaconda
$ source activate yourenvname
$ conda info -e
To install additional packages only to your virtual environment
$ conda install -n yourenvname [package]
Failure to specify “-n yourenvname” will install the package to the root Python installation.
To end a session in the current environment
$ source deactivate
No comments:
Post a Comment