Python can't find dependency - SOLVED

Discuss RoboTask here
snowseals
Posts: 59
Joined: Mon Apr 11, 2016 10:17 am

Python can't find dependency - SOLVED

Post by snowseals »

1. When I try to run a python script with Robotask, it shows it's missing a dependency.
I've tried to add the path in Options > Search Module Paths, but it won't find it.

Image

2. Also note I needed to use C:\\ but the other subfolders need \subfolder instead (?)
Normally in Python (on Win) u need to use C:\\all\\the\way\\like\\this but seems it's adding them by Robotask except the 1st root (sub)folder?

Code: Select all

;*****************************
;* RoboTask Task file
;* Do not edit in text editor!
;*****************************
 
[Root]
ActionAfterRun=INTEGER|0
Actions=FOLDER
Automat=INTEGER|-1
CatID=INTEGER|0
Comment=STRINGLIST
ContinueOnError=INTEGER|0
DisableOnError=INTEGER|0
DoNotStopWhenShutdown=INTEGER|0
ExternalName=STRING|"Task11"
Hide=INTEGER|0
ID=INTEGER|-1765535527
LogOnAsUser=INTEGER|1
Name=STRING|"eurotax goto"
OnErrorTaskID=INTEGER|-1
Priority=INTEGER|3
RunOnClose=INTEGER|0
RunOnStartup=INTEGER|1
ToLog=INTEGER|3
UnicodeFormat=INTEGER|1
WriteGeneralLog=INTEGER|0

[Actions]
Action1=FOLDER

[Actions\Action1]
ActionID=STRING|"A_SCRIPT_PYTHONSCRIPT"
Enabled=INTEGER|-1
Name=STRING|"Python Script"
Params=FOLDER

