[Tutor] import failure
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@one:$ pwd /home/alex/Proj/G/gdata-python-client (p2) alex@one:$ ls buildINSTALL.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@one:$ ./tests/run_data_tests.py Traceback (most recent call last): File "./tests/run_data_tests.py", line 19, in import gdata_tests.auth_test File "/home/alex/Proj/G/gdata-python-client/tests/gdata_tests/auth_test.py", line 24, in import gdata.auth File "/home/alex/Proj/G/gdata-python-client/src/gdata/auth.py", line 29, in import gdata.oauth.rsa as oauth_rsa File "/home/alex/Proj/G/gdata-python-client/src/gdata/oauth/rsa.py", line 10, in from tlslite.utils import keyfactory ImportError: No module named tlslite.utils (p2) alex@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@one:$ ./tests/run_data_tests.py Traceback (most recent call last): File "./tests/run_data_tests.py", line 19, in import gdata_tests.auth_test File "/home/alex/Proj/G/gdata-python-client/tests/gdata_tests/auth_test.py", line 24, in import gdata.auth File "/home/alex/Proj/G/gdata-python-client/src/gdata/auth.py", line 29, in import gdata.oauth.rsa as oauth_rsa File "/home/alex/Proj/G/gdata-python-client/src/gdata/oauth/rsa.py", line 10, in from tlslite.utils import keyfactory ImportError: No module named tlslite.utils (p2) alex@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@one:$ vim src/gdata/oauth/rsa.py (p2) alex@one:$ cat src/gdata/oauth/rsa.py | tail -n 4 if __name__ == "__main__": print("key_factory = " + repr(keyfactory)) (p2) alex@one:$ python src/gdata/oauth/rsa.py key_factory = '/home/alex/.virtualenvs/p2/local/lib/python2.7/site-packages/tlslite/utils/keyfactory.pyc'> (p2) alex@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 -- Alex Kleider (sent from my current gizmo) ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] import failure
Alex Kleider wrote: > (p2) alex@one:$ ./tests/run_data_tests.py Here you let the script decide which interpreter to pick... > Traceback (most recent call last): > ImportError: No module named tlslite.utils ...and it looks like it's not the one you'd like to have: > (p2) alex@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() > Any suggestions as to what the problem might be or how to investigate > further would be very much appreciated. Try (p2) alex@one:$ python ./tests/run_data_tests.py ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] import failure
On 2/22/19 9:55 AM, Alex Kleider wrote: (p2) alex@one:$ python src/gdata/oauth/rsa.py key_factory = '/home/alex/.virtualenvs/p2/local/lib/python2.7/site-packages/tlslite/utils/keyfactory.pyc'> (p2) alex@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 pip installs are specific to the interpreter, you're probably getting a mismatch there. Rule one: install this way: python -m pip install sheepdip that way you're sure the pip matches the python and things go in the expected place. Rule 2: you can do some inspection by printing the values of sys.executable and sys.path both in your interactive environment where it works and in your script where it doesn't work. My guess is you'll find a mismatch... but this is only surmise, something to try out, we can't see your precise environment. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] [EXTERNAL] Re: Help Please
Thanks Alex, This helped. Mario Ontiveros -Original Message- From: Alex Kleider [mailto:aklei...@sonic.net] Sent: Wednesday, February 20, 2019 10:20 PM To: Mario Ontiveros Cc: tutor@python.org; Tutor Subject: [EXTERNAL] Re: [Tutor] Help Please On 2019-02-20 06:30, Mario Ontiveros wrote: > Hello, > I am new to python and have been stuck on this for a while. What I > am trying to do is to remove rows with void, disconnected, and error > on lines. The code I have does that, the only problem is that it > removes my header because void is in header. I need to keep header. > > Any help will be greatly appreciated. > > with open("PSS.csv","r+") as f: > new_f = f.readlines() > f.seek(0) > for line in new_f: > if "Void" not in line: > if "Disconnected" not in line: > if "Error" not in line: > f.write(line) > f.truncate() > > > > Mario Ontiveros Since your file seems to be a csv file, can we assume your 'header' line is really a comma separated list of column names? If so, then using the csv module and specifically csv.DictReader (+/- DictWriter) might make things easier for you. --- Confidentiality Warning: This message and any attachments are intended only for the use of the intended recipient(s), are confidential, and may be privileged. If you are not the intended recipient, you are hereby notified that any review, retransmission, conversion to hard copy, copying, circulation or other use of all or any portion of this message and any attachments is strictly prohibited. If you are not the intended recipient, please notify the sender immediately by return e-mail, and delete this message and any attachments from your system. --- ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor