I just installed Selenium (from source) for Python 2.7.
When I try to import selenium, I get the following error:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Python27\lib\site-packages\selenium-2.25.0-py2.7.egg\selenium\__init__.py", line 16, in <module>
from .selenium import selenium
File "C:\Python27\lib\site-packages\selenium-2.25.0-py2.7.egg\selenium\selenium.py", line 19, in <module>
import http.client
ImportError: No module named http.client
What could be causing this? If I remember correctly, http.client is a python 3 module. Why is selenium trying to import it?
Thanks to the help of DSM, I figured it out. Because I had previously ran setup.py with a python3 executable by accident, the selenium build folder was populated with 2to3 converted code. When I later ran python27 setup.py install it ended up using the same build folder for the installation without overwriting its content. I ended up deleting the build folder and trying again, and it works.
Related
I am unable to import psutil when I activated python on my venv, its gives the following error message, which I cant resolve.
I tried to uninstall psutil and install psutil again but it still returns the same error.
>>> import psutil
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/wenlin.kwek/Documents/fp_churn/venv/lib/python3.7/site-packages/psutil/__init__.py", line 157, in <module>
from . import _psosx as _psplatform
File "/Users/wenlin.kwek/Documents/fp_churn/venv/lib/python3.7/site-packages/psutil/_psosx.py", line 16, in <module>
from . import _psutil_osx as cext
ImportError: dlopen(/Users/wenlin.kwek/Documents/fp_churn/venv/lib/python3.7/site-packages/psutil/_psutil_osx.cpython-37m-darwin.so, 2): Symbol not found: _kIOMasterPortDefault
Referenced from: /Users/wenlin.kwek/Documents/fp_churn/venv/lib/python3.7/site-packages/psutil/_psutil_osx.cpython-37m-darwin.so
Expected in: flat namespace
in /Users/wenlin.kwek/Documents/fp_churn/venv/lib/python3.7/site-packages/psutil/_psutil_osx.cpython-37m-darwin.so
Will appreciate if anyone knows how to resolve this issue, thanks.
Does it raise the same error when you activate the venv, open the virtualenv python interpreter and import psutil?
Another cause I can think of is when you name your script psutil.py and within that script you try to import the psutil module.
(see the post of Yong Wang: airflow error:AttributeError: module 'airflow.utils.log' has no attribute 'file_processor_handler')
I am doing some beginner Selenium to automate a task in the browser. I have installed Selenium using pip install selenium and I know it installed successfully because I saw the following message: Successfully installed selenium-3.9.0.
Okay so that's clear Selenium is up and working.
I want to run this python file:
from selenium import webdriver
browser = webdriver.Firefox()
type(browser)
browser.get('http://inventwithpython.com')
However, when I run this using the terminal, I get the following error:
mustafas-mbp:PlayDivya mustafahoda$ python playDivya.py
Traceback (most recent call last):
File "playDivya.py", line 4, in <module>
from selenium import webdriver
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/selenium/webdriver/__init__.py", line 18, in <module>
from .firefox.webdriver import WebDriver as Firefox # noqa
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/selenium/webdriver/firefox/webdriver.py", line 22, in <module>
import httplib as http_client
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/httplib.py", line 69, in <module>
from array import array
ImportError: dlopen(/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload/array.so, 2): Symbol not found: __PySlice_AdjustIndices
Referenced from: /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload/array.so
Expected in: flat namespace
in /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload/array.so
Any help would be super helpful. This is a very simple script and I have no idea why this is happening!
Thanks in advance!
The error says it all :
Traceback (most recent call last):
File "playDivya.py", line 4, in <module>
from selenium import webdriver
.
ImportError: dlopen(/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload/array.so, 2): Symbol not found: __PySlice_AdjustIndices
Reasons and Solution
This issue can arise when you install a new version of python. In those cases you may need to run hash -r python to tell bash to reset the cached location to the python executable.
If hash -r python says too many args then you can use rehash command.
As per the discussion Symbol not found: __PyCodecInfo_GetIncrementalDecoder the issue occurs when Python is updated from Python 2.7.10 to 2.7.11.
If you are using conda package you need to run conda install python=2.7.10 which will solve this problem.
Even downgrading Python to 2.7.10 will also work.
The best solution would be Re-Installing Selenium.
I'm having issues running ortools on Linux. I downloaded it from google's site (https://developers.google.com/optimization/) and installed it using "make install," but when I go to use it in python I get the following:
Traceback (most recent call last):
File "regular.py", line 42, in <module>
from ortools.constraint_solver import pywrapcp
File "/home/m3/summer/ortools_examples/examples/python/ortools.py", line 2, in <module>
ImportError: No module named linear_solver
It looks like despite installing ortools, its still not in my python path correctly, so when I call it in the file, it doesn't find anything and returns an error, right? Any advice on how to solve this?
I am trying to import spynner into my python program (import spynner) ... when I run the script, I receive the following error message:
Traceback (most recent call last):
File "C:\Users\Michael\Desktop\webscraper.py", line 2, in <module>
import spynner
File "build\bdist.win32\egg\spynner\__init__.py", line 2, in <module>
File "build\bdist.win32\egg\spynner\browser.py", line 52, in <module>
ImportError: No module named PyQt4
I then tried to install this module called PyQt4 (pip install PyQt4), which resulted in the following error message:
Could not find any downloads that satisfy the requirement Pyqt4
How can this problem be solved?
PyQt is available for download from Riverbank.
You can get PyQt4 here: http://www.riverbankcomputing.com/software/pyqt/download
They have links to both the source (so you can build it yourself) or binary packages.
If you need the PyQt documentation for the various classes the framework provides, you get get that from here
I'm trying to use Markdown with Django as shown in this tutorial. I've got the library installed and configured in Django using django.contrib.markup, but when I go to a page using markup, I get:
Error in 'markdown' filter: The Python markdown library isn't installed.
Then, through the interpreter I try running import markdown, which results in the following traceback:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python2.7/site-packages/markdown/__init__.py", line 43, in <module>
from .treeprocessors import build_treeprocessors
File "/usr/lib/python2.7/site-packages/markdown/treeprocessors.py", line 2, in <module>
from . import inlinepatterns
File "/usr/lib/python2.7/site-packages/markdown/inlinepatterns.py", line 47, in <module>
from urllib.parse import urlparse, urlunparse
ImportError: No module named parse
The Python documentation, however, tells me that urlparse has been renamed to urllib.parse in Python 3, which doesn't make any sense, because the Markdown library was installed through pip2, which put in into the python2.7 site-packages directory.
Changing that one line, by the way, results in more import errors.
No idea how this happened, but reinstalling Markdown worked. In retrospect, I probably should have tried that first.