[Actions\Action1\Params]
expand=STRING|"0"
script_0=STRING|"import time"
script_1=STRING|"import os"
script_10=STRING|"PASSWORD = 'CENSORED'"
script_100=STRING|"        font-size: 24px;"
script_101=STRING|"    }"
script_102=STRING|"    .table-head {"
script_103=STRING|"        font-size: 20px;"
script_104=STRING|"        font-weight: bold;"
script_105=STRING|"        margin-bottom: 8px;"
script_106=STRING|"    }"
script_107=STRING|"    .table-row {"
script_108=STRING|"        margin-bottom: 8px;"
script_109=STRING|"        cursor: pointer;"
script_11=STRING|"CSV = ""C:\\Users\SEK\Desktop\cars_1-400.csv"""
script_110=STRING|"        padding-bottom: 8px;"
script_111=STRING|"        font-size: 16px;"
script_112=STRING|"    }"
script_113=STRING|"    .table-row:hover {"
script_114=STRING|"        color: #2244ee;"
script_115=STRING|"    }"
script_116=STRING|"</style>"
script_117=STRING|""""""""
script_119=STRING|"def main_eurotax(car_id: int, page: int):"
script_120=STRING|"    # Login"
script_121=STRING|"    driver.get('http://eurotaxonline.nl/')"
script_122=STRING|"    driver.find_element_by_id('tbUser').send_keys(USERNAME)"
script_123=STRING|"    driver.find_element_by_id('tbPW').send_keys(PASSWORD)"
script_124=STRING|"    driver.find_element_by_id('btLogin').click()"
script_125=STRING|"    while True:"
script_126=STRING|"        if driver.find_element_by_id('lblLogout'):"
script_127=STRING|"            break"
script_128=STRING|"        time.sleep(0.1)"
script_13=STRING|"# Flask, selenium"
script_130=STRING|"    find_car(driver, car_id, page)"
script_131=STRING|"    # Keep selenium running"
script_132=STRING|"    os._exit(0)"
script_134=STRING|"# Find car by ID"
script_135=STRING|"def find_car(driver, car_nr: int, start_page: int = 1):"
script_136=STRING|"    driver.get('http://eurotaxonline.nl/dossiers.aspx')"
script_138=STRING|"    # Go to correct start page"
script_139=STRING|"    page = 1"
script_14=STRING|"app = Flask(__name__)"
script_140=STRING|"    if start_page > 11:"
script_141=STRING|"        while page != start_page:"
script_142=STRING|"            if page + 10 < start_page:"
script_143=STRING|"                driver.execute_script(f""__doPostBack('gvDossiers','Page${page+10}')"")"
script_144=STRING|"                page = wait_for_pager(driver)"
script_145=STRING|"                continue"
script_146=STRING|"            driver.execute_script(f""__doPostBack('gvDossiers','Page${start_page}')"")"
script_147=STRING|"            page = start_page"
script_149=STRING|"    while True:"
script_15=STRING|"chrome_options = Options()"
script_150=STRING|"        # Find IDs"
script_151=STRING|"        wait_for_pager(driver)"
script_152=STRING|"        table = driver.find_element_by_id('gvDossiers')"
script_153=STRING|"        rows = table.find_elements_by_tag_name('tr')"
script_154=STRING|"        for row in rows:"
script_155=STRING|"            id_elem = row.find_elements_by_tag_name('td')[1]"
script_156=STRING|"            if id_elem.text == str(car_nr):"
script_157=STRING|"                id_elem.click()"
script_158=STRING|"                return"
script_16=STRING|"chrome_options.add_experimental_option('detach', True)"
script_160=STRING|"        # Wait for next page"
script_161=STRING|"        page += 1"
script_162=STRING|"        if page == start_page + 10:"
script_163=STRING|"            break"
script_164=STRING|"        driver.execute_script(f""__doPostBack('gvDossiers','Page${page}')"")"
script_165=STRING|"        while True:"
script_166=STRING|"            page_number = wait_for_pager(driver)"
script_167=STRING|"            if page_number == page:"
script_168=STRING|"                break"
script_169=STRING|"            time.sleep(0.1)"
script_17=STRING|"driver = webdriver.Chrome('chromedriver.exe', options=chrome_options)"
script_171=STRING|"    print('Unable to locate car!')"
script_173=STRING|"# Wait for pager element = page loaded"
script_174=STRING|"def wait_for_pager(driver):"
script_175=STRING|"    while True:"
script_176=STRING|"        pager = driver.find_elements_by_class_name('cssPager')"
script_177=STRING|"        if len(pager) > 0:"
script_178=STRING|"            return int(pager[0].find_element_by_tag_name('span').text.strip())"
script_180=STRING|"@app.route('/')"
script_181=STRING|"def index_route():"
script_182=STRING|"    reader = csv.reader(open(CSV), delimiter=';')"
script_183=STRING|"    rows = json.dumps([r for r in reader][1:])"
script_184=STRING|"    html = HTML.replace(""['REPLACE_ME']"", rows)"
script_185=STRING|"    return html"
script_187=STRING|"@app.route('/<cid>/<page>')"
script_188=STRING|"def start_route(cid, page):"
script_189=STRING|"    t = threading.Thread(target=main_eurotax, args=(cid, int(page)))"
script_19=STRING|"HTML = """""""
script_190=STRING|"    t.start()"
script_191=STRING|"    return ''"
script_193=STRING|"def start_selenium():"
script_194=STRING|"    time.sleep(0.5)"
script_195=STRING|"    driver.get('http://127.0.0.1:36988')"
script_197=STRING|"if __name__ == '__main__':"
script_198=STRING|"    t = threading.Thread(target=start_selenium)"
script_199=STRING|"    t.start()"
script_2=STRING|"import csv"
script_20=STRING|"<!DOCTYPE html>"
script_200=STRING|"    app.run('127.0.0.1', 36988)"
script_21=STRING|"<html lang=""en"">"
script_22=STRING|"<head>"
script_23=STRING|"    <meta charset=""UTF-8"">"
script_24=STRING|"    <meta http-equiv=""X-UA-Compatible"" content=""IE=edge"">"
script_25=STRING|"    <meta name=""viewport"" content=""width=device-width, initial-scale=1.0"">"
script_26=STRING|"    <title>Car List</title>"
script_27=STRING|"</head>"
script_29=STRING|"<script type='module'>"
script_3=STRING|"import threading"
script_30=STRING|"import { createApp } from 'https://unpkg.com/petite-vue?module'"
script_32=STRING|"const CARS = ['REPLACE_ME']"
script_34=STRING|"createApp({"
script_35=STRING|"    query: null,"
script_36=STRING|"    cars: [],"
script_37=STRING|"    filter() {"
script_38=STRING|"        if (!this.query) return;"
script_4=STRING|"import json"
script_40=STRING|"        this.cars = CARS.filter((c) => {"
script_41=STRING|"            for (let i=0; i<c.length; i++) {"
script_42=STRING|"                if (c[i].toLowerCase().includes(this.query))"
script_43=STRING|"                    return true;"
script_44=STRING|"            }"
script_45=STRING|"            return false;"
script_46=STRING|"        });"
script_47=STRING|"    },"
script_48=STRING|"    go(id, page) {"
script_49=STRING|"        window.location.href = `/${id}/${page}`"
script_5=STRING|"from selenium import webdriver"
script_50=STRING|"    }"
script_51=STRING|"}).mount();"
script_53=STRING|"// Focus"
script_54=STRING|"setTimeout(() => {"
script_55=STRING|"    document.getElementById('input').focus();"
script_56=STRING|"}, 100);"
script_58=STRING|"</script>"
script_6=STRING|"from selenium.webdriver.chrome.options import Options"
script_60=STRING|"<body>"
script_62=STRING|"    <div class='content' v-scope>"
script_63=STRING|"        <input placeholder='Search' v-model='query' @input='filter' id='input'>"
script_64=STRING|"        <table>"
script_65=STRING|"            <tr class='table-head'>"
script_66=STRING|"                <th>ID</th>"
script_67=STRING|"                <th>Plate</th>"
script_68=STRING|"                <th>NAT-Code</th>"
script_69=STRING|"                <th>Brand</th>"
script_7=STRING|"from flask import Flask"
script_70=STRING|"                <th>Model</th>"
script_71=STRING|"                <th>Type</th>"
script_72=STRING|"                <th>Page</th>"
script_73=STRING|"            </tr>"
script_74=STRING|"            <tr v-for='car in cars' :key='car[0]' class='table-row' @click='go(car[0], car[6])'>"
script_75=STRING|"                <td>{{car[0]}}</td>"
script_76=STRING|"                <td>{{car[1]}}</td>"
script_77=STRING|"                <td>{{car[2]}}</td>"
script_78=STRING|"                <td>{{car[3]}}</td>"
script_79=STRING|"                <td>{{car[4]}}</td>"
script_80=STRING|"                <td>{{car[5]}}</td>"
script_81=STRING|"                <td>{{car[6]}}</td>"
script_82=STRING|"            </tr>"
script_83=STRING|"        </table>"
script_84=STRING|"    </div>"
script_86=STRING|"</body>"
script_87=STRING|"</html>"
script_89=STRING|"<style>"
script_9=STRING|"USERNAME = 'CENSORED'"
script_90=STRING|"    * {"
script_91=STRING|"        font: ""Trebuchet MS"" sans-serif;"
script_92=STRING|"    }"
script_93=STRING|"    .content {"
script_94=STRING|"        margin-left: 10%;"
script_95=STRING|"        width: 80%;"
script_96=STRING|"    }"
script_97=STRING|"    input {"
script_98=STRING|"        width: 100%;"
script_99=STRING|"        height: 32px;"
script_count=STRING|"203"
script_type=STRING|"0"
search_paths_0=STRING|"C:\Users\SEK\Documents\SEK\Dossiers"
search_paths_count=STRING|"1"
use_embedded=STRING|"1"


