"The filename or extension is too long" 在安装 confluent-kafka 时?

"The filename or extension is too long" while installing confluent-kafka?

我在使用“pip install confluent-kafka”安装 confluent-kafka 时遇到了一些问题。但我收到此错误:“文件名或扩展名太长。”详情如下。

Collecting confluent-kafka
  Using cached confluent-kafka-1.8.2.tar.gz (104 kB)
  Preparing metadata (setup.py) ... done
Building wheels for collected packages: confluent-kafka
  Building wheel for confluent-kafka (setup.py) ... error
  error: subprocess-exited-with-error

  × python setup.py bdist_wheel did not run successfully.
  │ exit code: 1
  ╰─> [48 lines of output]
      running bdist_wheel
      running build
      running build_py
      creating build
      creating build\lib.win-amd64-3.10
      creating build\lib.win-amd64-3.10\confluent_kafka
      copying src\confluent_kafka\deserializing_consumer.py -> build\lib.win-amd64-3.10\confluent_kafka
      copying src\confluent_kafka\error.py -> build\lib.win-amd64-3.10\confluent_kafka
      copying src\confluent_kafka\serializing_producer.py -> build\lib.win-amd64-3.10\confluent_kafka
      copying src\confluent_kafka\__init__.py -> build\lib.win-amd64-3.10\confluent_kafka
      creating build\lib.win-amd64-3.10\confluent_kafka\admin
      copying src\confluent_kafka\admin\__init__.py -> build\lib.win-amd64-3.10\confluent_kafka\admin
      creating build\lib.win-amd64-3.10\confluent_kafka\avro
      copying src\confluent_kafka\avro\cached_schema_registry_client.py -> build\lib.win-amd64-3.10\confluent_kafka\avro
      copying src\confluent_kafka\avro\error.py -> build\lib.win-amd64-3.10\confluent_kafka\avro
      copying src\confluent_kafka\avro\load.py -> build\lib.win-amd64-3.10\confluent_kafka\avro
      copying src\confluent_kafka\avro\__init__.py -> build\lib.win-amd64-3.10\confluent_kafka\avro
      creating build\lib.win-amd64-3.10\confluent_kafka\kafkatest
      copying src\confluent_kafka\kafkatest\verifiable_client.py -> build\lib.win-amd64-3.10\confluent_kafka\kafkatest
      copying src\confluent_kafka\kafkatest\verifiable_consumer.py -> build\lib.win-amd64-3.10\confluent_kafka\kafkatest
      copying src\confluent_kafka\kafkatest\verifiable_producer.py -> build\lib.win-amd64-3.10\confluent_kafka\kafkatest
      copying src\confluent_kafka\kafkatest\__init__.py -> build\lib.win-amd64-3.10\confluent_kafka\kafkatest
      creating build\lib.win-amd64-3.10\confluent_kafka\schema_registry
      copying src\confluent_kafka\schema_registry\avro.py -> build\lib.win-amd64-3.10\confluent_kafka\schema_registry
      copying src\confluent_kafka\schema_registry\error.py -> build\lib.win-amd64-3.10\confluent_kafka\schema_registry
      copying src\confluent_kafka\schema_registry\json_schema.py -> build\lib.win-amd64-3.10\confluent_kafka\schema_registry
      copying src\confluent_kafka\schema_registry\protobuf.py -> build\lib.win-amd64-3.10\confluent_kafka\schema_registry
      copying src\confluent_kafka\schema_registry\schema_registry_client.py -> build\lib.win-amd64-3.10\confluent_kafka\schema_registry
      copying src\confluent_kafka\schema_registry\__init__.py -> build\lib.win-amd64-3.10\confluent_kafka\schema_registry
      creating build\lib.win-amd64-3.10\confluent_kafka\serialization
      copying src\confluent_kafka\serialization\__init__.py -> build\lib.win-amd64-3.10\confluent_kafka\serialization
      creating build\lib.win-amd64-3.10\confluent_kafka\avro\serializer
      copying src\confluent_kafka\avro\serializer\message_serializer.py -> build\lib.win-amd64-3.10\confluent_kafka\avro\serializer
      copying src\confluent_kafka\avro\serializer\__init__.py -> build\lib.win-amd64-3.10\confluent_kafka\avro\serializer
      running build_ext
      building 'confluent_kafka.cimpl' extension
      creating build\temp.win-amd64-3.10
      creating build\temp.win-amd64-3.10\Release
      creating build\temp.win-amd64-3.10\Release\Users
      creating build\temp.win-amd64-3.10\Release\Users\Among
      creating build\temp.win-amd64-3.10\Release\Users\Among\AppData
      creating build\temp.win-amd64-3.10\Release\Users\Among\AppData\Local
      creating build\temp.win-amd64-3.10\Release\Users\Among\AppData\Local\Temp
      creating build\temp.win-amd64-3.10\Release\Users\Among\AppData\Local\Temp\pip-install-e4mpsn3s
      creating build\temp.win-amd64-3.10\Release\Users\Among\AppData\Local\Temp\pip-install-e4mpsn3s\confluent-kafka_a53471ea97464e83aa35d4164a2c7040
      creating build\temp.win-amd64-3.10\Release\Users\Among\AppData\Local\Temp\pip-install-e4mpsn3s\confluent-kafka_a53471ea97464e83aa35d4164a2c7040\src
      creating build\temp.win-amd64-3.10\Release\Users\Among\AppData\Local\Temp\pip-install-e4mpsn3s\confluent-kafka_a53471ea97464e83aa35d4164a2c7040\src\confluent_kafka
      error: could not create 'build\temp.win-amd64-3.10\Release\Users\Among\AppData\Local\Temp\pip-install-e4mpsn3s\confluent-kafka_a53471ea97464e83aa35d4164a2c7040\src\confluent_kafka': The filename or extension is too long
      [end of output]

  note: This error originates from a subprocess, and is likely not a problem with pip.
  ERROR: Failed building wheel for confluent-kafka
  Running setup.py clean for confluent-kafka
