简体   繁体   English

为什么 python 包使用 __version__ 和 pip (同一目录)显示不同的版本

[英]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.因此,看起来这不是包的错误,而是一个很好的例子,说明为什么你应该小心不要在同一个环境中随意混合condapip命令。 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.

相关问题 Python package(tensorflow)显示pip列表和.__version__ZD148E6221F39893之间的版本不匹配 - Python package (tensorflow) displays mismatching versions between pip list and .__version__ output 给定 Python 的维护版本,pip 是否共享相同版本的包? - Does pip share the same versions of a package given a maintenance version of Python? 使用 pip 将 Python package 安装到不同的目录中? - Install a Python package into a different directory using pip? 为什么pip会根据python版本升级到不同版本? - Why does pip upgrade to different versions depending on python version? pip list和sudo pip list显示了不同的包版本 - pip list and sudo pip list shows different package versions 为什么pip为相同版本的同一软件包安装不同的二进制文件? - Why is pip installing different binaries for the same version of the same package? Pip 列出与 Python 版本不兼容的包版本 - Pip lists versions of the package incompatible with the version of Python pip3 版本安装 package 到不同的目录 - pip3 version installing package into different directory 使用Pip将Test Python软件包安装在其他目录中 - Install Test Python Package in Different directory Using Pip 如果未设置 __version__ 变量,如何检查 python 包的版本 - How to check version of python package if no __version__ variable is set
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM