gpt4 book ai didi

Python 导入错误 : cannot import name __version__

转载 作者:太空狗 更新时间:2023-10-29 20:21:32 25 4
gpt4 key购买 nike

我正在尝试使用 requests 和 requests_oauthlib,现在我只是在尝试他们在 requests_oauthlib 的文档中使用的非常简单的 Twitter 验证凭据示例,以确认我已经掌握了基础知识。我做了一个“pip install requests requests_oauthlib”来获取模块。在终端窗口中,我可以“导入请求”没问题,但是当我尝试“导入 requests_oauthlib”时,我得到了这个:

>>> import requests_oauthlib
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python2.7/site-packages/requests_oauthlib/__init__.py", line 1, in
<module>
from .oauth1_auth import OAuth1
File "/usr/lib/python2.7/site-packages/requests_oauthlib/oauth1_auth.py", line 10, in
<module>
from requests.utils import to_native_string
File "/usr/lib/python2.7/site-packages/requests/utils.py", line 23, in <module>
from . import __version__
ImportError: cannot import name __version__

utils.py 的第 23 行确实看起来像这样:

from . import __version__

我在 Fedora 上使用 Python 2.7.5,在多次尝试让它工作后,我目前正在用头撞墙,任何帮助将不胜感激......

最佳答案

检查根目录下的 __init__.py。 openpyxl 从 .constrants.json 文件中读取这些信息。但是,PyInstaller 不知何故无法使其正确。我会让你自己写一个__version__.py文件,然后在__init__.py中替换它们。

另一种更简单的方法是像这样更改 __init__.py:

import json
import os


# Modified to make it work in PyInstaller
#try:
# here = os.path.abspath(os.path.dirname(__file__))
# src_file = os.path.join(here, ".constants.json")
# with open(src_file) as src:
# constants = json.load(src)
# __author__ = constants['__author__']
# __author_email__ = constants["__author_email__"]
# __license__ = constants["__license__"]
# __maintainer_email__ = constants["__maintainer_email__"]
# __url__ = constants["__url__"]
# __version__ = constants["__version__"]
#except IOError:
# # packaged
# pass

__author__ = 'See AUTHORS'
__author_email__ = 'eric.gazoni@gmail.com'
__license__ = 'MIT/Expat'
__maintainer_email__ = 'openpyxl-users@googlegroups.com'
__url__ = 'http://openpyxl.readthedocs.org'
__version__ = '2.4.0-a1'

"""Imports for the openpyxl package."""
from openpyxl.compat.numbers import NUMPY, PANDAS
from openpyxl.xml import LXML

from openpyxl.workbook import Workbook
from openpyxl.reader.excel import load_workbook

print('You are using embedded openpyxl... 2.4.0-a1 ...')

关于Python 导入错误 : cannot import name __version__,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25121356/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com