I am getting an error when trying to run a example .py from the serpscrap package.
I am on an iPhoneX in Pythonista.
Any help would be greatly appreciated.
Here is the traceback
Traceback (most recent call last):
File "/private/var/mobile/Containers/Shared/AppGroup/C27C5B11-1804-47B9-AF18-7287A8337C55/Pythonista3/Documents/testing/serpscrapetest.py", line 3, in <module>
import serpscrap
File "/private/var/mobile/Containers/Shared/AppGroup/C27C5B11-1804-47B9-AF18-7287A8337C55/Pythonista3/Documents/site-packages-3/serpscrap/__init__.py", line 5, in <module>
from serpscrap.serpscrap import SerpScrap
File "/private/var/mobile/Containers/Shared/AppGroup/C27C5B11-1804-47B9-AF18-7287A8337C55/Pythonista3/Documents/site-packages-3/serpscrap/serpscrap.py", line 11, in <module>
from scrapcore.core import Core
File "/private/var/mobile/Containers/Shared/AppGroup/C27C5B11-1804-47B9-AF18-7287A8337C55/Pythonista3/Documents/site-packages-3/scrapcore/core.py", line 8, in <module>
from scrapcore.cachemanager import CacheManager
File "/private/var/mobile/Containers/Shared/AppGroup/C27C5B11-1804-47B9-AF18-7287A8337C55/Pythonista3/Documents/site-packages-3/scrapcore/cachemanager.py", line 11, in <module>
from scrapcore.parsing import Parsing
File "/private/var/mobile/Containers/Shared/AppGroup/C27C5B11-1804-47B9-AF18-7287A8337C55/Pythonista3/Documents/site-packages-3/scrapcore/parsing.py", line 6, in <module>
from scrapcore.parser.google_parser import GoogleParser
File "/private/var/mobile/Containers/Shared/AppGroup/C27C5B11-1804-47B9-AF18-7287A8337C55/Pythonista3/Documents/site-packages-3/scrapcore/parser/google_parser.py", line 7, in <module>
from scrapcore.parser.parser import Parser
File "/private/var/mobile/Containers/Shared/AppGroup/C27C5B11-1804-47B9-AF18-7287A8337C55/Pythonista3/Documents/site-packages-3/scrapcore/parser/parser.py", line 7, in <module>
import lxml.html
File "/private/var/mobile/Containers/Shared/AppGroup/C27C5B11-1804-47B9-AF18-7287A8337C55/Pythonista3/Documents/site-packages-3/lxml/html/__init__.py", line 54, in <module>
from .. import etree
ImportError: cannot import name 'etree'
SerpScrap doesn't work on iOS at the moment, because of the lxml dependency.
I will update the docs to clearify this point.
But maybe you take a look on https://github.com/pybee/Python-Apple-support .
I'm not familiar with iOS, maybe someone can check if this can help to solve this issue. Otherwise feel free to open an issue on the serpscrap github page.
serpscrap evidently requires lxml, even though for some reason it only documents that requirement for Windows, rather than for all platforms.
You can't install packages that need C extension modules, like lxml, in Pythonista. You seem to have somehow gotten the pure-Python part of lxml installed,1 but that won't do any good without the C extension modules.
There's an open issue, #245, to add lxml as a pre-installed package with Pythonista, which would probably fix your problem.
So, your options are:
Help Pythonista get lxml building so they can close that bug and add lxml to the next version.
Modify serpscrap to work without lxml (if it's just using lxml.etree, it's possible that it would work with the stdlib ETree implementation).
File a feature request with serpscrap and hope someone else does it.
Switch to a different scraper that doesn't require lxml.
1. I'm not sure how that could happen; the install should just fail. But maybe serpscrap does some weird thing that happens to work on Linux and macOS but not iOS, and that's why they only list lxml as a dependency on Windows in the first place?
Related
I have recently updated to Ubuntu 18.04.1 LTS. After that I tried to run some of my python codes and I got an error related to the lmfit package, here's the code:
import scipy
from asteval import get_ast_names
import lmfit
(I have explicitly added the scipy and asteval modules to check python was finding them porperly)
I obtained this error:
Traceback (most recent call last):
File "/home/maurizio/Documents/Python/Programmini/PhD/TEAS/Test.py", line 3, in <module>
import lmfit
File "/home/maurizio/.local/lib/python2.7/site-packages/lmfit/__init__.py", line 42, in <module>
from .confidence import conf_interval, conf_interval2d
File "/home/maurizio/.local/lib/python2.7/site-packages/lmfit/confidence.py", line 12, in <module>
from .minimizer import MinimizerException
File "/home/maurizio/.local/lib/python2.7/site-packages/lmfit/minimizer.py", line 35, in <module>
from .parameter import Parameter, Parameters
File "/home/maurizio/.local/lib/python2.7/site-packages/lmfit/parameter.py", line 8, in <module>
from asteval import Interpreter, get_ast_names, valid_symbol_name
ImportError: cannot import name get_ast_names
which basically states that lmfit cannot find the function get_ast_names from asteval, although the python interpreter doesn't complain when I try to import it so it should be properly installed.
I have found this question with a similar problem and the guy in the comments claims he solved it by reinstalling it with pip3, so I tried to compile it with python3 and there's no problem so the issue concerns only python 2
Any help?
I believe you must have conflicting versions of lmfit and asteval. This should have been automatically noticed (and ideally resolved) when installing lmfit, but something there appears to have gone wrong. For the latest releases, you should get
>>> import asteval
>>> asteval.__version__
0.9.12
>>> import lmfit
>>> lmfit.__version__
0.9.11
Depending on how you installed these, you may need to check for and remove older versions of asteval in your $HOME/.local/lib/python2.7/site-packages/ folder and re-do pip install asteval.
I've seen this question asked before but none of the answers seem to work for me.
I am using python version 2.7.13
In my code I have ..
import base64
import httplib2
Now when I run it on my own pc it works fine, but when I run it on my works p.c. behind a firewall I get ..
Traceback (most recent call last):
File "mail4.py", line 2, in
import httplib2
File "C:\Python27\lib\site-packages\httplib2__init__.py", line 39, in
import urllib
File "C:\mypy\urllib.py", line 1, in
import requests
File "C:\Python27\lib\site-packages\requests__init__.py", line 43, in
import urllib3
File "C:\Python27\lib\site-packages\urllib3__init__.py", line 8, in
from .connectionpool import (
File "C:\Python27\lib\site-packages\urllib3\connectionpool.py", line 35, in
from .request import RequestMethods>
File "C:\Python27\lib\site-packages\urllib3\request.py", line 10, in >
from .packages.six.moves.urllib.parse import urlencode
ImportError: cannot import name urlencode
I've tried setting proxies.
I've tried uninstalling and re-installing six
Also
from urllib.parse import urlencode
All to no avail ?
You are (in this case) apparently running Python 2.7.x, however parse module is in urllib package in Python 3.x. In Python 2.x its name was (just) urlparse. Based on that, I'd guess different configuration (mismatch in versions used between Code and/or 3rd party packages and/or python interpreter is behind the problem you're seeing).
EDIT: sorry, I should have also noticed you are looking for urlencode on the last bit. In python 2.7 that is a function in urllib module: from urllib import urlencode.
I fixed this issue with installing Werkzeug to <1.0, which removed the contrib module
pip install Werkzeug==0.16.1
I reinstalled PyBluez some weeks ago since I couldn't get basic functions to work. Now I can't even import it to Python 3.
import bluetooth
Traceback (most recent call last):
File "<pyshell#0>", line 1, in <module>
import bluetooth
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/PyBluez-0.22-py3.6.egg/bluetooth/__init__.py", line 47, in <module>
from .osx import *
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/PyBluez-0.22-py3.6.egg/bluetooth/osx.py", line 1, in <module>
import lightblue
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/lightblue/__init__.py", line 160, in <module>
from _lightblue import *
ModuleNotFoundError: No module named '_lightblue'
I was not able to install pybluez via pip/pip3, however I was able to install it by downloading the Github project. I have tried to update it, all suggestions I could find on matter online and much more.
I appreciate any help I can get.
This is the closed OS X import issue #108 on GitHub: http://github.com/karulis/pybluez/issues/108
It's actually quite an old issue. What version are you on? El Captain?
One thing the author suggested you might do is remove your current installation and install the GitHub repo using pip:
git clone https://github.com/karulis/pybluez.git
pip install -e pybluez
That seemed to get the import working for the OP of the GitHub issue, but there were still some bugs due to limited support of OS X. You can read more about the bugs and troubleshooting on GitHub.
I am trying to use the Python Library requests using Liclipse. I have added the library but it is giving me the below error message
Traceback (most recent call last):
File "C:\programming\automate_boring_stuff\test.py", line 1, in <module>
import requests
File "C:\programming\libraries\kennethreitz-requests-> > 00fa5f1\requests\__init__.py", line 3, in <module>
from . import ssl_match_hostname
ImportError: cannot import name ssl_match_hostname
Unusually I was previously using it on another computer and it worked finebut on this one by just running import requests it gives me the above error message.
I have tried researching this but most of the answers I have found have been related to different libraries and I could not find how the fixes related to the requests library.
You have mucked up your installation; you appear to have moved the requests/packages/urllib3/packages/__init__.py file into the top-level requests folder.
Remove the package and re-install.
I'm using Tweepy to send some messages to Twitter. I'm getting a long traceback from the API. The traceback settles at:
ImportError: cannot import name Random
I used Pip to install the latest version of Tweepy:
Name: tweepy
Version: 2.3.0
Location: /System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages
Requires:
When I call
import tweepy
I get this traceback:
Traceback (most recent call last):
File "/Users/dromard/Projects/Drop Playlist/drop.py", line 4, in <module>
import tweepy
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/tweepy/__init__.py", line 14, in <module>
from tweepy.api import API
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/tweepy/api.py", line 8, in <module>
from tweepy.binder import bind_api
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/tweepy/binder.py", line 5, in <module>
import httplib
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/httplib.py", line 79, in <module>
import mimetools
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/mimetools.py", line 6, in <module>
import tempfile
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/tempfile.py", line 35, in <module>
from random import Random as _Random
ImportError: cannot import name Random
Process finished with exit code 1
I'm working in PyCharm and confirmed the site package and Python paths are correct in settings. I manually checked in console that the paths are correct, and there are no duplicate locations.
I haven't made any changes to Tweepy. I let Pip install it where it is, as it is. Permissions look correct:
-rw-r--r-- 1 root wheel
If I check Python in console:
- I get the same traceback
- When I run the individual imports, they all execute without error
It all fails out at the random call. I think random is part of Python's core packages, and not part of Tweepy.
I handed this script off to a co-worker, who then used Pip to install tweepy and hit the same traceback. Makes me think Pip might be contributing.
I'm relatively new to Python (programming in general). I looked through other 'import error' articles, but didn't find this specific issue. Any help is appreciated.
I figured this out.
I had created a python file called 'random.py' during the course of experimenting with a random number generating script. My 'import random' call was grabbing this file, which lacked the library Random. It essentially created a conflict with the proper 'random.'
Make sure that you delete the random.py file or overwrite it with another name, then recheck "from random import random".
I could not comment due to low experience.
I also had a xyz.py in a directory and calling a module of same name (import xyz) causes this error.
Make sure you do not save any file xyz.py that also have a python module at the same name.
This is what I found from my newbie experiment.
This also happens with python 3.8.