Install packages into existing conda environment specified in environment.yml - macos

I have anaconda environment called 'juldou_learning'.
I downloaded from Git a project with environment.yml inside.
I don't want to create new environment with environment.yml like:
conda env create -f environment.yml
but, only install packages to juldou_learning which are present in environment.yml file.
following does not work:
(juldou_learning) MBPuzivlaJulius:juldou_learning juldou$ conda install --file environment.yml
CondaValueError: could not parse 'name: juldou_learning' in: environment.yml

You can use the env command
conda env update --file environment.yml
You may need to activate the environment into which the packages are going to be installed first.

Like #darthbith said, use conda-env update, but don't forget to name the environment you want to install the packages into. If the environment.yml file contains an environment name, your packages will get installed there, regardless of which environment is currently activated. Here's how to name the target environment name:
conda env update --name environment_name --file environment.yml
Of course there are short argument names for --name and --file. To install the environment.yml packages in my base conda environment (the one that's activated if you haven't activated any others) I had to:
conda env update -n base -f environment.yml

Related

Conda create and conda install

I have used anaconda and miniconda without problem before so I don't know why I am having doubts now about the order to use them as
create an environment with conda create
Activate the environment with conda activate
Install packages with conda install
However, lately I have read one set of instructions in which they do a different order: 1->3->2. That means installing without activating and then activating.
Is this correct? Aren't I installing libraries outside of the environment?
There are multiple ways to create and install packages using conda.
create an environment, activate, install packages
conda create --name env_name python=3.8
conda activate env_name
conda install package_name another_package
create an environment with packages
conda create -n env_name python=3.8 package_name another_package
conda activate env_name
Both methods are correct. In fact, we often use a mix here and there. For example, if I have a project with requirements.txt to be installed with pip but would like it to have pandas and scikit-learn from conda-forge. I will do:
conda create --name ml_api python=3.7 -c conda-forge scikit-learn pandas
conda activate ml_api
python -m pip install -r requirements.txt
At any point, we can add packages in conda environment with
# this will install requests to ml_api env. This can be done at any (env)
conda install --name ml_api requests
# or activate ml_api and install. This will install on activated env
conda activate ml_api
conda install requests
At the end of the day, conda is there to help you. A better flow will depend on your need.
The order you listed them is correct but you only need the conda install packagename before you run the code. So you should first create the conda environment and then activate it. Now when you get ready to run the code the first time, be sure to install your package. This enables you to import the package in your python code.

Trying to replace Pip with Conda in a conda template repo

Working in a conda template repo on GitLab. Looking to replace pylint with flake8 in the gitlab CI, and install using conda instead of pip. Swap pip install flake8 with conda install flake8 and getting ther erroe that #command conda not found" after I push and view the pipeline. Any ideas why this might be?
You can use conda like this in Gitlab
image: continuumio/miniconda3:latest
before_script:
- conda env create -f environment.yml
- source activate koopa
tests:
stage: test
script:
- python -m unittest discover -v

Does conda env export use pip?

I successfully created a Conda environment at path ./xxxxx/conda_env/xyz. I am also able to activate that environment.
However, conda env export -p /xxxxx/conda_env/xyz fails (I have the same environment activated), giving error
Traceback (most recent call last):
File "/xxxxx/conda_env/xyz/bin/pip", line 7, in <module>
from pip._internal.cli.main import main
ModuleNotFoundError: No module named 'pip._internal.cli'
Does conda env export uses pip? If so, why?
P.S. I do have pip installed
$ conda list --explicit | grep pip
http://anaconda:8080/conda/anaconda/linux-64/pip-20.0.2-py36_1.tar.bz2
Your command doesn't make sense:
conda env export -p /xxxxx/conda_env/xyz
should probably be
conda env export -p /xxxxx/anaconda3/envs/conda_env
But it seems this command is deprecated anyhow. According to Exporting the environment.yml file your should instead use
conda activate conda_env
conda env export > environment.yml
However, it's totally fine to pip install packages from pypi.org into a conda environment that are not available on anaconda.org. And ideally pip packages should also end up in the environments.yml like
name: conda_env
channels:
- default
dependencies:
- python=3.8
- pip:
- tables
So no surprise that pip is involved here.

Spyder not starting AttributeError: module 'asycio' has no attribute 'WindowsSelectorLoopPolicy'

I activate my environment and launch from the conda command line
> activate myenv
> spyder
but I get this error:
Please help
I had to remove my environment conda remove -n envname --all and then conda create -n envname followed by activate envname then conda install -c anaconda spyder.
Seems that there is an issue with my old environments and a recent update I performed.
Now I have to just install the rest of the packages into this environment as clone from previous one wont even allow spyder4 to be installed.

How to add package to conda environment without pip

How can I add a package to an existing conda environment?
If it is a python package I can use pip install <package>, but what if pip does not work?
Is it sufficient to activate the environment and use conda install <package>?
You've answered your own question. In fact you really want to do conda install ... instead of using pip if you can.
You can install a conda package also without activating the environment. Just use conda install -n <env_name> <package> or conda install -p <path/to/env> <package>.
If you want to install a specific package inside a specific conda environment, you can use the following command.
First activate the conda environment and then do:
$ conda install --name <conda_env_name> -c <channel_name> <package_name>
For a concrete example, let's assume that you want to install chainer from the channel anaconda to an already created conda environment named chainerenv, then you can do:
$ conda install --name chainerenv -c anaconda chainer
If you want to install a package in the environment, you can use
conda install -p /path/to/env package
example:
conda install -p /users/dekstop/env-test Django
There's an alternative way to do this and I have just tested it on my own mac:
example: i want to install a non-conda package at my python2.7 environment:
go to terminal
activate the desired environment by: source activate py27
after you successfully activated the environment, you can install the package you wanted by: pip install package
The answer is yes (usually).
One example is that you can activate your conda environment and then directly do conda install pandas.tar.bz2 on the existing tar.bz2 files from /conda_envs/.pkgs (leftovers from other environments)
If you don't have a tarball package like that but you have the src with setup.py you can just do the usual install by python setup.py install (or python setup.py develop to link the src)

Resources