【问题标题】:How to install Pandas and dependencies without pip or any package manager如何在没有 pip 或任何包管理器的情况下安装 Pandas 和依赖项
【发布时间】:2019-01-21 12:40:23
【问题描述】:

我的公司 linux 开发环境没有安装 pip 或任何包管理器。 我如何在没有 pip/包管理器的情况下安装或使用 pandas 包和依赖项,如 numpy 等。

【问题讨论】:

    标签: python-2.7 pandas numpy


    【解决方案1】:

    您可以在沙盒上使用python wheels 进行本地安装(您将使用该目录将这些库与您的生产 东西分开)并通过在您的@ 上添加此路径来启用它987654329@.

    实际上,wheel 基本上是 .ZIP 文件,其中包含已为您的平台(Python 版本、操作系统和 CPU 架构)编译的具有本机依赖项(例如从 C 源代码生成的目标文件)的 python 包。

    首先要做的是创建一个单独的目录来保存包:

    mkdir -p /full/path/to/my/pandas_sandbox
    

    访问 PyPI 网站并下载 Pandas 及其依赖项:

    您会注意到其中一些,即 Pandas 和 Numpy,有很多选择。

    在选择包时,特别是对于 Pandas 和 Numpy,您需要考虑到 wheel naming convention,因此请确保您获得与您的 python 版本和 CPU 架构相匹配的轮子。

    例如,如果您需要在 x86_64 上运行的 Linux 上针对 Python 2.7 的 Pandas,请选择 pandas-0.23.3-cp27-cp27mu-manylinux1_x86_64.whl(注意 cp27manylinux1x86_64)。

    确定您的目标平台并下载 Pandas 和 Numpy 的特定版本。

    一旦你有了包(.whl 文件),将它们解压缩到沙箱目录中,根据我使用当前有效版本的实验,你最终会得到:

    .
    ├── dateutil
    ├── numpy
    ├── numpy-1.15.0.data
    ├── numpy-1.15.0.dist-info
    ├── pandas
    ├── pandas-0.23.3.dist-info
    ├── pytz
    ├── pytz-2018.5.dist-info
    ├── six-1.11.0.dist-info
    └── six.py
    

    现在,添加沙盒目录的路径PYTHONPATH

     export PYTHONPATH=/full/path/to/my/pandas_sandbox
    

    这将使/full/path/to/my/pandas_sandbox 下的包对python可见,因此您可以将它们作为已安装的依赖项使用和导入。

    例子:

    $ export PYTHONPATH=/full/path/to/my/pandas_sandbox
    $ python
    Python 2.7.12 (default, Dec  4 2017, 14:50:18) 
    [GCC 5.4.0 20160609] on linux2
    Type "help", "copyright", "credits" or "license" for more information.
    >>> import pandas
    >>> pandas.__file__
    '/full/path/to/my/pandas_sandbox/pandas/__init__.pyc'
    >>> 
    

    注意事项:

    1) 请记住,这不是维护 Python 环境和依赖项的推荐方式。

    2) 请记住,export PYTHONPATH=/a/given/path 仅对当前 shell 会话有效,因此您可以在新 shell 上保持您的 python 安装干净。例如,您可以通过将此 export 添加到您的 .bashrc 来使其永久化。

    【讨论】:

    • 感谢您提供如此详细的解决方案。我会试试这个并更新。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-06-03
    • 1970-01-01
    • 2013-11-29
    • 2021-10-05
    • 1970-01-01
    • 1970-01-01
    • 2021-08-11
    相关资源
    最近更新 更多