Pip 安装不断抛出奇怪的“ImportError”

Pip 安装不断抛出奇怪的“ImportError”

我一直在尝试使用 pip 安装一些软件包,但pyudev总是出现导入错误。我不知道为什么它只发生在 pyudev 中。它在我的另一台电脑上安装得很好。以下是命令和输出:

$ sudo pip install pyudev

Collecting pyudev
  Downloading pyudev-0.16.1.tar.gz (74kB)
    100% |################################| 77kB 882kB/s 
    Traceback (most recent call last):
      File "<string>", line 20, in <module>
      File "/tmp/pip-build-1Pk9rC/pyudev/setup.py", line 55, in <module>
    packages=setuptools.find_packages(),
      File "/usr/lib/python2.7/distutils/core.py", line 151, in setup
    dist.run_commands()
      File "/usr/lib/python2.7/distutils/dist.py", line 953, in run_commands
    self.run_command(cmd)
      File "/usr/lib/python2.7/distutils/dist.py", line 972, in run_command
    cmd_obj.run()
      File "<string>", line 12, in replacement_run
      File "/usr/local/lib/python2.7/dist-packages/pkg_resources/__init__.py", line 2310, in load
    return self.resolve()
      File "/usr/local/lib/python2.7/dist-packages/pkg_resources/__init__.py", line 2316, in resolve
    module = __import__(self.module_name, fromlist=['__name__'], level=0)
    ImportError: No module named version
    Complete output from command python setup.py egg_info:
    running egg_info

    creating pip-egg-info/pyudev.egg-info

    Traceback (most recent call last):

      File "<string>", line 20, in <module>

      File "/tmp/pip-build-1Pk9rC/pyudev/setup.py", line 55, in <module>

    packages=setuptools.find_packages(),

      File "/usr/lib/python2.7/distutils/core.py", line 151, in setup

    dist.run_commands()

      File "/usr/lib/python2.7/distutils/dist.py", line 953, in run_commands

    self.run_command(cmd)

      File "/usr/lib/python2.7/distutils/dist.py", line 972, in run_command

    cmd_obj.run()

      File "<string>", line 12, in replacement_run

      File "/usr/local/lib/python2.7/dist-packages/pkg_resources/__init__.py", line 2310, in load

    return self.resolve()

      File "/usr/local/lib/python2.7/dist-packages/pkg_resources/__init__.py", line 2316, in resolve

    module = __import__(self.module_name, fromlist=['__name__'], level=0)

    ImportError: No module named version

    ----------------------------------------
    Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-build-1Pk9rC/pyudev

更新:当我进一步挖掘时,我注意到在我的另一台计算机上它并没有尝试安装“版本”。

更新 2:嗯,我不知道为什么会发生这种情况,但这是 python-daemon 包的问题。这是另一个有同样问题的用户。https://stackoverflow.com/questions/27972349/installing-latest-python-daemon-2-0-3-breaks-subsequent-pip-installs

更新 3:刚刚意识到我忘了提到卸载 python-daemon 可以解决问题。这是一个旧的依赖项,我不再需要它。最新版本导致了这个问题。

答案1

首先尝试升级 pip 本身。

pip install -U pip

相关内容