ImportError when rum a SB script in a Docker #2681
-
Hi folks, I have a problem running a script using SB when I build a docker container. The script runs fine on my local machine, it also runs fine when I go through the interactive docker using "docker run -i -t seleniumbase", then I go inside the folder where the script is, and run with "python myscript.py". The problem is happening when I'm trying to run it on the container startup. When I try to do it I got the error: "ImportError: No module named seleniumbase" I tried to do it with Dockerfile like that: And also building the seleniumbase container and running it like this: Here is the myscript.py content: from seleniumbase import SB
driver = SB(uc=True, xvfb=True, headed=True)
with SB() as sb:
try:
sb.driver.get("https://bot.sannysoft.com/")
print(sb.driver.get_page_source())
finally:
sb.driver.quit() Can anyone help me with that? |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 3 replies
-
It doesn't look like Try: pip install seleniumbase Maybe you need something like this if you have multiple Python environments on your system: python3 -m pip install seleniumbase |
Beta Was this translation helpful? Give feedback.
-
Doesn't these lines on the selenium Dockerfile do this? #=====================
# Set up SeleniumBase
#=====================
COPY sbase /SeleniumBase/sbase/
COPY seleniumbase /SeleniumBase/seleniumbase/
COPY examples /SeleniumBase/examples/
COPY integrations /SeleniumBase/integrations/
COPY requirements.txt /SeleniumBase/requirements.txt
COPY setup.py /SeleniumBase/setup.py
RUN find . -name '*.pyc' -delete
RUN find . -name __pycache__ -delete
RUN pip3 install --upgrade pip setuptools wheel
RUN cd /SeleniumBase && ls && pip3 install -r requirements.txt --upgrade
RUN cd /SeleniumBase && pip3 install . |
Beta Was this translation helpful? Give feedback.
-
I'm using exactly this Dockerfile, I just added my this line to copy run_test_bot.sh The script myscript.py is inside the examples folder COPY integrations/docker/run_test_bot.sh / The content of the run_test_bot.sh is: #!/bin/bash
set -e
# Run example test from inside Docker image
echo "Running example SeleniumBase test from Docker with Chrome..."
cd /SeleniumBase/examples/ && python myscript.py --browser=chrome
exec "$@" Look at the screenshot, It works fine with the docker test, but when I try to run my script, module not found :( |
Beta Was this translation helpful? Give feedback.
-
I don't know if you've already managed to solve your problem, but I had a similar import problem with another package and I managed to solve it using "-m". Examples:
or
|
Beta Was this translation helpful? Give feedback.
It doesn't look like
seleniumbase
was ever installed on your system.Try:
Maybe you need something like this if you have multiple Python environments on your system: