[Tutor] import failure

Mark Lawrence breamoreboy at gmail.com
Sat Feb 23 14:41:48 EST 2019


On 22/02/2019 16:55, Alex Kleider wrote:
> 
> I'm trying to programmatically manipulate my google contacts using
> a library (https://github.com/google/gdata-python-client) which I've
> cloned.  The documentation suggests running a test to start with
> which I did (OS: Ubuntu 18.4, running in a python2.7 venv 'p2')
> with the following rather puzzling results (explanation below):
> 
> (p2) alex at one:$ pwd
> /home/alex/Proj/G/gdata-python-client
> (p2) alex at one:$ ls
> build                INSTALL.txt  pydocs             samples src
> contacts_example.py  Makefile     README.txt         set_python_path.sh 
> tests
> __init__.py          MANIFEST.in  RELEASE_NOTES.txt  setup.py 
> upload-diffs.py
> (p2) alex at one:$ ./tests/run_data_tests.py
> Traceback (most recent call last):
>    File "./tests/run_data_tests.py", line 19, in <module>
>      import gdata_tests.auth_test
>    File 
> "/home/alex/Proj/G/gdata-python-client/tests/gdata_tests/auth_test.py", 
> line 24, in <module>
>      import gdata.auth
>    File "/home/alex/Proj/G/gdata-python-client/src/gdata/auth.py", line 
> 29, in <module>
>      import gdata.oauth.rsa as oauth_rsa
>    File "/home/alex/Proj/G/gdata-python-client/src/gdata/oauth/rsa.py", 
> line 10, in <module>
>      from tlslite.utils import keyfactory
> ImportError: No module named tlslite.utils
> (p2) alex at one:$ pip install tlslite
> DEPRECATION: Python 2.7 will reach the end of its life on January 1st, 
> 2020. Please upgrade your Python as Python 2.7 won't be maintained after 
> that date. A future version of pip will drop support for Python 2.7.
> Collecting tlslite
>    Downloading 
> https://files.pythonhosted.org/packages/92/2b/7904cf913d9bf150b3e408a92c9cb5ce0b97a9ec19f998af48bf4c607f0e/tlslite-0.4.9.tar.gz 
> (105kB)
>      100% |                               | 112kB 174kB/s
>      100% |                               | 112kB 174kB/s
> Building wheels for collected packages: tlslite
>    Building wheel for tlslite (setup.py) ... done
>    Stored in directory: 
> /home/alex/.cache/pip/wheels/f8/de/72/213ac7112be37bc832e971c092757ae92aa5ae4b433e214ba9 
> 
> Successfully built tlslite
> Installing collected packages: tlslite
> Successfully installed tlslite-0.4.9
> (p2) alex at one:$ ./tests/run_data_tests.py
> Traceback (most recent call last):
>    File "./tests/run_data_tests.py", line 19, in <module>
>      import gdata_tests.auth_test
>    File 
> "/home/alex/Proj/G/gdata-python-client/tests/gdata_tests/auth_test.py", 
> line 24, in <module>
>      import gdata.auth
>    File "/home/alex/Proj/G/gdata-python-client/src/gdata/auth.py", line 
> 29, in <module>
>      import gdata.oauth.rsa as oauth_rsa
>    File "/home/alex/Proj/G/gdata-python-client/src/gdata/oauth/rsa.py", 
> line 10, in <module>
>      from tlslite.utils import keyfactory
> ImportError: No module named tlslite.utils
> (p2) alex at one:$ python
> Python 2.7.15rc1 (default, Nov 12 2018, 14:31:15)
> [GCC 7.3.0] on linux2
> Type "help", "copyright", "credits" or "license" for more information.
>>>> import tlslite
>>>> exit()
> (p2) alex at one:$ vim src/gdata/oauth/rsa.py
> (p2) alex at one:$ cat src/gdata/oauth/rsa.py | tail -n 4
> if __name__ == "__main__":
>      print("key_factory = " + repr(keyfactory))
> (p2) alex at one:$ python src/gdata/oauth/rsa.py
> key_factory = <module 'tlslite.utils.keyfactory' from 
> '/home/alex/.virtualenvs/p2/local/lib/python2.7/site-packages/tlslite/utils/keyfactory.pyc'> 
> 
> (p2) alex at one:$ python
> Python 2.7.15rc1 (default, Nov 12 2018, 14:31:15)
> [GCC 7.3.0] on linux2
> Type "help", "copyright", "credits" or "license" for more information.
>>>> from tlslite.utils import keyfactory
>>>>
> 
> Details: The initial run failed because of unavailability of a module.
> A little reading led to the discovery that it could be easily installed
> using pip but after doing so: Still the same failure.
> Running the interpreter proves that the module is now available but the
> test still fails.
> Adding a bit of code to the bottom of the failing module shows that it
> in fact can import the module in question.
> Ran the interpreter again just to be sure that the function is available
> and indeed it is.
> I don't understand how this could be possible.
> 
> Any suggestions as to what the problem might be or how to investigate
> further would be very much appreciated.
> 
> Cheers,
> Alex
> 

Just to follow up there are some useful tips in this 
https://mail.python.org/pipermail/python-list/2019-February/739643.html 
as to how to debug these type of problems.

-- 
My fellow Pythonistas, ask not what our language can do for you, ask
what you can do for our language.

Mark Lawrence



More information about the Tutor mailing list