I am playing around with this repo:
https://github.com/timgrossmann/InstaPy
I have cloned the repo, installed Python 3.6, Selenium, py virtual driver (Although I am not sure if I have to save it somewhere).
I have two questions:
1) How do I set up a path for PY command? -- What does that mean exactly? And what does it do? I have googled that, and I don't have any Python experience so I am having a hard time understanding it.
2) I have downloaded chromedriver and put it in the assets, but I am having trouble figuring out if what I put there makes sense.
When I run chromedriver, I get this error: Only local connections are allowed.
[0.011][SEVERE]: bind() returned an error, errno=48: Address already in use (48). I have tried killing it, but it says there's nothing to kill.
And when I run python quickstart.py, I get this error Message: 'chromedriver' executable needs to be in PATH. Please see https://sites.google.com/a/chromium.org/chromedriver/home, which I am assuming is related to the fact that I didn't set a path.
If I run python instapy/login_util.py, I get File "instapy/login_util.py", line 2, in <module>
from .time_util import sleep
ValueError: Attempted relative import in non-package.
Sorry for the long message, I am just hoping to understand everything. I have read the docs and questions from the repo, but I still feel very confused
Try setting the path for chrome driver
import os
os.environ["Selenium_Chrom_Path"] = "/foo/path_to_chrome_exec"
Related
I was recently working with web automation, with Selenium and python, and I faced into the error almost everyone got.
from selenium import webdriver
window = webdriver.Firefox()
window.get("https://ecoledirecte.com")
But I looked up for several answers, and None of them worked ! I tried the solution for this question, but nothing changed. I checked several times, and the geckodriver is in PATH (I extracted the file into my Downloads folder, then moved the executable into my main folder). I checked if indicating the mozilla geckovriver folder in the calling of webdriver.Firefox() would help (webdriver.Firefox("C:\\Users\\user\\Downloads\\mozilla-geckodriver-9b5f85c")), but no.
Is there any reason for that ?
I think I once put it in my System32 folder (which is in PATH!) but this is probably a little sketchy. Wherever you put the geckodriver, you just have to add that location to your PATH environment variable.
Try following this instruction:
http://www.learningaboutelectronics.com/Articles/How-to-install-geckodriver-Python-windows.php
I believe you could also install in the same folder where your python file is located - it should probably pick up that folder (but I'm not sure).
this is an easy solution:
webdriver.Firefox(executable_path='Your full path to the geckodriver executable'+'geckodriver')
In order to install Selenium, step 3 on (this site indicates needing to install the chromedriver file in your PATH. I am on a work computer that does not have access to the system PATH directly. I have tried listing in the local PATH (I'm on Windows 7) variable chain like so: C:\Users\mknerr\AppData\Local\Programs\Python\Python36-32\Scripts\;C:\Users\mknerr\AppData\Local\Programs\Python\Python36-32\;C:\Users\mknerr\AppData\Local\atom\bin;C:\Users\mknerr\Programs\ChromeDriver\
(The .exe is in the ChromeDriver folder)
When I run the script with webDriver.Chrome(), I still get a WebDriverException that chromedriver needs to be in my PATH. If anyone has an idea why this isn't working from my local PATH, I'd love to hear them.
However, my real question is when I distribute this script to the rest of my team, they will likely have the same issue since my script will be calling chromedriver, which none of them will have installed, much less in their PATH. Can Python directly install a program or dependency in the PATH so they don't have to go directly accessing environment variables? I can guarantee nobody is going to feel comfortable doing that.
You can place chromedriver.exe in the same folder as the executable. Just run the program with the driver right next to it.
In our internal automation framework, we actually just distribute the Chromedriver executable as part of the framework, in the same folder as the framework's entry point.
Then, whenever we need a browser session, we do something similar to this:
import os
from selenium import webdriver
chromedriver_location = os.path.join(
os.path.dirname(os.path.abspath(__file__)), 'chromedriver.exe')
context.browser = webdriver.Chrome(executable_path=chromedriver_location)
chromedriver.exe is the default Windows name of the executable, of course; change to whatever you need.
This avoids any user setup other than installing the framework itself. No messing with PATH or any other local files.
Out of nowhere my scripts aren't finding locations anymore, that worked previously.
The only thing i changed was to add a environmental variable in Windows because i didn't get access python via the command line. But also after deleting it and resetting the "PATH" variable the problem is the same.
The error only occurs for modules in my project directory which i import via "from... import..."
no problem with "import sys" and so on.
I don't understand what's going on. I use eclipse and Python 2.7.
Update: I "auto configured" in the interpreter menu so that PYTHONPATH was rebuilt, i used File-->Restart but i won't damn work! I even removed the system environmental variable from windows. What is wrong with my setup?
Update2: Now i even reinstalled Eclipse but the f***ing errormessage is still there. It's driving me crazy! Anybody with more tips?
Update3: The problem occured after my laptop shut down because the battery was low. During that it was executing a script. Maybe it has sth. to do with the forced shutdown.
Ok, i found the solution.
Somehow the inner structure of my project got messed up, that the relative path in "from main.path1.path2 import ..." wasn't valid anymore.
Either it worked like "from path1.path2 import..." or (what i did) I created a project and included again the folder structure, but in the way that it works.
This is embarrassing to ask because it seems like something with so slim chance of error. I wouldn't think this would be difficult, but I've been plugging away at this for almost 3 hours now and it's giving me a headache. I've read several dozen stackoverflow threads and Google threads.
I've installed PhantomJS, added it to my System Variables PATH, and it works properly in the command line. I also installed Selenium earlier with easy_install.
The error I get is:
__init__ C:\Python27\lib\site-packages\selenium-2.39.0-py2.7.egg\selenium\webdriver\phantomjs\webdriver.py 50
start C:\Python27\lib\site-packages\selenium-2.39.0-py2.7.egg\selenium\webdriver\phantomjs\service.py 66
WebDriverException: Message: 'Unable to start phantomjs with ghostdriver.' ; Screenshot: available via screen
Here's my code:
from selenium import webdriver
driver = webdriver.PhantomJS(executable_path="C:\Python27\misc\phantomjs\phantomjs.exe")
I also tried:
from selenium import webdriver
driver = webdriver.PhantomJS()
I get the same error message. This has to be something simple that I'm doing wrong. I'd appreciate any comments or answers.
Windows 7 64 bit
Python 2.7
This may have been a version issue for you, but since I just went through setting this up on my Windows 7 PC without issues I'm going to share my 'journey' here.
First of, I'm more used to the Mac/Linux Terminal and having the python package manager pip at my disposal is essential to me. After installing Python 2.7.8 and adding ;c:\Python27 to my PATH I noticed that pip isn't included with Python versions lower than 2.7.9, so I had to add it myself. Afterwards I added ;c:\Python27\Scripts to my PATH.
After that fetching the python package selenium was as easy as typing the following into the cmd:
pip install selenium
Then I downloaded the phantomjs-1.9.7-windows.zip from here, unzipped it and placed it here:
C:\Python27\misc\phantomjs-1.9.7-windows\phantomjs.exe
From there I had a working Python 2.7/Selenium Webdriver/PhantomJS example for Windows 7.
from selenium import webdriver
import os
phantomjs_path = "C:\Python27\misc\phantomjs-1.9.7-windows\phantomjs.exe"
browser = webdriver.PhantomJS(executable_path=phantomjs_path, service_log_path=os.path.devnull)
browser.set_window_size(1400, 1000)
browser.get("https://stackoverflow.com/")
print browser.title
Note that I added the argument service_log_path=os.path.devnull to the function webdriver.PhantomJS() to prevent PhantomJS from creating a ghostdriver.log in the directory of the python file being executed.
I had the same problem running Python 3.4 on Windows Server 2012 R2. PhantomJS was failing to create the ghostdriver.log file. I followed these steps that fixed it for me:
Made sure phantomjs.exe was not showing "Blocked" on the File Properties|Security tab, and ran it as standalone app to confirm.
Deleted an old copy of the ghostdriver.log file that was in the same directory.
Ran python REPL from the console while checking to see if the code that instantiated the driver was getting called successfully.
browser = webdriver.PhantomJS(executable_path='phantomjs.exe', desired_capabilities=argdc, service_args=svc_args)
Do you any other file or directory with a same name , or a file of coding (like .. phantomjs.py) which you have named same as phantomjs is so then rename it to something else. i hope it works
I'll preface this question by saying that I've barely used python before, and never before on Mac OS, so I am fully ready to accept that I'm probably doing something rather silly!
I've been sent two python projects, one of which I need to run. When I open the project I'm interested in (in TextWrangler), and run, I get the following error:
context.py:16: ImportError: No module named fetch_command
Well.. fetch_command is a module in the other program, which is in the same directory (/Users/myname) as the program that I am trying to run. The (scant documentation for the applications suggests:
"I wouldn't try installing into your python installation dirs,
I'd install to some home directory or prefix and set up your
PYTHONPATH and PATH (or use virtualenv)"
and so I have tried (and succeeded - I've tested by calling echo $PATH and echo $PYTHONPATH) adding Users/myname to PATH and PYTHONPATH. This did nothing. I then tried adding /Users/myname/other_python_app/src to PATH and PYTHONPATH, but this also hasn't worked. Anyone know what I'm doing wrong..?
Thanks a lot in advance!
Ah, I understand the issue now. It's not that you can't find it in your Python project, but rather in your text editor. There should be a menu entry to set your PYTHONPATH from within TextWrangler (I tried looking for the documentation but the site seems to be down). Oftentimes, these editors don't respect the PYTHONPATH variable or do so only on restart.
This is a bit of a hack in your case, but try adding an empty file __init__.py so Python knows that this directory contains a module.