Last edited by snowseals on Thu Sep 30, 2021 1:50 pm, edited 1 time in total.
Oleg
Site Admin
Posts: 3000
Joined: Thu Jan 01, 1970 1:00 am
Contact:

Re: Python can't find dependency

Post by Oleg »

Are you sure that selenium module is in this path ?

Code: Select all

C:\Users\SEK\Documents\SEK\Dossiers
Maybe you must use your own copy of Python engine (not embedded) where you installed all necessary modules
Image
Oleg Yershov
snowseals
Posts: 59
Joined: Mon Apr 11, 2016 10:17 am

Re: Python can't find dependency

Post by snowseals »

Strangely enough when I enter 'where python3' in CMD, it shows the following:
Image

As in some built-in Python version?


Hence I don't think that will solve it to point it towards this location?
snowseals
Posts: 59
Joined: Mon Apr 11, 2016 10:17 am

Re: Python can't find dependency

Post by snowseals »

When I try to point it towards that Python3 it shows I don't have access:

Image
Last edited by snowseals on Thu Sep 30, 2021 12:58 pm, edited 1 time in total.
snowseals
Posts: 59
Joined: Mon Apr 11, 2016 10:17 am

Re: Python can't find dependency

Post by snowseals »

Even weirder... it's 0b?

Image
snowseals
Posts: 59
Joined: Mon Apr 11, 2016 10:17 am

Re: Python can't find dependency

Post by snowseals »

It is refering to chromedriver of selenium:
Image

Which is located in the assigned path:
Image
snowseals
Posts: 59
Joined: Mon Apr 11, 2016 10:17 am

Re: Python can't find dependency

Post by snowseals »

When I run it locally in CMD, it does work:
https://i.imgur.com/zfVOKBI.mp4
Oleg
Site Admin
Posts: 3000
Joined: Thu Jan 01, 1970 1:00 am
Contact:

Re: Python can't find dependency

Post by Oleg »

Embedded python is in folder
C:\ProgramData\RoboTask\Python64
or
C:\ProgramData\RoboTask\Python32

This instance contains only necessary modules
If you have prepared instance of Python you can use it

BTW: where command show file in path only
Oleg Yershov
Oleg
Site Admin
Posts: 3000
Joined: Thu Jan 01, 1970 1:00 am
Contact:

Re: Python can't find dependency

Post by Oleg »

snowseals wrote:When I run it locally in CMD, it does work:
https://i.imgur.com/zfVOKBI.mp4
I saw you movie
use you own Python in RoboTask (field "Use specified Python")

Code: Select all

C:\Users\SEK\Documents\SEK\Dossiers\python3.exe
Oleg Yershov
Oleg
Site Admin
Posts: 3000
Joined: Thu Jan 01, 1970 1:00 am
Contact:

Re: Python can't find dependency

Post by Oleg »

In your movie you are using
C:\Users\SEK\Documents\SEK\Dossiers\python3.exe

Use it in RoboTask too.
Oleg Yershov
Post Reply