【问题标题】:installing cPickle with python 3.5使用 python 3.5 安装 cPickle
【发布时间】:2016-09-05 02:23:13
【问题描述】:

这可能很愚蠢,但我无法使用 python 3.5 docker 映像安装 cPickle

Dockerfile

FROM python:3.5-onbuild

requirements.txt

cpickle

当我尝试构建图像时

$ docker build -t sample .
Sending build context to Docker daemon 3.072 kB
Step 1 : FROM python:3.5-onbuild
# Executing 3 build triggers...
Step 1 : COPY requirements.txt /usr/src/app/
Step 1 : RUN pip install --no-cache-dir -r requirements.txt
 ---> Running in 016c35a032ee
Collecting cpickle (from -r requirements.txt (line 1))
  Could not find a version that satisfies the requirement cpickle (from -r requirements.txt (line 1)) (from versions: )
No matching distribution found for cpickle (from -r requirements.txt (line 1))
You are using pip version 7.1.2, however version 8.1.1 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
The command '/bin/sh -c pip install --no-cache-dir -r requirements.txt' returned a non-zero code: 1

【问题讨论】:

    标签: python docker pickle python-3.5


    【解决方案1】:

    cPickle 带有标准库……在 python 2.x 中。你在 python 3.x 上,所以如果你想要cPickle,你可以这样做:

    >>> import _pickle as cPickle
    

    但是,在 3.x 中,使用 pickle 会更容易。

    无需安装任何东西。如果某些东西在 python 3.x 中需要cPickle,那么这可能是一个错误。

    【讨论】:

    • 啊! _pickle 是 python 3.x 中 cPickle 的替代品吗?或pickle 会一样快吗?
    • 是的,而且pickle使用_pickle,所以速度也很快,可以处理子类。
    • 我正在使用 Python 3.6.6,并尝试了所有方法:将 pickle 导入为 cPickle,导入 pickle,将 _pickle 导入为 cPickle,但仍然出现错误“ModuleNotFoundError: No module named 'cPickle'”
    • @pari:我认为您在上面的评论中详述的三个导入语句不会产生特定的错误。也许您应该进一步调查,并可能会问一个新的 SO 问题,如果它确实是一些新问题或您遇到的一些错误。
    • 在 Python 2 中,cPickle 是 pickle 的加速版本,后来添加到标准库中。导入它并回退到泡菜是完全正常的。在 Python 3 中集成了加速版本,除了import pickle 之外,没有理由使用其他任何东西。
    【解决方案2】:

    python 2 和 3 都可以使用它

    try:
      import cPickle as pickle
    except:
      import pickle
    

    【讨论】:

      猜你喜欢
      • 2018-09-09
      • 1970-01-01
      • 1970-01-01
      • 2016-10-16
      • 2015-09-10
      • 2016-11-10
      • 2016-06-20
      • 2016-08-02
      • 1970-01-01
      相关资源
      最近更新 更多