Python Forum
Syntax errors: Struggling to setup enviroment and load packages
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Syntax errors: Struggling to setup enviroment and load packages
#1
I'm trying to run code that accesses Flickr's API. The code is pre-designed and reportedly works, and it is available here:
https://github.com/ultralytics/flickr_scraper#readme

I'm very new to python and have gone through the tutorials, appropriate setup for Windows 10 and followed the base instructions to the letter, but I just can't get this to work. I have some programming experience using R to complete similar tasks.

The first instruction on the ReadMe is:
$ git clone https://github.com/ultralytics/flickr_scraper
$ cd flickr_scraper
$ pip install -U -r requirements.txt

When I run this, I keep receiving syntax errors after the first space in all my code. What am I doing wrong? I think I need to create a virtual environment to install/import new packages but I'm getting confused.

I know this is quite a basic problem, but could anyone help with step by step instructions? Thanks for your time.
Reply
#2
(Jun-24-2021, 12:35 PM)AH56 Wrote: When I run this, I keep receiving syntax errors after the first space in all my code. What am I doing wrong? I think I need to create a virtual environment to install/import new packages but I'm getting confused.

I know this is quite a basic problem, but could anyone help with step by step instructions? Thanks for your time.
Can show a basic installation,virtual environment is best so get all new and don't conflict with installed before.
I use cmder here,commands is the same in cmd/Powershell.
# Make 
G:\div_code
λ python -m venv flick_env

# Cd in
G:\div_code
λ cd flick_env\

# Activate
G:\div_code\flick_env
λ G:\div_code\flick_env\Scripts\activate

# Clone down
(flick_env) G:\div_code\flick_env
λ git clone https://github.com/ultralytics/flickr_scraper
Cloning into 'flickr_scraper'...
remote: Enumerating objects: 186, done.
remote: Counting objects: 100% (4/4), done.
remote: Compressing objects: 100% (4/4), done.
Receiving objects:  71% (133/186)   1 (delta 0), pack-reused 182 eceiving objects:  70% (131/186)
Receiving objects: 100% (186/186), 46.52 KiB | 0 bytes/s, done.
Resolving deltas: 100% (113/113), done.
Checking connectivity... done.

# Cd in
(flick_env) G:\div_code\flick_env
λ cd flickr_scraper\

# Install
(flick_env) G:\div_code\flick_env\flickr_scraper (master)
λ pip install -U -r requirements.txt
Collecting flickrapi
  Downloading ....ect

Successfully installed certifi-2021.5.30 chardet-4.0.0 flickrapi-2.4.0 idna-2.10 numpy-1.21.0
oauthlib-3.1.1 pillow-8.2.0 requests-2.25.1 requests-oauthlib-1.3.0 requests-toolbelt-0.9.1 six-1.16.0 tqdm-4.61.1 urllib3-1.26.5

# Test that it work
(flick_env) G:\div_code\flick_env\flickr_scraper (master)
λ python flickr_scraper.py --help
usage: flickr_scraper.py [-h] [--search SEARCH] [--n N] [--download]

optional arguments:
  -h, --help       show this help message and exit
  --search SEARCH  flickr search term
  --n N            number of images
  --download       download images
Reply
#3
Thanks for this, the program runs! However, I'm getting an error.

# Run code
λ python3 flickr_scraper.py --search 'bees' --n 10
Traceback (most recent call last):
File "C:\Users\Student\Desktop\cmder\flick_env\flickr_scraper\flickr_scraper.py", line 66, in <module>
get_urls(search=opt.search, # search term
File "C:\Users\Student\Desktop\cmder\flick_env\flickr_scraper\flickr_scraper.py", line 31, in get_urls
for i, photo in enumerate(photos):
File "C:\Users\Student\AppData\Roaming\Python\Python39\site-packages\flickrapi\core.py", line 690, in data_walker
photoset = rsp.getchildren()[0]
AttributeError: 'xml.etree.ElementTree.Element' object has no attribute 'getchildren'


#There's a note from the devs that this is because the FlickrAPI uses getchildren, but this has been removed in python 3.9. I need to downgrade to 3.8 to fix this, but now need to create a virtual eviroment that has both 3.8 in it, and flickr_Scraper. How do I do this on cmder? Cheers.
Reply
#4
(Jun-25-2021, 02:04 PM)AH56 Wrote: I need to downgrade to 3.8 to fix this, but now need to create a virtual eviroment that has both 3.8 in it, and flickr_Scraper. How do I do this on cmder? Cheers.
You don't need to downgrade just install Python 3.8 and do not add it to PATH.
Python 3.9/3.8 and pip installation under Windows
Then can use py to access Python 3.8.
Here is the start then the other commands is the same
# Make environment with Python 3.8 
G:\div_code\py -3.8 -m venv flick38_env

G:\div_code
λ cd flick38_env\

G:\div_code\flick38_env
λ G:\div_code\flick38_env\Scripts\activate

(flick38_env) G:\div_code\flick38_env
λ cd flickr_scraper\
.....
Can do a test to see it works.
(flick38_env) G:\div_code\flick38_env\flickr_scraper (master)
λ python flickr_scraper.py --search "bees" --n 10 --download
0/10 https://live.staticflickr.com/5537/14142817779_8786627929_o.jpg
1/10 https://live.staticflickr.com/829/41747732682_f4f10ec204_o.jpg
2/10 https://live.staticflickr.com/1662/23809746334_c22950a054_o.jpg
3/10 https://live.staticflickr.com/4094/4822128168_415b5ce1e4_o.jpg
4/10 https://farm6.staticflickr.com/5511/12638717365_7643b6e19a_b.jpg
5/10 https://live.staticflickr.com/961/27921370568_0795b91dfb_o.jpg
6/10 https://farm2.staticflickr.com/1646/26540040015_54f071db32_b.jpg
7/10 https://farm8.staticflickr.com/7377/26868463353_6da2da165d_b.jpg
8/10 https://farm8.staticflickr.com/7595/17187249975_b1ccddea5f_b.jpg
9/10 https://farm2.staticflickr.com/1578/26186589965_678bd3c5a4_b.jpg
Some points if search has more than one work use double quote and not single.
python flickr_scraper.py --search "honeybees on flowers" --n 10 --download
I have to use Ctrl+c to stop it get out.
Reply
#5
I did have look at error message for Python 3.9 and fix it.
In core.py i change this on line 690.
#photoset = rsp.getchildren()[0]
photoset = list(rsp)[0] # Fix
Test with 3.9:
(flick_env) G:\div_code\flick_env\flickr_scraper (master)
λ python flickr_scraper.py --search "bees" --n 10 --download
0/10 https://live.staticflickr.com/5537/14142817779_8786627929_o.jpg
1/10 https://live.staticflickr.com/829/41747732682_f4f10ec204_o.jpg
2/10 https://live.staticflickr.com/1662/23809746334_c22950a054_o.jpg
3/10 https://live.staticflickr.com/4094/4822128168_415b5ce1e4_o.jpg
4/10 https://farm6.staticflickr.com/5511/12638717365_7643b6e19a_b.jpg
5/10 https://live.staticflickr.com/961/27921370568_0795b91dfb_o.jpg
6/10 https://farm2.staticflickr.com/1646/26540040015_54f071db32_b.jpg
7/10 https://farm8.staticflickr.com/7377/26868463353_6da2da165d_b.jpg
8/10 https://farm8.staticflickr.com/7595/17187249975_b1ccddea5f_b.jpg
9/10 https://farm2.staticflickr.com/1578/26186589965_678bd3c5a4_b.jpg
I give author a message about this so he can fix it.
Reply
#6
Thanks for this and the message to the author. It all works great !
snippsat likes this post
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Struggling with Juggling JSON Data SamWatt 7 534 May-09-2022, 02:49 AM
Last Post: snippsat
  struggling with != statements CallumRoberts2004 2 867 Aug-18-2020, 03:01 PM
Last Post: GOTO10
  I’m Flat out struggling to understand list indexes gr3yali3n 7 1,715 Jul-20-2020, 07:18 PM
Last Post: princetonits
  Struggling with nested list gr3yali3n 3 1,360 Jul-09-2020, 05:30 PM
Last Post: DPaul
  Struggling to exit this while loop fatherted99 5 1,490 Feb-08-2020, 07:46 PM
Last Post: fatherted99
  Pip Syntax Errors in CMD: Windows 10 and Python 3.8.1 jamesphopper 2 3,398 Feb-08-2020, 07:21 PM
Last Post: jamesphopper
  Struggling with several while loops nsadams87xx 1 1,155 Nov-25-2019, 02:12 AM
Last Post: Larz60+
  struggling with loop/webscrape zarize 4 1,463 Sep-27-2019, 08:44 AM
Last Post: zarize
  Still struggling with np.where... pberrett 1 1,263 May-10-2019, 11:30 AM
Last Post: scidam
  Mysterious syntax errors... help? friendlymegalomaniac 3 2,114 Apr-26-2018, 09:22 PM
Last Post: micseydel

Forum Jump:

User Panel Messages

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