英文:
Cannot import Python hdfs client or config modules from hdfscli
问题
我尝试创建一个使用hdfscli库的Python 3 HDFS客户端。根据文档,我尝试了以下代码:
```python
import hdfs
client = hdfs.config.Config().get_client("dev")
但出现了AttributeError: module 'hdfs' has no attribute 'config'
错误。
我还尝试了以下代码:
import hdfs
client = hdfs.client.InsecureClient("http://<target/IP/address>")
但出现了AttributeError: module 'hdfs' has no attribute 'client'
错误。
我还尝试了from hdfs import client
和from hdfs import config
,但分别出现了ModuleNotFoundError: No module named 'ConfigParser'
和ImportError: cannot import name 'config' from 'hdfs'
错误。
我使用poetry进行包管理,并尝试重新运行了poetry lock
和poetry install
,但都没有成功。我的pyproject.toml
文件中列出了hdfs = "^1.0.1"
。我还有一个hdfscli.cfg文件,位于尝试访问它的脚本的几个级别之上。
<details>
<summary>英文:</summary>
I'm trying to create a Python 3 HDFS client using the hdfscli library. Per the documentation, I've tried
import hdfs
client = hdfs.config.Config().get_client("dev")
which yields `AttributeError: module 'hdfs' has no attribute 'config'`
and I've tried
import hdfs
client = hdfs.client.InsecureClient("http://<target/IP/address/>")
which yields `AttributeError: module 'hdfs' has no attribute 'client'`.
I've also tried `from hdfs import client` and `from hdfs import config`, which yield `ModuleNotFoundError: No module named 'ConfigParser'` and `ImportError: cannot import name 'config' from 'hdfs'` respectively.
I'm using poetry for package management, and I've re-run `poetry lock` and `poetry install` to no avail. The `pyproject.toml` file lists `hdfs = "^1.0.1"`. I have a hdfscli.cfg file a couple levels up from the script that's trying to access it.
</details>
# 答案1
**得分**: 1
Running `poetry remove hdfs`, `poetry add hdfs`, `poetry lock`, and `poetry install` again seems to have resolved the issue. The `pyproject.toml` file now lists `hdfs = "^2.7.0"`, so I may have just had quite an old hdfs version.
<details>
<summary>英文:</summary>
Running `poetry remove hdfs`, `poetry add hdfs`, `poetry lock`, and `poetry install` again seems to have resolved the issue. The `pyproject.toml` file now lists `hdfs = "^2.7.0"` so I may have just had quite an old hdfs version.
</details>
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论