~
is a string, so it is not going the evaluated as expected.
You can make use of expanduser to get the user’s home directory:
import os
def ensure_dir():
home = os.path.expanduser("~")
if platform.system() == ('Windows'):
chromeDir = os.path.join(home, '/Drivers/Google/Chrome/chromedriver')
if not os.path.exists(chromeDir):
...
CLICK HERE to find out more related problems solutions.