Cannot update python package on anaconda to latest version - python

Some of my python packages on anaconda cannot be updated to the latest version.
For instance, beautifulsoup4 latest version on anaconda is v4.71 as seen in the release notes.
https://docs.anaconda.com/anaconda/reference/release-notes/
However, when I run conda update beautifulsoup4, the latest version that I can update to is v4.6.
I discovered that the channel used by beautifulsoup4 is pypi.
# Name Version Build Channel
beautifulsoup4 4.6.0 pypi_0 pypi
bleach 3.1.0 py_0 conda-forge
I suspect if I were to change the channel from pypi to conda-forge, I should be able to update to the latest version.
How can I change the channel from pypi to conda-forge? Or does the solution lies somewhere else?
I am using Windows 10 64-bit, python 3.7.

I was running through this problem myself.
Let's take a look at versions in conda-forge and PyPi:
Conda Forge
PyPi
Both are actually up to date. So the problem here isn't as much the channels but conda mixing up the reference for the labels.
Update conda with
conda update
This will actually spew out a message telling you to run the command with a prefix for the proper path for your environment. Should be something like this:
conda update --prefix C:\Users\yourAccount\AppData\Local\Continuum\anaconda3 anaconda
Run that and it will update packages as well, including beautifulsoup4.
After this, you'll notice that creating new environment with just conda install beautifulsoup4 will return you the latest version.
Another curious thing to notice is that
There aren't distributions of 4.7 for Win-32 or Linux-32. So, if you are on either of those, updating conda won't help. You'll have to get the source code and build it yourself (if it is even possible).

Related

"torch" and "pytorch" version mismatch in conda

I installed the following in an environment:
cudatoolkit=11.3
pytorch=1.11.0
torchvision=0.12.0
But when asking for the torch/cuda version I get this:
$ python3 -c "import torch; print(torch.__version__)"
1.12.1+cu102
Which is not what I want (1.12.1 would be fine, but cu102 is too old). Looking further, I see this:
$ conda list torch
# packages in environment at /home/ml/anaconda3/envs/ldm:
#
# Name Version Build Channel
pytorch 1.11.0 py3.8_cuda11.3_cudnn8.2.0_0 pytorch
pytorch-lightning 1.4.2 pypi_0 pypi
pytorch-mutex 1.0 cuda pytorch
torch 1.12.1 pypi_0 pypi
torch-fidelity 0.3.0 pypi_0 pypi
torchdiffeq 0.2.3 pypi_0 pypi
torchmetrics 0.6.0 pypi_0 pypi
torchvision 0.12.0 py38_cu113 pytorchcode
So "pytorch" has the version I want (with cuda11.3), but "torch" is 1.12.1. Why? Moreover, "torch" does not seem to be a conda package (PackagesNotFoundError when trying to install), which is surprising since it appears in "conda list".
There is clearly something I do not understand about conda / pytorch. Can someone please explain it?
From what I know, the torch package uses the LuaRocks Package manager. And if you use it mostly in python, you should aim for 'PyTorch', which conda only takes care of.
For your case, I strongly suggest you create a new environment and start again installing PyTorch and it's components from the beginning. Read this compatibility matrix and try to install it according to those tables.
So in the end that "torch" fake (?) package was my previous install of pytorch and cuda (with pip). The conda install actually made the pip one not work anymore ("import torch" was not working outside of the environment). Which is even weirder since my understanding of virtual environment was that it should at the very least not affect what's outside.
The solution was to reinstall pytorch with pip (outside the environment). After that, "import torch" worked inside the environment. Which again is weird since conda installed his own version of pytorch, apparently not to use it in the end.
I consider this an "answer" as it solves the problem I was having, but I still don't understand why conda behaved this way.

conda install does not seem to have acces to latest package version

