[英]Why a python package shows different versions using __version__ and pip (same directory)
I have carefully checked the environment, and the two methods shows the same package directory:我仔细检查了环境,两种方法显示同一个包目录:
>>> !pip show astropy
Name: astropy
Version: 5.1
Summary: Astronomy and astrophysics core library
Home-page: http://astropy.org/
Author: The Astropy Developers
Author-email: astropy.team@gmail.com
License: BSD 3-Clause License
Location: /home/duhc/anaconda3/lib/python3.9/site-packages
Requires: packaging, numpy, PyYAML, pyerfa
Required-by: sdss-marvin, photutils, mgefit, gwcs
>>> import astropy
>>> print(astropy.__version__)
>>> print(astropy.__path__)
4.3.1
['/home/duhc/anaconda3/lib/python3.9/site-packages/astropy']
We see, the directories are the same, both are /home/duhc/anaconda3/lib/python3.9/site-packages
, while the versions are different.我们看到,目录是一样的,都是/home/duhc/anaconda3/lib/python3.9/site-packages
,而版本不同。
This does not happen in a fresh environment:这不会发生在新鲜的环境中:
$>conda create -n astropy python=3.9.7 astropy=5.1
$>conda activate astropy
$>pip show astropy
Name: astropy
Version: 5.1
Summary: Astronomy and astrophysics core library
Home-page: http://astropy.org
Author: The Astropy Developers
Author-email: astropy.team@gmail.com
License: BSD 3-Clause License
Location: ...\miniconda3\envs\astropy\lib\site-packages
Requires: numpy, packaging, pyerfa, PyYAML
Required-by:
$>python -c "import astropy; print(astropy.__version__)"
5.1
Also does not happen when the package is installed from pypi从 pypi 安装软件包时也不会发生
$>conda uninstall astropy
$>pip install astropy
$>python -c "import astropy; print(astropy.__version__)"
5.1
$>pip show astropy
Name: astropy
Version: 5.1
Summary: Astronomy and astrophysics core library
Home-page: http://astropy.org
Author: The Astropy Developers
Author-email: astropy.team@gmail.com
License: BSD 3-Clause License
Location: ...\miniconda3\envs\astropy\lib\site-packages
Requires: numpy, packaging, pyerfa, PyYAML
Required-by:
What probably happened is that you overwrote a pip installed package with conda.可能发生的事情是你用 conda 覆盖了一个 pip 安装的包。 Complete steps to reproduce:完整的重现步骤:
$> conda create -n astropy python=3.9.7
$> conda activate astropy
$> pip install astropy
$> pip show astropy
Name: astropy
Version: 5.1
Summary: Astronomy and astrophysics core library
Home-page: http://astropy.org
Author: The Astropy Developers
Author-email: astropy.team@gmail.com
License: BSD 3-Clause License
Location: ...\miniconda3\envs\astropy\lib\site-packages
Requires: numpy, packaging, pyerfa, PyYAML
Required-by:
$> conda install astropy==4.3.1
$> pip show astropy
Name: astropy
Version: 5.1
Summary: Astronomy and astrophysics core library
Home-page: http://astropy.org
Author: The Astropy Developers
Author-email: astropy.team@gmail.com
License: BSD 3-Clause License
Location: ...\miniconda3\envs\astropy\lib\site-packages
Requires: numpy, packaging, pyerfa, PyYAML
Required-by:
$> python -c "import astropy; print(astropy.__version__)"
4.3.1
Therefore it looks like this is not a bug of the package, but rather a good example of why you should be careful to not mix conda
and pip
commands in the same environment without care.因此,看起来这不是包的错误,而是一个很好的例子,说明为什么你应该小心不要在同一个环境中随意混合conda
和pip
命令。 I would especially advice against doing so in your base environment (personally, I would not change the base env at all, except for updates).我特别建议不要在您的基础环境中这样做(就个人而言,我根本不会更改基础环境,除了更新)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.