简体   繁体   中英

Installing selenium package for multiple anaconda versions

I have two python distributions on my computer. I can control where I should install which package so far. However, it is changed for selenium package. I have no idea about the reason and it is somehow installed into another location under VS side. In the current scenario, I expect that the selenium package should be installed on "C:\\Anaconda3\\Lib\\site-packages" but this is not the case for selenium.

Any overall understanding about the case and solution ?

from selenium import webdriver

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

Traceback (most recent call last):
  File "D:\workspace\PyRecetem\dynamic.py", line 1, in <module>
    from selenium import webdriver
ModuleNotFoundError: No module named 'selenium'

Current pip version is:

C:\WINDOWS\system32>pip -V
pip 19.0.3 from C:\Anaconda3\lib\site-packages\pip (python 3.7)

Installation command:

C:\WINDOWS\system32>py -3 -m pip install selenium
Requirement already satisfied: selenium in c:\program files (x86)\microsoft visual studio\shared\python37_64\lib\site-packages (3.141.0)
Requirement already satisfied: urllib3 in c:\program files (x86)\microsoft visual studio\shared\python37_64\lib\site-packages (from selenium) (1.25.8)

Installed python paths:

C:\WINDOWS\system32>where python
C:\Anaconda3\python.exe
C:\Anaconda2\python.exe

You said that

I have two python distributions on my computer.

But it looks like you have three:

C:\Anaconda3\python.exe
C:\Anaconda2\python.exe
C:\Windows\py.exe

The last probably got installed alongside visual studio, as the site-packages are at c:\\program files (x86)\\microsoft visual studio\\shared\\python37_64\\lib\\site-packages

So py -m pip install did not install to any of your anaconda installations but instead to the version that came with visual studio. Use

python -m pip install

to install to your anaconda3 distribution.

Side Note :

The reason for anaconda 2 and 3 at the same time, some of my projects are dependent on python2

This is a valid reason to wanting to keep two different python versions around. However, since anaconda comes with conda built in, the way to go would be to have virtual environments instead of different aanconda installations to avoid the ambiquity of different python installations in the same system. Simply do

conda create -n py27 python=2.7
conda create -n py37 python=3.7

and then you can conda activate whichever python version you might want

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