0

I am new to python. I am using VS code on Windows. Following is my simple python code.

from selenium import webdriver

browser = webdriver.Firefox()
browser.get('http://seleniumhq.org/')

I am trying to install selenium package but it is giving me error ModuleNotFoundError: No module named 'selenium'. I tried following commands.

conda install selenium
python -m pip install -U selenium

Then I tried in a virtual env

conda create -n selenium-env python=3.6
conda activate selenium-env
conda install -n selenium0env selenium 

Still getting the same error. Update:

I noticed that when I first run the py file after restarting VS code, it activates one of my virtual environments automatically. I think that virtual env does not have selenium installed in it. Below is the terminal output when I run the py file

How do I stop that environment from getting activated automatically? I want to run this in a different environment.

PS D:\Learnings\Python\SampleDesktopApp> conda activate pyfinance

PS D:\Learnings\Python\SampleDesktopApp> & 

C:/Users/rajen/anaconda3/envs/pyfinance/python.exe 
d:/Learnings/Python/SampleDesktopApp/Test.py

Traceback (most recent call last):

  File "d:\Learnings\Python\SampleDesktopApp\Test.py", line 1, in <module>

    from selenium import webdriver

ModuleNotFoundError: No module named 'selenium'

PS D:\Learnings\Python\SampleDesktopApp> 
0

2 Answers 2

1

Well first things first update your pip.

Use the command: python -m pip install --upgrade pip if that doesn't work then there is a chance there's a bug in your Python or site-packages directory. Uninstall Python and then reinstall the latest version and it should work then.

Side note: Once you get selenium working, you can't just initialize Firefox or Chrome without having their respective drivers. for Firefox its geckodriver.exe https://github.com/mozilla/geckodriver/releases for Chrome its chromedriver.exe https://chromedriver.chromium.org/downloads

Once you have the driver installed you have to include the driver in the Webdriver argument executable_path like so:

    driver = webdriver.Firefox(executable_path="drivers/geckodriver.exe")

Update

Conda is automatically running the virutalenv so instead of using command conda activate pyfinance.

try running with just simple: python pyfinance.py

Sign up to request clarification or add additional context in comments.

1 Comment

Upgrade did not help. Thanks for info on setting up driver. I am going to do that. But I need to get rid of package issue first. I have updated the question. Please guide me if you can before I uninstall the python
0

I was installing the selenium in one environment and running py file in another. So I used VS code option Python: Select Interpreter to change the environment while running the file. It worked.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.