Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
investigating a bash error
#1
Hi Python Forum,

I'm struggling with getting a twphotos to work, I found the script here and I think based on what others have said it is working for them. I cant get it to work in the command line so I've posted some detailed commands used and outputs.

https://github.com/shichao-an/twitter-ph...r/twphotos

I've installed Python, Xcode command line, and have tested python is working.

And so I run

pip install twitter-photos
Returns

Output:
Requirement already satisfied: twitter-photos in ./Library/Python/2.7/lib/python/site-packages (0.4.0) Requirement already satisfied: python-twitter in /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages (from twitter-photos) (3.4.2) Requirement already satisfied: requests in /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages (from twitter-photos) (2.19.1) Requirement already satisfied: urllib3 in /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages (from twitter-photos) (1.23) Requirement already satisfied: future in /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages (from python-twitter->twitter-photos) (0.16.0) Requirement already satisfied: requests-oauthlib in /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages (from python-twitter->twitter-photos) (1.0.0) Requirement already satisfied: certifi>=2017.4.17 in /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages (from requests->twitter-photos) (2018.4.16) Requirement already satisfied: chardet<3.1.0,>=3.0.2 in /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages (from requests->twitter-photos) (3.0.4) Requirement already satisfied: idna<2.8,>=2.5 in /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages (from requests->twitter-photos) (2.7) Requirement already satisfied: oauthlib>=0.6.2 in /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages (from requests-oauthlib->python-twitter->twitter-photos) (2.1.0)
Checked credentials are set using

cat ~/.twphotos
returns the correct information in the config file

pip install python-twitter
returns

Output:
Requirement already satisfied: python-twitter in /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages (3.4.2) Requirement already satisfied: future in /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages (from python-twitter) (0.16.0) Requirement already satisfied: requests-oauthlib in /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages (from python-twitter) (1.0.0) Requirement already satisfied: requests in /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages (from python-twitter) (2.19.1) Requirement already satisfied: oauthlib>=0.6.2 in /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages (from requests-oauthlib->python-twitter) (2.1.0) Requirement already satisfied: certifi>=2017.4.17 in /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages (from requests->python-twitter) (2018.4.16) Requirement already satisfied: chardet<3.1.0,>=3.0.2 in /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages (from requests->python-twitter) (3.0.4) Requirement already satisfied: urllib3<1.24,>=1.21.1 in /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages (from requests->python-twitter) (1.23) Requirement already satisfied: idna<2.8,>=2.5 in /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages (from requests->python-twitter) (2.7)
pip install requests
returns

Output:
Requirement already satisfied: requests in /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages (2.19.1) Requirement already satisfied: certifi>=2017.4.17 in /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages (from requests) (2018.4.16) Requirement already satisfied: chardet<3.1.0,>=3.0.2 in /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages (from requests) (3.0.4) Requirement already satisfied: urllib3<1.24,>=1.21.1 in /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages (from requests) (1.23) Requirement already satisfied: idna<2.8,>=2.5 in /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages (from requests) (2.7)
pip install urllib3
returns

Output:
Requirement already satisfied: urllib3 in /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages (1.23)
BUT when running command
twitter-photos
or
twphotos
Returns

Output:
-bash: twitter-photos: command not found
Or
Output:
-bash: twphotos: command not found
pip uninstall twitter-photos
returns (for info on locations)

