0

I have a script that is set up to install dependencies if they are not already installed. The code for this is below:

import importlib
try:
    importlib.import_module('selenium')
    importlib.import_module('win32com.client')
    importlib.import_module('keyboard')
except ImportError:
    import pip
    pip.main(['install', 'selenium', '--trusted-host'])
    pip.main(['install', 'pypiwin32' '--trusted-host'])
    pip.main(['install', 'keyboard', '--trusted-host'])
finally:
    globals()['selenium'] = importlib.import_module('selenium')
    globals()['win32com.client'] = importlib.import_module('win32com.client')
    globals()['keyboard'] = importlib.import_module('keyboard')

This works fine on my computer and several of my colleagues', but the rest of my team (on the same network at the same location) can't get this to run. The issue appears to be with pip at first -- it throws an SSL error even when called directly from the command line with "pip install selenium" (and even with "pip install --trusted-host pypi.python.org"):

Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError(SSLError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certification verify failed (_ssl.c:833)'),)': /simple/selenium

I found this post which led me to try the --trusted-host solution without success. I checked C:Program Data/ and there was no "pip" folder there, so I created one and created a pip.ini config file. (NOTE: There was no config file at the user level either. I confirmed Pip was installed).

In the pip.ini file I copy/pasted the solution from that thread:

[global]
trusted-host pypi.python.org
    pypi.org
    files.pythonhosted.org

Now I get the error:

configparser.ParsingError: Source contains parsing errors: 'C:\\ProgramData\\pip\\pip.ini' 
  [line 2]: 'trusted-host pypi.python.org\n' 
  [line 3]: etc etc etc 
  [line 4]: etc etc etc

To see if I could bypass this process, I used easy_install to install selenium (successfully) but it was unable to locate pywin32. It found keyboard but when running setup.py for that module it gave me an error "No such file or directoyr: 'CHANGES.md'.

To summarize my questions:

  1. Why would there be differences between computers on the same network in being able to use pip and access pypi.python.org? (Additionally, does the absence of pip folders and pip.ini files with the default installation raise any red flags?)

  2. Why is "pip install --trusted-host pypi.python.org selenium" failing?

  3. What is going wrong with my config file parsing?

  4. Is there a reason easy_install cannot find pywin32?

ipenguin67
  • 1,483
  • 5
  • 22
  • 39
  • 1
    Try `pip install --trusted-host pypi.org selenium`, does it work? Also, in `pip.ini` you have to separate keya and values by colon or equality sign, for example `trusted-host=pypi.org`. – hoefling May 01 '18 at 17:53
  • 1
    this is probably related to the new version of pip being released which no longer supports the old ssl certs --> https://stackoverflow.com/questions/49748063/pip-install-fails-for-every-package-could-not-find-a-version-that-satisfies-th/49748494#49748494 – eagle May 01 '18 at 17:54
  • Are your colleagues using either an oldish version of Python (more than a few patch versions ago in 2.7, not sure how back in 3.x) on Windows, or using Apple's pre-installed Python 2.7 on macOS before High Sierra? Also, do some of them have pip 10 and others pip 9 or earlier? (Basically, new pip with old Python is a problem, especially on Windows and on Mac 10.6-10.12, for different reasons). – abarnert May 01 '18 at 17:54
  • It looks like the missing equal sign did the trick (I also had them update pip just in case, but it seemed to work ok to do it from the windows cmd line via "python -m pip install --upgrade pip") – ipenguin67 May 01 '18 at 19:12

0 Answers0