简体   繁体   中英

Can't find Selenium module running Python

I have Python 3.6 installed on my machine (Mac), and the Anaconda package as a whole. I am trying to run a simple script in PyCharm that looks like the following:

from selenium import webdriver
browser = webdriver.Firefox()
type(browser)
browser.get('http://inventwithpython.com')

When I run that I get the error message: 'Import error. No module named Selenium'.

EDIT: Here is the full stack trace that was requested below (Sorry, if this is not the full stack trace let me know):

Traceback (most recent call last): File "/Users/xxxx/PycharmProjects/StringsLoops/Selenium.py", line 1, in from selenium import webdriver ImportError: No module named 'selenium'

Process finished with exit code 1

I tried installing Selenium again using:

pip install selenium

and it installed successfully. I then ran my program again, same error. After some googling I tried:

python3 -m pip install selenium

That gave the following error:

'Requirement already satisfied: selenium in /Users/xxxx/anaconda/lib/python3.6/site-packages'

So I am lost at this point at what to do. I know a while back this used to work but that was before I:

A. upgraded OS to Mac OSX- Sierra

B. installed Anaconda (before I just had Python on my machine as a standalone and installed Selenium as a standalone)

Any ideas?

Thanks

Since it sounds like your code is working properly in the terminal but not in PyCharm, it leads me to believe that PyCharm isn't properly configured. Try setting the default interpreter for PyCharm to the Anaconda python verson: https://www.jetbrains.com/help/pycharm/configuring-python-interpreter-for-a-project.html .

Ideally, you should make a new environment and select "Add Local" when selecting your interpreter.

Hey I know this is a late reply but i figured out a way how you can fix this first of all the problem is within pycharm because if you already installed a module succefully that means IT'S INSTALLED !!! now for the solution : ---Go to files in the up-left corner scroll down and click on settings than look for a tab that says project:(your project name) click on that it will give you two options click on python interperter then choose your project name through the project interperter list after that you will see a "+" sign on your right hand side click on that then a tab will pop up than head over to the search bar above and type your package/module name which in this case is selenium then select it from the list presented and click on install package THAT'S IT !!!!!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM