vscode on Ubuntu is unable to open windows - python-3.x

I'm having issues with vscode on Ubuntu running particular Python code (that seemingly relies on porting or connecting to an external application). The same code will run fine if I execute it directly from an Ubuntu terminal with the same env on the same machine.
Here's a couple of examples.
When I try to initiate vedo.plotter.Plotter() when running from vscode, I get this error:
ERROR: In /work/standalone-x64-build/VTK-source/Rendering/OpenGL2/vtkXOpenGLRenderWindow.cxx, line 1223
vtkXOpenGLRenderWindow (0x5587f7b42cf0): bad X server connection. DISPLAY=Aborted (core dumped)
If I run the same code directly in terminal, it runs fine, so this is an issue with the way vscode is configured, but I can't find any answers online. I've played with a few settings in vscode but with no success.
This seems to be an issue on all vscode installations I have running on Ubuntu (in this case 20.04). Here's the vscode info:
Version: 1.51.0
Commit: fcac248b077b55bae4ba5bab613fd6e9156c2f0c
Date: 2020-11-05T18:16:10.374Z
Electron: 9.3.3
Chrome: 83.0.4103.122
Node.js: 12.14.1
V8: 8.3.110.13-electron.0
OS: Linux x64 5.4.0-52-generic snap
Similarly, I'm unable to open up browser windows from vscode (for example plotly fig.show() and selenium driver = webdriver.Chrome(chromedriver) won't open browser windows. I get the following error with selenium:
selenium.common.exceptions.WebDriverException: Message: unknown error: Chrome failed to start: exited abnormally.
(unknown error: DevToolsActivePort file doesn't exist)
Again, this works fine direct from the terminal and everything works fine if run from a Windows or Mac installed vscode, so this is specific to this Ubuntu install.
I'd really appreciate any help!
Jonny

Related

Python 3 - selenium on xvfb-run- cannot process extension

I need to automate tasks to extract information from websites using the uBlock plugin with Chrome driver using the selenium module in Python 3.
I am running my code remotely without a GUI on the remote machine - for that I am using xvfb-run to simulate a desktop environment where Chrome launches with a specific window size.
The remote machine has the following Debian operating system:
uname -a
Linux mem 4.19.0-10-amd64 #1 SMP Debian 4.19.132-1 (2020-07-24) x86_64 GNU/Linux
These were the steps I took to configure my environment and code on the remote machine:
1 - To configure my environment, I installed this version of Google Chrome:
google-chrome --version
Google Chrome 86.0.4240.111
2 - Check the versions of Python 3 and selenium I installed:
python --version
Python 3.7.3
pip freeze
selenium==3.141.0
3 - Check the xvfb-run version:
apt-cache policy xvfb
2:1.20.4-1+deb10u1
4 - With these packages configured, I obtained the chromedriver_linux64.zip from this list (the version 86.0.4240.22 below is the most recent one that is the same major version of the installed google-chrome):
https://chromedriver.storage.googleapis.com/index.html
https://chromedriver.storage.googleapis.com/index.html?path=86.0.4240.22/
5 - To be able to use the uBlock extension of Chrome, I needed to install an extension that is able to produce a .crx archive file of other installed extensions.
For this, I used CRX Extractor/Downloader:
https://chrome.google.com/webstore/detail/crx-extractordownloader/ajkhmmldknmfjnmeedkbkkojgobmljda
6 - After using that extension, I got my ublock.crx file to test.
I managed to use the binary in chromedriver_linux64.zip without the extension to launch a Chrome instance and do some basic crawling.
But when I tried to use ublock.crx in my code, I got an exception.
The code was this:
This is the exception produced:
ublock.crx error
selenium.common.exceptions.SessionNotCreatedException: Message: session not
created: cannot process extension #1
from unknown error: cannot unzip
I am launching it from my program like this:
from selenium import webdriver
option = webdriver.ChromeOptions()
option.add_extension(ublock_crx_file_path)
driver = webdriver.Chrome(executable_path=driver_path, options=option)
I have made sure the path of ublock_crx_file_path is valid and points to the file I obtained from Chrome.
Hopefully someone can shed light on this?

OpenCV 4.4.0: qt.qpa.xcb: could not connect to display on a remote EC2 instance. How to solve this issue?

I am running the Opencv 4.4.0 in a Ubuntu 20.04 AWS-Ec2 instance connected with VSCODE trough the Remote Explorer module.
I am trying to open an image that I have uploaded to the project.
import cv2
img = cv2.imread("imgs/cat1.jpg")
cv2.imshow("Output", img)
But when I run the file (pressing the green arrow) I get the follow error:
(env) ubuntu#ip-xxx-xx-xx-xxx:~/vhosts/opencv-ml-images$ /bin/python3 /home/ubuntu/vhosts/opencv-ml-images/chapter1.py
qt.qpa.xcb: could not connect to display
qt.qpa.plugin: Could not load the Qt platform plugin "xcb" in "/home/ubuntu/.local/lib/python3.8/site-packages/cv2/qt/plugins" even though it was found.
This application failed to start because no Qt platform plugin could be initialized. Reinstalling the application may fix this problem.
Available platform plugins are: xcb.
Aborted (core dumped)
Does someone knows what is happening? maybe something related to the fact I am running the opencv in a remote computer? How to sove it?
I think what you are trying to do is run it on Remote Desktop Connection. I was having the same problem but I am running WSL 2 (Both are quite similar). And I solved it by setting up environment for GUI applications on WSL 2 from https://wiki.ubuntu.com/WSL . Just start your X server and run the code again. It should work. If not, do reply so that we can sort it out together.

AttributeError: 'LifoQueue' object has no attribute 'put' selenium webdriver

I have installed selenium and the chrome web driver and made it accessible via the path variable of my operating system (using Linux virtual machine on windows and python3). I run this simple code and get the below error. Any ideas as to what may cause this error?
Thanks in advance!
Selenium version installed:
selenium-3.141.0 urllib3-1.25.8
Chrome driver installed (latest version for chrome browser 80) :
ChromeDriver 80.0.3987.106 (f68069574609230cf9b635cd784cfb1bf81bb53a-refs/branch-heads/3987#{#882})
Chrome browser installed :
Google Chrome 80.0.3987.132
Python version :
Python 3.6.9
import selenium
from selenium import webdriver
options = webdriver.chrome.options.Options()
options.add_argument('--no-sandbox')
options.add_argument('--disable-dev-shm-usage')
chromedriver = '/usr/bin/chromedriver'
print('test0') #is being printed
driver = webdriver.Chrome('/usr/bin/chromedriver',options=options)
print('test') #not being printed
driver.get('http:google.com')
Error message when running the code : The process started from chrome location /usr/bin/google-chrome is no longer running, so ChromeDriver is assuming that Chrome has crashed.
When I try to run google-chrome with (sudo google-chrome) I get this message:
[56:56:0316/235226.650275:ERROR:zygote_host_impl_linux.cc(89)] Running as root without --no-sandbox is not supported. See https://crbug.com/638180.
I tried modifying the google-chrome file in the /usr/bin but it is read-only so the workaround I found online was to add the options '--no-sandbox' in my code above. But hasn't resolved the issue.
Resolved : had a python file named queue in working directory and had to rename it
Solution:
This error "AttributeError: 'LifoQueue' object has no attribute 'put' selenium webdriver" is caused by having in your working directory a file with the name Queue. Rename that.
For this error "The process started from chrome location /usr/bin/google-chrome is no longer running, so ChromeDriver is assuming that Chrome has crashed."
If you tried all possible solutions and still get issues then if you are using Linux virtual machine that seems to be causing the problem and I suggest to install docker desktop on windows and download a docker image with all the libraries you will be needing to run selenium apps .

CasperJS with Slimerjs - Xlib: extension "RANDR" missing on display ":99"

I am trying to running Casperjs with Slimerjs
I Installed SlimerJS 0.10.2
I have installed Mozilla Firefox 45.5.1 (tried with 50 too)
I have installed CasperJS 1.1.3
I have installed xvfb 1.17.4
Running on Centos 6.8
When tried to run a casperjs+slimerjs from php I get:
Gecko error: it seems /usr/bin/firefox is not compatible with SlimerJS.
See Gecko version compatibility. If version is correct, launch slimerjs
with --debug=true to see Firefox error message
When I try to run a script from console with debug=true like:
/usr/local/bin/casperjs /tmp/casperjs-5cn484 --debug=true --engine=slimerjs
(I tried with xvfb-run too)
I get this error:
Xlib: extension "RANDR" missing on display ":99".
process 5588: D-Bus library appears to be incorrectly set up; failed to read machine uuid: Failed to open "/var/lib/dbus/machine-id": No such file or directory
See the manual page for dbus-uuidgen to correct this issue.
D-Bus not built with -rdynamic so unable to print a backtrace
Redirecting call to abort() to mozalloc_abort
/usr/lib/node_modules/slimerjs/src/slimerjs: line 167: 5588 Segmentation fault "$SLIMERJSLAUNCHER" -app "$SLIMERDIR/application.ini" $PROFILE -no-remote "$#"
if i run slimerjs --debug=true, I get:
Error: cannot open display: :1.1
Gecko error: it seems /usr/bin/firefox is not compatible with SlimerJS.
See Gecko version compatibility. If version is correct, launch slimerjs
with --debug=true to see Firefox error message
I already tried a lot of solution, like:
tried: Xvfb :1 -screen 0 1024x768x24 +extension RANDR & and export DISPLAY=:1 (with :99 too)
tried export LD_LIBRARY_PATH=/usr/lib/x86_64-linux-gnu/
upgrade downgrade firefox version
check if there was fonts, there is one, so no problem
I don't know what I am trying anymore, some suggestions? : )
Anyway I get it running installing dbus package and with the comand:
dbus-uuidgen > /var/lib/dbus/machine-id
The Xlib: extension "RANDR" missing on display ":99" isn't a big issue...
from:
http://www.torkwrench.com/2011/12/16/d-bus-library-appears-to-be-incorrectly-set-up-failed-to-read-machine-uuid-failed-to-open-varlibdbusmachine-id/
Did you see this issue? Apparently you should:
Change the max version in src/application.ini
MaxVersion=45.*
I'm not sure about the xrandr error but it seems unrelated. Could be a result of experimentation or a red herring.
There's also a DBUS error that could be causing the subsequent segmentation fault.
I suggest you try to check it step by step:
see that firefox is working
X forwarding might help here, it would bring up the remote firefox window locally
make sure that firefox is working headless
you could generate an xvfb screenshot
check with slimerjs
check with your PHP wrapper script

pywin32 running 32bit windows service on 64bit OS

I am running 32bit python application on old Windows Server 2003 using pywin32 package and it's working fine. Lately I've received new Server with windows Server 2012 64bit OS and I started installing the same application. While it didn't run under 64bit Python 3.4 I've installed 32bit version and it's working fine when I am running it from command line.
The problem starts when I want to run it as windows service. It installs and looks ok but it doesn't start.
I am receiving following error: The service is not responding to the control function.
More help is available by typing NET HELPMSG 2186.
When I check pythonservice.exe it shows me following error:
PythonService was unable to locate the service manager. Please see the event log for details
Is there any way I could run it as it does run under 32bit?
Thanks,
Mike

Resources