【问题标题】:How to force import use the pip library instead of conda library?如何强制导入使用 pip 库而不是 conda 库?
【发布时间】:2021-11-29 19:58:18
【问题描述】:

以下命令显示我的机器中有两个 numpy。

bash-4.2$ conda list numpy
# packages in environment at /app/anaconda3:
#
# Name                    Version                   Build  Channel
numpy                     1.15.0           py36h1b885b7_0    https://mycompany.intranet/repository/anaconda-main-proxy
numpy-base                1.15.0           py36h3dfced4_0    https://mycompany.intranet/repository/anaconda-main-proxy

bash-4.2$ pip list | grep numpy
numpy (1.19.5)
numpydoc (1.1.0)

导入pandas时出现如下错误。

>>> import pandas
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/app/anaconda3/lib/python3.6/site-packages/pandas/__init__.py", line 22, in <module>
    from pandas.compat.numpy import (
  File "/app/anaconda3/lib/python3.6/site-packages/pandas/compat/numpy/__init__.py", line 21, in <module>
    "this version of pandas is incompatible with numpy < 1.15.4\n"
ImportError: this version of pandas is incompatible with numpy < 1.15.4
your numpy version is 1.15.0.
Please upgrade numpy to >= 1.15.4 to use this pandas version

有没有办法让import pandas使用numpy的pip版本,哪个版本是1.19.5? conda频道是公司内部频道,版本较旧。

【问题讨论】:

  • 你必须使用你系统的python而不是conda版本。
  • 系统的python是v2.7,我必须使用conda版本是V3.6

标签: python pip anaconda


【解决方案1】:

您可以使用另一个Conda channel 来安装更新版本的pandasnumpy

例如,您可以使用conda-forge channel:

conda config --add channels conda-forge

使用新的 Conda 环境并安装 pandas

conda install pandas --channel conda-forge

conda-forge的包信息:pandasnumpy


或者,为 Python 3.x 创建和使用 virtual environment using venv 或为 Python 2.7 创建和使用 virtualenv,并使用 pip 安装所有需要的包。以venv 为例:

cd YOUR_PROJECT_ROOT
python -m venv env
source env/bin/activate
pip install pandas

另见:https://packaging.python.org/guides/installing-using-pip-and-virtual-environments


或者,将pandas 降级到使用numpy 1.15.0 的版本。

【讨论】:

    猜你喜欢
    • 2023-04-04
    • 2012-11-02
    • 2019-04-06
    • 2011-05-24
    • 2022-11-20
    • 2011-02-26
    • 2019-08-25
    • 2020-04-07
    • 2019-10-20
    相关资源
    最近更新 更多