Failed to build confluent-kafka
Installing collected packages: confluent-kafka
  Running setup.py install for confluent-kafka ... error
  error: subprocess-exited-with-error

  × Running setup.py install for confluent-kafka did not run successfully.
  │ exit code: 1
  ╰─> [50 lines of output]
      running install
      C:\Users\Among\AppData\Local\Programs\Python\Python310\lib\site-packages\setuptools\command\install.py:34: SetuptoolsDeprecationWarning: setup.py install is deprecated. Use build and pip and other standards-based tools.
        warnings.warn(
      running build
      running build_py
      creating build
      creating build\lib.win-amd64-3.10
      creating build\lib.win-amd64-3.10\confluent_kafka
      copying src\confluent_kafka\deserializing_consumer.py -> build\lib.win-amd64-3.10\confluent_kafka
      copying src\confluent_kafka\error.py -> build\lib.win-amd64-3.10\confluent_kafka
      copying src\confluent_kafka\serializing_producer.py -> build\lib.win-amd64-3.10\confluent_kafka
      copying src\confluent_kafka\__init__.py -> build\lib.win-amd64-3.10\confluent_kafka
      creating build\lib.win-amd64-3.10\confluent_kafka\admin
      copying src\confluent_kafka\admin\__init__.py -> build\lib.win-amd64-3.10\confluent_kafka\admin
      creating build\lib.win-amd64-3.10\confluent_kafka\avro
      copying src\confluent_kafka\avro\cached_schema_registry_client.py -> build\lib.win-amd64-3.10\confluent_kafka\avro
      copying src\confluent_kafka\avro\error.py -> build\lib.win-amd64-3.10\confluent_kafka\avro
      copying src\confluent_kafka\avro\load.py -> build\lib.win-amd64-3.10\confluent_kafka\avro
      copying src\confluent_kafka\avro\__init__.py -> build\lib.win-amd64-3.10\confluent_kafka\avro
      creating build\lib.win-amd64-3.10\confluent_kafka\kafkatest
      copying src\confluent_kafka\kafkatest\verifiable_client.py -> build\lib.win-amd64-3.10\confluent_kafka\kafkatest
      copying src\confluent_kafka\kafkatest\verifiable_consumer.py -> build\lib.win-amd64-3.10\confluent_kafka\kafkatest
      copying src\confluent_kafka\kafkatest\verifiable_producer.py -> build\lib.win-amd64-3.10\confluent_kafka\kafkatest
      copying src\confluent_kafka\kafkatest\__init__.py -> build\lib.win-amd64-3.10\confluent_kafka\kafkatest
      creating build\lib.win-amd64-3.10\confluent_kafka\schema_registry
      copying src\confluent_kafka\schema_registry\avro.py -> build\lib.win-amd64-3.10\confluent_kafka\schema_registry
      copying src\confluent_kafka\schema_registry\error.py -> build\lib.win-amd64-3.10\confluent_kafka\schema_registry
      copying src\confluent_kafka\schema_registry\json_schema.py -> build\lib.win-amd64-3.10\confluent_kafka\schema_registry
      copying src\confluent_kafka\schema_registry\protobuf.py -> build\lib.win-amd64-3.10\confluent_kafka\schema_registry
      copying src\confluent_kafka\schema_registry\schema_registry_client.py -> build\lib.win-amd64-3.10\confluent_kafka\schema_registry
      copying src\confluent_kafka\schema_registry\__init__.py -> build\lib.win-amd64-3.10\confluent_kafka\schema_registry
      creating build\lib.win-amd64-3.10\confluent_kafka\serialization
      copying src\confluent_kafka\serialization\__init__.py -> build\lib.win-amd64-3.10\confluent_kafka\serialization
      creating build\lib.win-amd64-3.10\confluent_kafka\avro\serializer
      copying src\confluent_kafka\avro\serializer\message_serializer.py -> build\lib.win-amd64-3.10\confluent_kafka\avro\serializer
      copying src\confluent_kafka\avro\serializer\__init__.py -> build\lib.win-amd64-3.10\confluent_kafka\avro\serializer
      running build_ext
      building 'confluent_kafka.cimpl' extension
      creating build\temp.win-amd64-3.10
      creating build\temp.win-amd64-3.10\Release
      creating build\temp.win-amd64-3.10\Release\Users
      creating build\temp.win-amd64-3.10\Release\Users\Among
      creating build\temp.win-amd64-3.10\Release\Users\Among\AppData
      creating build\temp.win-amd64-3.10\Release\Users\Among\AppData\Local
      creating build\temp.win-amd64-3.10\Release\Users\Among\AppData\Local\Temp
      creating build\temp.win-amd64-3.10\Release\Users\Among\AppData\Local\Temp\pip-install-e4mpsn3s
      creating build\temp.win-amd64-3.10\Release\Users\Among\AppData\Local\Temp\pip-install-e4mpsn3s\confluent-kafka_a53471ea97464e83aa35d4164a2c7040
      creating build\temp.win-amd64-3.10\Release\Users\Among\AppData\Local\Temp\pip-install-e4mpsn3s\confluent-kafka_a53471ea97464e83aa35d4164a2c7040\src
      creating build\temp.win-amd64-3.10\Release\Users\Among\AppData\Local\Temp\pip-install-e4mpsn3s\confluent-kafka_a53471ea97464e83aa35d4164a2c7040\src\confluent_kafka
      error: could not create 'build\temp.win-amd64-3.10\Release\Users\Among\AppData\Local\Temp\pip-install-e4mpsn3s\confluent-kafka_a53471ea97464e83aa35d4164a2c7040\src\confluent_kafka': The filename or extension is too long
      [end of output]

  note: This error originates from a subprocess, and is likely not a problem with pip.
error: legacy-install-failure

× Encountered error while trying to install package.
╰─> confluent-kafka

note: This is an issue with the package mentioned above, not pip.
hint: See above for output from the failure.

我尝试在这个 link“https://github.com/confluentinc/confluent-kafka-python/issues/1002”中使用其他方法。但是也不行。

请帮帮我!!

Windows 低于 1607 的版本对路径的最大长度有限制(由 MAX_PATH 设置),这将文件路径的长度限制在 260 个字符以内。

还好,如果你是运行Windows10版本1607,可以开启对长路径的支持:

  1. 点击Win+R
  2. 键入 regedit 并按 Enter
  3. 转到Computer\HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\FileSystem
  4. 编辑或创建名为 LongPathsEnabled 的密钥(类型:REG_DWORD
  5. 输入 1 作为其值并按 OK
  6. 重新启动系统并重试。它现在应该可以工作了。

阅读更多: Maximum Path Length Limitation in Windows