Am I doing something wrong in my commands? I can't remove Keras.
$ conda remove --name myEnv keras
Collecting package metadata (repodata.json): done
Solving environment: failed
PackagesNotFoundError: The following packages are missing from the target environment:
- keras
$ conda list --name myEnv keras
# packages in environment at /Users/me/anaconda3/envs/myEnv:
#
# Name Version Build Channel
keras 2.3.1 pypi_0 pypi
The channel pypi for keras means you have mix used pip and conda. To uninstall the keras installed from pypi, use pip.
pip uninstall keras
It's not a good idea to mix use both package managers pip and conda in one environment. If you really need to. Read the official guide Using Pip in a Conda Environment.
conda remove --force (the rest of the command)
Pip Interoperability
As #Simba correctly identified, the package is from PyPI (i.e., it was installed via pip). By default, Conda can recognize the presence of such packages but will not interact with them. However, there is a "preview" configuration option, pip_interop_enabled, that enables such interaction (see Conda v4.6 Release Notes). You could either
Set this option globally:
conda config --set pip_interop_enabled true
conda remove --name myEnv keras
If you have PyPI packages generally, then this should help improve your env stability, but at the cost of slightly longer solve times, since now Conda will account for packages coming from PyPI.
Temporarily turn it on just for this operation
CONDA_PIP_INTEROP_ENABLED=1 conda remove --name myEnv keras
Related
i have dask, dask-core and dask geopandas installed as shown:
dask 2021.7.1 pyhd8ed1ab_0 conda-forge
dask-core 2021.7.1 pyhd8ed1ab_0 conda-forge
dask-geopandas 0.1.0a4 pypi_0 pypi
however, when importing I kept getting an error message :
"ModuleNotFoundError: No module named 'dask_geopandas'"
I wonder what has gone wrong with installation, thank you.
This could happen if pip install and conda install installed packages in different paths (this typically happens when the conda environment does not have its own pip).
A simple way out of this is to install everything with conda, so in this case you would run the following within your conda environment:
conda install -c conda-forge dask dask-geopandas
Alternatively, make sure that your conda environment has pip installed also and then run the pip within the conda environment:
conda install -c conda-forge dask pip
# if the conda environment is not activate, then activate it
# using: conda activate the_name_of_your_env
pip install dask-geopandas
In addition, there are specific instructions at https://geopandas.readthedocs.io/en/latest/getting_started/install.html#installing-with-pip about extra steps you may need to take when using pip - you might need a compiler available in your system.
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.
I have created a conda environnmennt
and then pip installed tensorflow using a pip wheel. numpy was installed by pip at same stage.
When trying to install scipy,
conda wants to install numpy in parallel of pip installed numpy....?
How to make various installed be recognized by conda ?
This is what the new configuration option pip_interop_enabled, introduced in Conda v4.6 is for. It is still considered a "preview" feature, but I've had success using it:
conda config --set pip_interop_enabled true
Until this feature is released in earnest, I think it would be wise to limit its use to a per-env-basis by using the --env flag when running the above.
It should be kept in mind that preferring Conda packages is still best practice. A must read in this regard is "Using Pip in a Conda Environment".
Objective: Create a conda environment with pytorch and torchvision. Anaconda Navigator 1.8.3, python 3.6, MacOS 10.13.4.
What I've tried:
In Navigator, created a new environment. Tried to install pytorch and torchvision but could not because the UI search for packages does not find any packages available matching pytorch, torch, torchvision, or similar strings.
conda install pytorch torchvision -c pytorch
conda update --all
pytorch 0.3.1, torch 0.3.1, and torchvision 0.2.0 now appear as installed in the root environment. However, the root environment is no longer cloneable; the clone button is gray/disabled (it used be enabled/cloneable). I could use the root environment as a fallback but the main point of conda is to be able to create separate and disposable environments. What am I missing?
UPDATE -----------------
Running conda install -c pytorch pytorch yields:
# All requested packages already installed. But if I activate the pytorch environment and list the packages therein, there is no package containing the word "torch". If I then do conda search pytorch I get PackagesNotFoundError: The following packages are not available from current channels: - pytorch. If I activate the base environment and then do conda list then pytorch is in the package list for base. So how does one create a separate environment containing pytorch?
You seem to have installed PyTorch in your base environment, you therefore cannot use it from your other "pytorch" env.
Either:
directly create a new environment (let's call it pytorch_env) with PyTorch: conda create -n pytorch_env -c pytorch pytorch torchvision
switch to the pytorch environment you have already created with: source activate pytorch_env and then install PyTorch in it: conda install -c pytorch pytorch torchvision
I struggled with this and was reminded to RTFM (Read The F'ing Manual) documentation...
See Verify the installation with import torch not pytorch. which is from Pytorch
Which one should I use to install keras if I have anaconda?
conda install -c conda-forge keras
&
pip install --upgrade keras
Also, what is conda-forge? Why need to do it this way?
The advantages of using conda rather than pip to install packages in your Anaconda environment(s) are that:
conda should determine what dependencies your requested package has, and install those too in one operation, and
you can then keep the installed packages up to date using the conda update command:
pip, PyPI, and setuptools?
None of this is going to help with updating packages that have been
installed from PyPI via pip, or any packages installed using python
setup.py install. conda list will give you some hints about the
pip-based Python packages you have in an environment, but it won’t do
anything special to update them.
The conda-forge channel is where you can find packages that have been built for conda but are not part of the official Anaconda distribution (yet).
See answers to this question for more detail on the two options (although bear in mind some of the answers may be out of date).