簡體   English   中英

為什么 python 包使用 __version__ 和 pip (同一目錄)顯示不同的版本

[英]Why a python package shows different versions using __version__ and pip (same 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']

我們看到,目錄是一樣的,都是/home/duhc/anaconda3/lib/python3.9/site-packages ,而版本不同。

這不會發生在新鮮的環境中:

$>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

從 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:

可能發生的事情是你用 conda 覆蓋了一個 pip 安裝的包。 完整的重現步驟:

$> 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

因此,看起來這不是包的錯誤,而是一個很好的例子,說明為什么你應該小心不要在同一個環境中隨意混合condapip命令。 我特別建議不要在您的基礎環境中這樣做(就個人而言,我根本不會更改基礎環境,除了更新)。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM