Prevent conda from automatically downgrading python package

不羁岁月 提交于 2021-01-29 10:04:37

问题


I had problems with pandas-datareader package v0.81. To fix my problem, I had to upgrade the package to a newer version 0.9 by running the following command;

conda install -c anaconda pandas-datareader

Unfortunately, when I tried to upgrade conda packages later using the command conda update --all, pandas-datareader is downgraded back to v0.81. v0.81 is from conda-forge channel. What I want is the v0.9 from anaconda channel.

Below is what I want.

https://anaconda.org/anaconda/pandas-datareader

Below is not what I want

https://anaconda.org/conda-forge/pandas-datareader

How do I force conda to always upgrade pandas-datareader to the latest version in anaconda channel when I run conda update --all?

I am using python anaconda 2020_07 version on Windows 10.


回答1:


Specify Minimum Version

Conda is sufficiently powerful to parse minimum versions, and it remembers that they've been specified. If you would prefer 0.9 as the minimum, then you just need to say so with

conda install 'pandas-datareader>=0.9'

or

conda install pandas-datareader[version='>=0.9']

Once you've run this, it will be added into your explicit specifications,1 and that should lock in at least that version of pandas-datareader, including in subsequent conda update --all runs.2 This answer has a fuller description of Conda's MatchSpec system, which covers the scope of what can be specified.

Channel Specifications

Although this isn't what OP effectively wants, it may be worth elaborating why the channel switching happened and how a channel can also be explicitly specified. The --channel|-c flag only adds (and prioritizes) a channel during the command it is used with. It does not tell Conda that a particular package should come from that channel. Hence, since OP likely has conda-forge prioritized over defaults in their global/user configuration (see conda config --show channels), running conda update --all will simply switch back to whatever the most recently uploaded build is.

To explicitly indicate that a package should come from a channel, one should instead use

conda install anaconda::pandas-datareader

This will then add anaconda::pandas-datareader into the explicit specifications, and that should lock in the fact that one expects pandas-datareader to come from the anaconda channel.

Package Pinning

Otherwise, package pinning could be another option.


[1] One can check explicit specifications with conda env export --from-history.

[2] Be aware that some flags may override explicit specifications without warning, such as --update-deps.



来源:https://stackoverflow.com/questions/65385983/prevent-conda-from-automatically-downgrading-python-package

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!