Issue
I created a virtualenv in python and then installed with all modules needed to my project.
requests certifi beatifulsoap4 ...
If i run the program in the integrated terminal in visual studio code, it works fine. But If use de command "Run Code" - CTRL+Alt+N - in visual studio code I get the follow error
from selenium import webdriver
ImportError: No module named selenium
I already changed the python path to point to my virtualenv but problem persist.
{
"files.autoSave": "afterDelay",
"python.pythonPath": "env/bin/python3"
}
If i change my code to not use selenium, then the "Run Code" command works fine (eveen with others imports)
Solution
I have the same problem, Selenium was installed but Visual Studio was not able to import it. In Laymen's term:
The thing is Selenium is installed but VS Code can't access it, and you need link both them.
That's how I solved it.
- Uninstall Selenium using
pip uninstall selenium
- Then create a New Folder on your preferred location, (Like Desktop, or D drive, etc.)
- Open that folder in Visual Studio Code.
- Now go to the Terminal of VS Code and create a Virtual Environment (Google python Virtual Environment if you don't know how to create one)
- Then, install selenium in that virtual Environment using
pip install selenium
- You will see some files are included in your folder after pip
install selenium (
pipfile
andpipfile.lok
) - Lastly, install pyLint to your virtual environment using
pipenv install pylint --dev
If you still get an error, open your command-line and install selenium on your PC. Previously we installed it only in our virtual environment.
Answered By - Raj Dhakad Answer Checked By - Marilyn (WPSolving Volunteer)