python - pip install pickle 不工作 - 没有这样的文件或目录

标签 python linux bash python-3.x pip

Ubuntu 16.04 LTS,尝试用 pip 安装 cpickle。我搜索了一下,还没有找到任何有用的东西。

未设置 PYTHONPATH。

错误信息

user@hostname:~$ sudo -H pip3 install cpickle
Collecting cpickle
  Using cached cpickle-0.5.tar.gz
    Complete output from command python setup.py egg_info:
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/usr/lib/python3.5/tokenize.py", line 454, in open
        buffer = _builtin_open(filename, 'rb')
    FileNotFoundError: [Errno 2] No such file or directory: '/tmp/pip-build-wn926hef/cpickle/setup.py'

    ----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-build-wn926hef/cpickle/
You are using pip version 8.1.1, however version 9.0.1 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.


    ----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-build-q46tq1l8/cpickle/
You are using pip version 8.1.1, however version 9.0.1 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.

故障排除步骤

# version info
user@hostname:~$ python --version
Python 2.7.12
user@hostname:~$ python3 --version
Python 3.5.2

# I don't think cache is the problem
rm -rf ~/.cache/
sudo -H pip install  cpickle --no-cache-dir # same problem
sudo -H pip3 install  cpickle --no-cache-dir # same problem

最佳答案

在网上查了一下,发现了这个

enter image description here

A common pattern in Python 2.x is to have one version of a module implemented in pure Python, with an optional accelerated version implemented as a C extension; for example, pickle and cPickle.

This places the burden of importing the accelerated version and falling back on the pure Python version on each user of these modules. In Python 3.0, the accelerated versions are considered implementation details of the pure Python versions.

Users should always import the standard version, which attempts to import the accelerated version and falls back to the pure Python version. The pickle / cPickle pair received this treatment. The profile module is on the list for 3.1. The StringIO module has been turned into a class in the io module.

这意味着在 Python3 中它作为一个库出现...

import _pickle as cPickle

更新

正如 Invapid 在下面的评论中所说,这个与上面的答案类似

from six.moves import cPickle

关于python - pip install pickle 不工作 - 没有这样的文件或目录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43550407/

相关文章:

bash - 无法运行 tar 命令 - 无效选项 -- '▒'

python 3 : using "all" on class variables

android - 如何创建 APK 但不运行它

linux - 判断卷是否安装在 ec2 实例上

linux - 交叉编译 FTDI VCP Driver for embedded linux arm

python - 检查进程是否仍在运行

python - 带有可选参数的方法的 assertRaises

python - django.db.utils.OperationalError : FATAL: Peer authentication failed for user "deadlylaid"

python - 使用 @patch 装饰器模拟类属性

linux - 什么可以解释 [blastall] ERROR : Arguments must start with '-' error?