Do we need to install same conda packages repeatedly for different virtual environments? Is there a way to reuse python packages from one virtualenv to other? Is there a way to use global conda packages within a virtual environment?
You can copy the packages in one environment to other using the following command..
conda create -n --clone
For example , default environment is "base" and i want to copy it to a new env "new" , then...
conda create -n new --clone base
For more options , type ...
conda create -h
Related
Conda allows me to list all virtual environments as shown here. The commands are:
conda info --envs OR conda env list
I want to do that using pip. Does pip have any option to list all virtual environments created by me ? I have created a virtual environment on my desktop but I cannot figure out a way to list it along with the base environment.
No, not in an easy way.
Python virtual environments created with venv, virtualenv and most other python-only virtual environments can be stored anywhere on the disk. And AFAIK they are not indexed, they are truly isolated (after all you can just remove venv directory and be done with it, you don't need to do anything special). They are also unmanaged by an environment manager. So that would require entire disk scan. Which potentially can be done (you can search for all Python executables for example) but is rather painful.
It works with miniconda because miniconda manages other packages and files that it installs, so it places venvs in concrete path, e.g. /home/username/miniconda/envs/.
One indirect way is to run below command and see the directories where the python executable resides. Some of the paths will be python virtual environments and you can verify it by listing the files in those paths.
$ whereis python
You can use conda to create and manage venv and virtualenv environments and other packages installed using pip.
First create a conda environment with CONDA AND PIP installed into it, e.g.,
conda create --name core --channel conda-forge python=3.9 conda pip
Here I created the conda environment named "core" and installed Python 3.9, conda, and pip into it. So now the 'core' conda environment functions like an administrative environment shell. By installing conda into the conda environment, conda will track packages installed by pip into that environment. You must use "pip install" INSIDE this new conda environment, so conda will index and track those pip package installations. However, conda will still not index and centrally manage the venv environments, like it does for its own conda environments.
Here is a very good detailed guide that explains how and why to use conda and pip for virtual environments. It covers the important aspect of using conda and pip together.
Why You Need Python Environments and How to Manage Them with Conda
Create virtual environments for python with conda
I installed several conda packages in /usr/local/pkgs, and created a new environment with conda create --name env1. Will this environment by default include all the packages in /usr/local/pkgs, or will it include only the packages that are shipped by default with conda? Also, where can I see the list of packages that are included in a given environment? I'm using OS X.
No, it doesn't. If you want it to, you can use
conda create --name env1 --clone base
But it's generally not recommended to clone base since it includes additional packages only base needs.
You can check what is installed in an env with
conda list --name env1
you can list all the packages installed with conda list once the environment is activated
conda activate envname
conda list
The packages in the base environment wont be available in environments by default
I recently installed Anaconda in my Windows. I did that to use some packages from some specific channels required by an application that is using Python 3.5 as its scripting language.
I adjusted my PATH variable to use Conda, pointing to the Python environment of the particular program, but now I would like to use Conda as well for a different Python installation that I have on my Windows.
When installing Anaconda then it isn't asking for a Python version to be related to. So, how can I use Conda to install into the other Python installation. Both Python installations are 'physical' installations - not virtual in any way.
Uninstall the other python installation and create different conda environments, that is what conda is great at.
Using conda from your anaconda installation to manage packages from another, independent python installation is not possible and not very feasible.
Something like this could serve your needs:
Create one env for python 3.5 conda create -n py35 python=3.5
Create one env for some other python version you would like to use, e.g. 3.6: conda create -n py36 python=3.6
Use conda activate py35, conda deactivate, conda activate py36 to switch between your virtual environments.
I have a python 3.4 environment with very specific packages installed. Is there a straight forward way to create an anaconda environment will all the same packages without creating a python environment then manually installing the packages. e.g..
conda create -n myenv python=3.4
conda activate myenv
conda install beautifulsoup4==4.6.1
I'd like to do this as i want to share a python script and make it as easy as possible for others to run it.
These are all the packages installed in my python3.4 environment
'altgraph==0.16.1',
'asn1crypto==0.24.0',
'beautifulsoup4==4.6.1',
'certifi==2018.4.16',
'cffi==1.11.5',
'chardet==3.0.4',
'configargparse==0.13.0',
'cryptography==2.3',
'defusedxml==0.5.0',
'dis3==0.1.3',
'future==0.17.1',
'h5py==2.8.0',
'idna==2.7',
'jira==2.0.0',
'macholib==1.11',
'numpy==1.15.3',
'oauthlib==2.1.0',
'pbr==4.2.0',
'pefile==2018.8.8',
'pycparser==2.18',
'pyinstaller==3.4',
'pyjwt==1.6.4',
'pyqt4==4.11.4',
'pywin32-ctypes==0.2.0',
'pywin32==220',
'regex==2018.07.11',
'requests-oauthlib==1.0.0',
'requests-toolbelt==0.8.0',
'requests==2.19.1',
'six==1.11.0',
'urllib3==1.23',
'xmltodict==0.11.0'
conda-env is your friend:
conda-env export -n orig > orig.yml
where orig is the name of the environment you want to clone, followed by
conda-env create -n new -f=orig.yml
where new is the new name of the copy. The file orig.yml contains everything about the environment you want to copy: dependencies, installed packages incl. version, and such.
I want to create an anaconda python environment with all of the packages that Continuum includes in its default Anaconda installer. Based on some internet search I used the following command:
conda create -n env_full python=3
However, only handful of packages would be installed. Please see the screen shot.
Kindly guide me to use correct commands.
Right now I am trying to do this on a desktop computer, but I would like to apply the same principles to the cluster facility.
To install all of the packages that Continuum includes in its default Anaconda installer, the simplest command is this:
conda create -n env_full anaconda
This will install the latest version of the anaconda package set, as compiled for your default version of Python (the one you used to install Anaconda originally). If you'd like to create an environment with a different version of Python, then just add that to the command line; e.g.
conda create -n env_full anaconda python=2.7
conda create -n env_full anaconda python=3.5
Anaconda ships with a root env, this is named as base. You can use this as it is or clone a new environment from it.
if you just want a environment with all the packages for day to day then you can use the base enviornment itself.
you can list the all available conda env on your machine as follows
conda info --env
you will see a enviornment name base, activate it to use it
source activate base
You can verify all the packages available in the env with following command ( This work with any env created with conda)
conda list -n base
As I said above if you want a different env then you can clone base using following command
conda create --name <env_name> --clone base
When I run this command:
conda create -n env_full anaconda>
I get a PackageNotFoundError. So I create a simple environment:
conda create -n env_full
and use this command to install all the anaconda default packages:
conda install anaconda