This question already has answers here:
Pycharm and sys.argv arguments
(12 answers)
Closed 2 years ago.
I am trying to grab the 1st and 2nd argument using sys but i am unable to do so this is the code i am using :
import sys
import os
from PIL import Image
image_folder=sys.argv[1]
image_folder2=sys.argv[2]
print(image_folder)
this is the error
File "C:/Users/hp/PycharmProjects/test sys/test.py", line 4, in
image_folder=sys.argv[1]
IndexError: list index out of range
Any kind of help is appreciate[enter image description here][2]
You need to pass the command line arguments from the run configuration.
Related
This question already has answers here:
Qt module alternative for PyQt6
(2 answers)
Closed 1 year ago.
I'm trying to port a code from PyQt5 to PyQt6, but the following error occur:
AttributeError: type object 'QImage' has no attribute 'Format_RGB888'
It happens with any Format_*, although in the PyQt6 QImage documentation these formats are present.
Python 3.9 installed with miniforge, Mac M1 with OS X 11.5.2
Thanks.
Ok, found the solution myself.
Although in PySide6's doc ( https://doc.qt.io/qtforpython/PySide6/QtGui/QImage.html ) these constants are still written in PyQt5's way, they are now stored in the Format enum. The port from PyQt5 to PyQt6 is then:
PyQt5:
QImage.Format_RGB888
PyQt6:
QImage.Format.Format_RGB888
This applies to all Format_* constants of QImage.
This question already has answers here:
ImportError: cannot import name namedtuple
(2 answers)
Closed 3 years ago.
I am currently working in PYCHARM and it gives me the error whenever I run the program. I tried various methods to remove this error but to no avail.
What can I do to fix this issue?
import re
File "F:\Anaconda\envs\tensorflow\lib\re.py", line 125, in <module>
import functools
File "F:\Anaconda\envs\tensorflow\lib\functools.py", line 21, in <module>
from collections import namedtuple
ImportError: cannot import name 'namedtuple'
Check the module in stdlib named types, it gets imported instead.
You can either rename your module, or switch to absolute imports.
Hope this will help you.
This question already has answers here:
QWidget: Must construct a QApplication before a QPaintDevice
(2 answers)
Must construct a QApplication before a QWidget & Invalid parameter passed to C runtime function
(3 answers)
Update PyQt widget through ipython/jupyter notebook cells
(1 answer)
Closed 3 years ago.
I am now learning pyQT and I would like to do something that is presumably not difficult, but for which I could not find any satisfactory answer on the internet : Create a function using pyQT5 that just opens the standard file dialog of Windows or Ubuntu from iPython and returns the filepath (and filename).
My first attempts from tutorials found online ( https://www.tutorialspoint.com/pyqt/pyqt_qfiledialog_widget.htm ) were not successful. It looks something like:
from PyQt5.QtWidgets import (QMainWindow, QTextEdit,
QAction, QFileDialog, QApplication)
from PyQt5.QtGui import QIcon
def test_dialog():
dlg = QFileDialog()
dlg.setFileMode(QFileDialog.AnyFile)
if dlg.exec_():
filenames = dlg.selectedFiles()
return filenames
if __name__ == '__main__':
test_dialog()
I use the latest versions of anaconda distribution with Python 3.7.3 and pyQT 5.9.2 .
This question already has answers here:
I'm getting an IndentationError. How do I fix it?
(6 answers)
Closed 4 years ago.
When i compile this code, it gives me an error right there...
import pygame, sys, random, time
check_errors=pygame.init()
if check_errors[1]!=0:
print("(!) Had {0} initializing errors, exiting...".format(check_errors[1]))
sys.exit(-1) #ON this line says:IndentationError: unindent does not match any outer indentation level
else:
print("(+) PyGame successfully initialized!")
I tried some stuff but cant make it work, im a newbee as you can see.
edit: that wasnt a problem i misstyped it...
You have a " " before the import line 1.
This question already has an answer here:
Selenium - visibility_of_element_located: __init__() takes exactly 2 arguments (3 given)
(1 answer)
Closed 6 years ago.
Recently , I want to make a web crawler ,and I am newbie in programming. I know this error is common in stackoverflow.com ,but I studied and tried million times .It's still failed.
Below is my code , it's semi-finished.
import requests
import time
from bs4 import BeautifulSoup
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import WebDriverWait
chrome_path = "C:\Program Files\Anaconda3\Scripts\chromedriver.exe"
web = webdriver.Chrome(chrome_path)
web.get('https://www.agoda.com/zh-tw/pages/agoda/default/DestinationSearchResult.aspx?asq=%2bZePx52sg5H8gZw3pGCybdmU7lFjoXS%2baxz%2bUoF4%2bbAP7QU5sGtWmrzIvlWpeSVhG7hBqSW0J1d8hA8mgoocSdtpIj66gXToDH6PLoebpS2%2b7zRXCrzWTxWGJcCS2%2b98%2bkomkepA8A1QWe2FGYglfZpxj%2fA%2bylTfAGs1qJCjm9nxgYafyEWBFMPjt2sg351B&city=18343&tick=636125544363&isdym=true&searchterm=%E5%A2%BE%E4%B8%81&pagetypeid=1&origin=TW&cid=-1&htmlLanguage=zh-tw&checkIn=2016-10-25&checkOut=2016-10-26&los=1&rooms=1&adults=2&children=0&isFromSearchBox=true&ckuid=db61c7c8-1cf8-4b14-9c04-9c8aababbac5')
soup=BeautifulSoup(web.page_source,"lxml")
#wait=ui.WebDriverWait(web,10)
a=1
hotelname=web.find_elements_by_class_name("hotel-name")
try:
while len(soup.select('.btn-right')) >0:
print("page",a)
a=a+1
for number,name in enumerate(hotelname):
print(number,name.text.strip())
#time.sleep(1)
if len(soup.select('.btn-right'))>0 :
web.find_element_by_id("paginationNext").click()
soup=BeautifulSoup(web.page_source,"lxml")
hotelname=web.find_elements_by_class_name("hotel-name")
else:
break
web.close()
except:
time.sleep(3)
print("wake up")
WebDriverWait(web,10).until(EC.element_to_be_clickable(By.XPATH,"//button[#data-selenium='pagination-next-btn']"))
web.find_element_by_id("paginationNext").click()
print("click ok")
When I run this code , I get the error message:
File "C:/Users/Elvis/.spyder-py3/driver2.py", line 77, in
WebDriverWait(web,10).until(EC.element_to_be_clickable(By.CLASS_NAME,"pagination-next-btn"))
TypeError: __init__() takes 2 positional arguments but 3 were given
I guess that there is a bug in this line
WebDriverWait(web,10).until(EC.element_to_be_clickable(By.XPATH,"//button[#data-selenium='pagination-next-btn']"))
I just want to check this button is clickable, or wait for 10 seconds.
I try to adjust the path and tag much times, but doesn't work.
By the way, I use python3 , win10 and chromedriver.
If you have idea ,please help me ,I really want solve this problem and finish my first web-crawler.
Thank you.
enter image description here
You should give tuple of args to element_to_be_clickable((locator type, locator)), but not two separate args element_to_be_clickable(locator type, locator)
WebDriverWait(web,10).until(EC.element_to_be_clickable((By.XPATH,"//button[#data-selenium='pagination-next-btn']")))