Python ImportError: unable to import name __version__

I'm trying to use requests and oauthlib requests, and right now I'm just trying to skip dead simple Twitter to check the credentials that they use in the documentation for request_oauthlib to confirm that I have the basics. I got "pip install requests requests_oauthlib" to get the modules. In the terminal window, I can "import requests" without problems, but when I try to "import requests_oauthlib", I get the following:

>>> 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__ 

Line 23 utils.py really looks like this:

 from . import __version__ 

I am using Python 2.7.5 on Fedora, and I am currently banging my head against this wall after several attempts to make it work, any help would be greatly appreciated ...

+7
python oauth
source share
2 answers

Check __init__.py in the root directory. openpyxl reads this information from a .constants.json file. However, PyInstaller somehow cannot do it right. I would write the __version__.py file myself and replace them in __init__.py .

Another simpler way is to modify __init__.py as follows:

 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 ...') 
+6
source share

I used openpyxl in my project, when I do exe using py2exe, compilation is fine, but when I run compiled exe, I met the same problem.

ImportError: cannot import name __version __

Try changing the init .py in the root folder with the lightpyxl parameters, do not read the version from the constants.json file, just write as __ version__ = '2.4.1' . I decided that way.

+3
source share

All Articles