when i install keras on my conda environement it does not seem to install the latest version since i have 2.0.5 and itseems to be 2.0.8 (https://pypi.python.org/pypi/Keras)
when i run conda update keras i get the following error message :
# All requested packages already installed.
# packages in environment at /home/user/anaconda2/envs/conda_env:
#
keras 2.0.5 py36_0
same problem when i try to install keras-vis but then it does not exist at all so i have to do a pip-install that create double packages in my environement
Conda uses it's own repository of compiled binaries. The latest version available in the main channel "anaconda" is keras 2.0.5. If you use conda-forge you get access to 2.0.6.
Newer versions need to be installed over pip.
EDIT:
You can actually use this channel to get the newer version.

How to downgrade conda version?

I need to downgrade my conda version from 4.3 to 4.2 on my CentOS 6.7 machine.
What is the command required to do that?
I wouldn't recommend downgrading conda except when the newly installed (upgraded) version has a critical bug.
But since you asked: You can specify a version by appending ={version} to the packages, this works even for the conda package:
$ conda install conda=4.2
If you want a specific 4.2 version you can also use (for example):
$ conda install conda=4.2.15
Note that downgrading conda can be very risky. After the downgrade your conda could fail completely or work incorrectly. Conda uses a lot of metadata that evolve over time ... so if the downgraded conda version cannot make sense of these - or even worse corrupt them - you'll have a painful experience in how to recover your conda environemnt. Downgrade conda at your own risk (and in my opinion only if really, really necessary)!
In case you already downgraded conda and it's throwing exceptions (for example CondaUpgradeError) at you, then maybe this "section" in an troubleshooting guide in the conda repository may be useful:
Conda upgrade error
Cause
Downgrading conda from 4.6.1 to 4.5.x and then trying to conda install conda or conda upgrade conda will produce a solving and upgrade error similar to the following:
Solving environment: failed
CondaUpgradeError: This environment has previously been operated on by a
conda version that's newer than the conda currently being used. A newer
version of conda is required.
target environment location: /opt/conda
current conda version: 4.5.9
minimum conda version: 4.6
Solution
Change the .condarc file. Set the parameter by editing the .condarc file directly: allow_conda_downgrades: true in conda version 4.5.12. This will then let you upgrade. If you have something older than 4.5.12, install conda 4.6.1 again from the package cache.
EXAMPLE: If my conda info says package cache : /opt/conda/pkgs and my Python version is 3.7, then on the command line, type conda install /opt/conda/pkgs/conda-4.6.1-py37_0.tar.bz2 to resolve the issue.

Why some packages are upgradable in Pip, not in Conda? [duplicate]

This question already has answers here:
What is the difference between pip and conda?
(14 answers)
Closed 5 years ago.
I installed Anaconda under Windows 10. Everything is working fine. I also ran
conda upgrade --all
in a command prompt.
However, I noticed that when I type this in a command prompt:
pip list -o
I get (among other things)
astroid (1.4.7) - Latest: 1.4.8 [wheel]
This means package astroid is upgradable under pip. However, when I go to the Anaconda Navigator and look at the list of upgradable packages I do not see astroid in it. (I was not able to find a command line way of seeing which packages are upgradable under Conda).
Can someone explain why astroid appears as upgradable under Pip and not under Conda?
The package list maintained by Anaconda is different than that of PyPI. It seems that astroid is not yet updated in the Anaconda package list.
You can either wait until the update is available in Anaconda, or you can temporarily use the version available via pip by uninstalling the conda version and installing the pip one:
conda remove astroid
pip install astroid
When Anaconda has updated, reverse those two commands to switch back:
pip uninstall astroid
conda install astroid
It looks like Anaconda hasn't updated astroid yet - their package list shows it as only available for v1.4.7 (select Python 3.5 in the top tab and Ctrl+F astroid, or look on this page). However, astroid have updated the PyPI repository where Pip fetches packages from, so v1.4.8 is available through Pip and not through Anaconda.
As for why the package hasn't been upgraded - I'm not quite sure. There's been plenty of time since the release and there's no explanation why they wouldn't upgrade, so I can't really tell. Installing via pip should be fine if you need the latest version, though.

How to install PyPi packages using anaconda conda command

When using the Anacoda Python distribution, what is the best way to install a PyPi package that isn't available directly through Anaconda? For now I'm using:
conda pipbuild [pypi_name]
conda install --use-local [package_spec]
But I'm unclear if this is the best way and if conda update --all will update these packages when updates are made available. I'm also unclear what the point of binstar is when PyPi already exists.
I will disagree with the accepted response and note that pip install [some-pypi-package] is often the best way to install PyPi packages in Conda environments.
While the packages won't be managed by the Conda package manager, they will still be managed by the Anaconda environment. It will download the correct version of the package for the active Python install and update it correctly using the pip package manager.
When using Anaconda, you should turn to conda before pip when you can, but you don't lose any of the replicability benefits of using Anaconda when you use pip.
Anaconda recently published a doc that supports this: https://docs.conda.io/projects/conda/en/latest/user-guide/tasks/manage-environments.html#using-pip-in-an-environment
If you want to build conda packages for PyPI packages, the recommended way is to use conda skeleton pypi package and use conda build package on the recipe that it creates. To install the package, use conda install --use-local package (here and elsewhere, package is the name of the PyPI package you wish to install).
You will need to update the recipe each time the package is updated.
You can also use pip to install these packages. There are two disadvantages: firstly, these packages won't be managed by conda at all. Secondly, these packages will not work if your default python version is different from the python version you are using in conda.
Since version 4.6.0, Conda has improved its interoperability with pip:
Conda and pip have historically had difficulties getting along. Pip
hasn’t respected Conda’s environment constraints, while Conda has been
all too happy to clobber pip-installed software. It’s a mess. Conda
4.6.0 adds preview support for better interoperability. With this interoperability, Conda can use pip-installed packages to satisfy
dependencies, and can even remove pip-installed software cleanly and
replace them with Conda packages when appropriate. There’s still room
for improvement before pip and Conda are hunky-dory BFFs, but we hope
this is a good start. This feature is disabled by default right now
because it can significantly impact Conda’s performance. If you’d like
to try it, you can set this condarc setting:
conda config --set pip_interop_enabled True
So, the way to get PyPI packages into conda (at the time of writing this) seems to be:
pip install <package>
If you want conda to replace the PyPI packages with its own (where possible), just run:
conda update --all
Given that the above setting is made. Conda marks its own channels as higher priority than pip, thus packages will be replaced.
There is a caveat (thanks #alfalfasprout): Since conda did not install the pypi packages they are not included in conda export --from-history. You'd have to get the list (from conda or pip) and install these packages separately via pip, like you did originally. Thus, for people using the conda history functionality, there is at least a second step needed.

Categories