Output:
Uninstalling twitter-photos-0.4.0: Would remove: /Users/local/Library/Python/2.7/bin/twphotos /Users/local/Library/Python/2.7/lib/python/site-packages/twitter_photos-0.4.0-py2.7.egg-info /Users/local/Library/Python/2.7/lib/python/site-packages/twphotos/*
I tried another command and it works OK

pip uninstall twitter-photos
Returns

Output:
Successfully uninstalled twitter-photos-0.4.0
Then tried

pip install --user twitter-photos
Output:
Using cached https://files.pythonhosted.org/packages/b0/d9/40da537d49971c07f5c2255844fde46cd4e40bc0da7e06e616a64d94b1ef/twitter-photos-0.4.0.tar.gz Requirement already satisfied: python-twitter in /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages (from twitter-photos) (3.4.2) Requirement already satisfied: requests in /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages (from twitter-photos) (2.19.1) Requirement already satisfied: urllib3 in /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages (from twitter-photos) (1.23) Requirement already satisfied: future in /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages (from python-twitter->twitter-photos) (0.16.0) Requirement already satisfied: requests-oauthlib in /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages (from python-twitter->twitter-photos) (1.0.0) Requirement already satisfied: certifi>=2017.4.17 in /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages (from requests->twitter-photos) (2018.4.16) Requirement already satisfied: chardet<3.1.0,>=3.0.2 in /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages (from requests->twitter-photos) (3.0.4) Requirement already satisfied: idna<2.8,>=2.5 in /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages (from requests->twitter-photos) (2.7) Requirement already satisfied: oauthlib>=0.6.2 in /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages (from requests-oauthlib->python-twitter->twitter-photos) (2.1.0) Installing collected packages: twitter-photos Running setup.py install for twitter-photos ... done Successfully installed twitter-photos-0.4.0
Then tried running again and same problem error

for more info I run the command:

echo $PATH
returns:

Output:
/Users/local/.rvm/gems/ruby-2.5.1/bin:/Users/local/.rvm/gems/ruby-2.5.1@global/bin:/Users/local/.rvm/rubies/ruby-2.5.1/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Users/local/.rvm/bin
Thank you for look at this in advance, I hope I've included all the right information. Please ask for any outputs or details and I'll come back with them.

If you can explain what it is that needs checking and how things work, or any links to read further into what might cause this they would be much appreciated.

Regards XTR
Reply
#2
make sure:
python -V
# and
pip -V
are in sync (same version of python)
it sounds like the kind of errors you run into when there not
Reply
#3
Hi Larz60+

Thanks for your reply, I tried your suggestions and they return

Output:
Python 2.7.15 # and pip 10.0.1 from /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pip (python 2.7)
I think these are both the latest versions as I updated them manually.

regards, XTR
Reply
#4
I am not a Linux user, but two things come to mind:
a. Are you actually acesssing twphotos?
Try /Users/local/Library/Python/2.7/bin/twphotos or navigate to the directory and execute twphotos.
b. Verify that you have execute permissions for twphotos if a. above does not work.

Lewis
To paraphrase: 'Throw out your dead' code. https://www.youtube.com/watch?v=grbSQ6O6kbs Forward to 1:00
Reply
#5
Lewis,

Amazing - thank you, that solved the problem and I need to familiarise myself with what all the folders and paths.

When I run

echo $PATH
I notice all of the references to Ruby

Output:
/Users/local/.rvm/gems/ruby-2.5.1/bin:/Users/local/.rvm/gems/ruby-2.5.1@global/bin:/Users/local/.rvm/rubies/ruby-2.5.1/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Users/local/.rvm/bin
Do you know what the syntax name to help with understanding how to read the output from that? (as a debugging tool for future use)

I also wondered if you know of a script or process to assess what version of Python code is written to support and compatible with, or if there is a signature you can read as a way of checking - can I run something that will look at a py file and tell me if it is Python 2.7 or 3 or both?

The output of my terminal is now as below with another load of errors!

Thanks for your help, XTRw

Output:
/Users/local/Library/Python/2.7/bin/twphotos Retrieving photos from Twitter API... Traceback (most recent call last): File "/Users/local/Library/Python/2.7/bin/twphotos", line 11, in <module> load_entry_point('twitter-photos==0.4.0', 'console_scripts', 'twphotos')() File "/Users/local/Library/Python/2.7/lib/python/site-packages/twphotos/photos.py", line 291, in main twphotos.get() File "/Users/local/Library/Python/2.7/lib/python/site-packages/twphotos/photos.py", line 71, in get self.auth_user = self.verify_credentials().screen_name File "/Users/local/Library/Python/2.7/lib/python/site-packages/twphotos/photos.py", line 162, in verify_credentials return self.api.VerifyCredentials() File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/twitter/api.py", line 4682, in VerifyCredentials data = self._ParseAndCheckTwitter(resp.content.decode('utf-8')) File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/twitter/api.py", line 4890, in _ParseAndCheckTwitter self._CheckForTwitterError(data) File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/twitter/api.py", line 4910, in _CheckForTwitterError raise TwitterError(data['errors']) twitter.error.TwitterError: [{u'message': u'Invalid or expired token.', u'code': 89}]
Reply
#6
Quote:Do you know what the syntax name to help with understanding how to read the output from that? (as a debugging tool for future use)
Each individual item in the path is separated by a colon ':'. You can write a bash script to decode or use something like the following Python file (tested in Windows only):
import sys
linux_path_list = sys.path
print(linux_path_list)

for mypath in linux_path_list:
    print( mypath)

Quote:Do you know of a script or process to assess what version of Python code is written to support and compatible with, or if there is a signature you can read as a way of checking - can I run something that will look at a py file and tell me if it is Python 2.7 or 3 or both?
There are probably tools out there that can identify the source code, but I do not know of any. You can compile the source file using the various versions and see if the file compiles without any errors.

You can use the Python Launcher (py.exe in Windows) that comes with Python starting with version 3.3. You can then compile version 2 or version 3 as you like:
Output:
py -2 abcd.py py -3 abcd.py

Your errors may be caused by lack of a Twitter Configuration file needed by twphotos. See the Setup section for details in https://pypi.org/project/twitter-photos/

Lewis
To paraphrase: 'Throw out your dead' code. https://www.youtube.com/watch?v=grbSQ6O6kbs Forward to 1:00
Reply
#7
(Jul-04-2018, 08:48 PM)ljmetzger Wrote: I also wondered if you know of a script or process to assess what version of Python code is written to support and compatible with, or if there is a signature you can read as a way of checking
It's in the setup.py of Repo.
There you see that is for Python 2,also that these get installed install_requires=['python-twitter', 'requests', 'urllib3']
entry_points={
        'console_scripts': [
            'twphotos = twphotos.photos:main',
        ],
    },
This mean that twphotos will be made in Path(bin) Linux,on Windows entry_points will make a twphotos.exe in Path.

Quick demo here i use pipenv for virtual environment for Python 2.7,as Python 3.7 is my main version.
Using virtual environment also eliminate any problem with Path to twphotos.
# Make environment for 2.7
int@mint ~/twitter_env $ pipenv --two
Creating a virtualenv for this project...
Pipfile: /home/mint/twitter_env/Pipfile
Using /usr/bin/python2 (2.7.12) to create virtualenv...
â ‹Running virtualenv with interpreter /usr/bin/python2
.....
Installing setuptools, pip, wheel...done.

# Activate shell
mint@mint ~/twitter_env $ pipenv shell
Launching subshell in virtual environment…
 . /home/mint/.local/share/virtualenvs/twitter_env-KsA1zvUG/bin/activate
.....

# Install
(twitter_env-KsA1zvUG) mint@mint ~/twitter_env $ pip install twitter-photos
Collecting twitter-photos  
............
Installing collected packages: idna, urllib3, chardet, certifi, requests, oauthlib, requests-oauthlib, future, python-twitter, twitter-photos
Successfully installed certifi-2018.4.16 chardet-3.0.4 future-0.16.0 idna-2.7 oauthlib-2.1.0 python-twitter-3.4.2 requests-2.19.1 requests-oauthlib-1.0.0 twitter-photos-0.4.0 urllib3-1.23

# Test twphotos placment
(twitter_env-KsA1zvUG) mint@mint ~/twitter_env $ which twphotos
/home/mint/.local/share/virtualenvs/twitter_env-KsA1zvUG/bin/twphotos

# Run all work but i have not setup credentials
(twitter_env-KsA1zvUG) mint@mint ~/twitter_env $ twphotos
Traceback (most recent call last):
...
Exception: No credentials found.
With pipenv also get a fine graph over what's installed in the virtual environment.
twitter_env-KsA1zvUG) mint@mint ~/twitter_env $ pipenv graph
twitter-photos==0.4.0
  - python-twitter [required: Any, installed: 3.4.2]
    - future [required: Any, installed: 0.16.0]
    - requests [required: Any, installed: 2.19.1]
      - certifi [required: >=2017.4.17, installed: 2018.4.16]
      - chardet [required: >=3.0.2,<3.1.0, installed: 3.0.4]
      - idna [required: >=2.5,<2.8, installed: 2.7]
      - urllib3 [required: >=1.21.1,<1.24, installed: 1.23]
    - requests-oauthlib [required: Any, installed: 1.0.0]
      - oauthlib [required: >=0.6.2, installed: 2.1.0]
      - requests [required: >=2.0.0, installed: 2.19.1]
        - certifi [required: >=2017.4.17, installed: 2018.4.16]
        - chardet [required: >=3.0.2,<3.1.0, installed: 3.0.4]
        - idna [required: >=2.5,<2.8, installed: 2.7]
        - urllib3 [required: >=1.21.1,<1.24, installed: 1.23]
  - requests [required: Any, installed: 2.19.1]
    - certifi [required: >=2017.4.17, installed: 2018.4.16]
    - chardet [required: >=3.0.2,<3.1.0, installed: 3.0.4]
    - idna [required: >=2.5,<2.8, installed: 2.7]
    - urllib3 [required: >=1.21.1,<1.24, installed: 1.23]
  - urllib3 [required: Any, installed: 1.23]
Reply
#8
Hello

This all worked and I have the images downloading now!

many thanks for your help

XTR
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020