Getting error about bad escape during start of Arelle - python

I am trying to get Arelle working on Ubuntu linux 18.04 with Python 3.6.9.
Step-1: (Download Arelle software):
git clone https://github.com/Arelle/Arelle.git -b lxml
Step-2 Install Python LXML:
apt-get install -y python-lxml
Step-3 Install Python tk:
Due to error: 'No module named tkinter'
...I install:
apt-get install python3-tk
When it's time to start Arelle from terminal, I use:
python3 arelleGUI.pyw
I then get following error:
Traceback (most recent call last):
File "arelleGUI.pyw", line 9, in <module>
from arelle import CntlrWinMain
File "/tmp3/Arelle/arelle/CntlrWinMain.py", line 22, in <module>
from arelle import Cntlr
File "/tmp3/Arelle/arelle/Cntlr.py", line 8, in <module>
from arelle import ModelManager
File "/tmp3/Arelle/arelle/ModelManager.py", line 8, in <module>
from arelle import (ModelXbrl, Validate, DisclosureSystem)
File "/tmp3/Arelle/arelle/Validate.py", line 9, in <module>
from arelle import (ModelXbrl, ModelVersReport, XbrlConst, ModelDocument,
File "/tmp3/Arelle/arelle/ModelVersReport.py", line 9, in <module>
from arelle import (XbrlConst, XbrlUtil, XmlUtil, UrlUtil, ModelXbrl, ModelDocument, ModelVersObject)
File "/tmp3/Arelle/arelle/ModelDocument.py", line 9, in <module>
from arelle import (XbrlConst, XmlUtil, UrlUtil, ValidateFilingText, XmlValidate)
File "/tmp3/Arelle/arelle/ValidateFilingText.py", line 16, in <module>
docCheckPattern = re.compile(r"&\w+;|[^0-9A-Za-z`~!##$%&\*\(\)\.\-+ \[\]\{\}\|\\:;\"'<>,_?/=\t\n\r\m\f]") # won't match &#nnn;
File "/usr/lib/python3.6/re.py", line 233, in compile
return _compile(pattern, flags)
File "/usr/lib/python3.6/re.py", line 301, in _compile
p = sre_compile.compile(pattern, flags)
File "/usr/lib/python3.6/sre_compile.py", line 562, in compile
p = sre_parse.parse(p, flags)
File "/usr/lib/python3.6/sre_parse.py", line 855, in parse
p = _parse_sub(source, pattern, flags & SRE_FLAG_VERBOSE, 0)
File "/usr/lib/python3.6/sre_parse.py", line 416, in _parse_sub
not nested and not items))
File "/usr/lib/python3.6/sre_parse.py", line 527, in _parse
code1 = _class_escape(source, this)
File "/usr/lib/python3.6/sre_parse.py", line 336, in _class_escape
raise source.error('bad escape %s' % escape, len(escape))
sre_constants.error: bad escape \m at position 67
I found this SO question that seems related to the issue.

This is an error in Arelle, which shows up for Python 3.6 and later. There is a pull request for it , but that is still open (since July 2017). Given that Python 3.6 has been out for quite a while, I don't know why this hasn't been fixed.
You are using the lxml branch, which has been stale for 10 years. So perhaps this error has actually been fixed (even if the pull request is still open) on the master brach, but not on the lxml branch. Try installing from master first, if that is an option for you.

Related

TypeError from pip when setting up virtualenv

new to coding and I think I've searched thoroughly for answers to this question, but the suggested solutions haven't been working for me. Apologies if this is a duplicate, though!
I'm trying to set up my computer according to these instructions, currently trying to get virtualenv up and running. However, pip doesn't seem to be working properly. I was able to use python -m pip as a workaround and installed virtualenv using: python -m pip install virtualenv
But the same workaround doesn't seem to work with virtualenvwrapper: python -m pip install virtualenvwrapper gives me this error:
Exception:
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pip/basecommand.py", line 215, in main
status = self.run(options, args)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pip/commands/install.py", line 324, in run
requirement_set.prepare_files(finder)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pip/req/req_set.py", line 380, in prepare_files
ignore_dependencies=self.ignore_dependencies))
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pip/req/req_set.py", line 634, in _prepare_file
abstract_dist.prep_for_dist()
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pip/req/req_set.py", line 129, in prep_for_dist
self.req_to_install.run_egg_info()
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pip/req/req_install.py", line 412, in run_egg_info
self.setup_py, self.name,
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pip/req/req_install.py", line 387, in setup_py
import setuptools # noqa
File "/Library/Python/2.7/site-packages/setuptools/__init__.py", line 12, in <module>
import setuptools.version
File "/Library/Python/2.7/site-packages/setuptools/version.py", line 1, in <module>
import pkg_resources
File "/Library/Python/2.7/site-packages/pkg_resources/__init__.py", line 72, in <module>
import packaging.requirements
File "/Library/Python/2.7/site-packages/packaging/requirements.py", line 59, in <module>
MARKER_EXPR = originalTextFor(MARKER_EXPR())("marker")
TypeError: __call__() takes exactly 2 arguments (1 given)
If I try running anything directly with a pip command, such as pip install virtualenvwrapper, I get this error:
Traceback (most recent call last):
File "/usr/local/bin/pip", line 5, in <module>
from pkg_resources import load_entry_point
File "/Library/Python/2.7/site-packages/pkg_resources/__init__.py", line 72, in <module>
import packaging.requirements
File "/Library/Python/2.7/site-packages/packaging/requirements.py", line 59, in <module>
MARKER_EXPR = originalTextFor(MARKER_EXPR())("marker")
TypeError: __call__() takes exactly 2 arguments (1 given)
I have a mac running Sierra (10.12.4). Python version 2.7.6. Pip 9.0.1
Thoughts? Thank you!

"sre_constants.error: nothing to repeat" error every time trying to install using pip

I just installed Python 2.7.5 on my Windows 10 machine and I also got pip installed through setuptools. However whenever I try to install something using pip e.g. pip install numpy, I get this error message:
Traceback (most recent call last):
File "C:\Python27\Scripts\pip-script.py", line 8, in <module>
load_entry_point('pip==9.0.1', 'console_scripts', 'pip')()
File "C:\Python27\lib\site-packages\pkg_resources.py", line 318, in load_entry_point
return get_distribution(dist).load_entry_point(group, name)
File "C:\Python27\lib\site-packages\pkg_resources.py", line 2221, in load_entry_point
return ep.load()
File "C:\Python27\lib\site-packages\pkg_resources.py", line 1954, in load
entry = __import__(self.module_name, globals(),globals(), ['__name__'])
File "C:\Python27\lib\site-packages\pip-9.0.1-py2.7.egg\pip\__init__.py", line 26, in <module>
from pip.utils import get_installed_distributions, get_prog
File "C:\Python27\lib\site-packages\pip-9.0.1-py2.7.egg\pip\utils\__init__.py", line 27, in <module>
from pip._vendor import pkg_resources
File "C:\Python27\lib\site-packages\pip-9.0.1-py2.7.egg\pip\_vendor\pkg_resources\__init__.py", line 73, in <module>
__import__('pip._vendor.packaging.specifiers')
File "C:\Python27\lib\site-packages\pip-9.0.1-py2.7.egg\pip\_vendor\packaging\specifiers.py", line 275, in <module>
class Specifier(_IndividualSpecifier):
File "C:\Python27\lib\site-packages\pip-9.0.1-py2.7.egg\pip\_vendor\packaging\specifiers.py", line 373, in Specifier
r"^\s*" + _regex_str + r"\s*$", re.VERBOSE | re.IGNORECASE)
File "C:\Python27\Lib\re.py", line 190, in compile
return _compile(pattern, flags)
File "C:\Python27\Lib\re.py", line 242, in _compile
raise error, v # invalid expression
sre_constants.error: nothing to repeat
Since I'm pretty new to Python, I don't really understand what this error means. Any workaround?
I had a similar issue with a library that is using regular expressions (with the re.compile() function). I solved this issue installing the last version available 2.7.13 (I run a Windows 7).
Before I had the 2.7.6 version. I updated it installing the new version with the .msi installer, available in the Python web page.

"This package should not be accessible on Python 3" when running python3

I was trying to use virtualenv to switch between python versions before learning that I could use both python and python3 on my Mac.
I was able to fix my python 2.7 version so that still works fine however, now when I run python3, I get this error:
Failed to import the site module
Traceback (most recent call last):
File "/usr/local/Cellar/python3/3.6.0/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site.py", line 544, in <module>
main()
File "/usr/local/Cellar/python3/3.6.0/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site.py", line 530, in main
known_paths = addusersitepackages(known_paths)
File "/usr/local/Cellar/python3/3.6.0/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site.py", line 282, in addusersitepackages
user_site = getusersitepackages()
File "/usr/local/Cellar/python3/3.6.0/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site.py", line 258, in getusersitepackages
user_base = getuserbase() # this will also set USER_BASE
File "/usr/local/Cellar/python3/3.6.0/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site.py", line 248, in getuserbase
USER_BASE = get_config_var('userbase')
File "/usr/local/Cellar/python3/3.6.0/Frameworks/Python.framework/Versions/3.6/lib/python3.6/sysconfig.py", line 601, in get_config_var
return get_config_vars().get(name)
File "/usr/local/Cellar/python3/3.6.0/Frameworks/Python.framework/Versions/3.6/lib/python3.6/sysconfig.py", line 580, in get_config_vars
import _osx_support
File "/usr/local/Cellar/python3/3.6.0/Frameworks/Python.framework/Versions/3.6/lib/python3.6/_osx_support.py", line 4, in <module>
import re
File "/usr/local/Cellar/python3/3.6.0/Frameworks/Python.framework/Versions/3.6/lib/python3.6/re.py", line 125, in <module>
import functools
File "/usr/local/Cellar/python3/3.6.0/Frameworks/Python.framework/Versions/3.6/lib/python3.6/functools.py", line 21, in <module>
from collections import namedtuple
File "/usr/local/Cellar/python3/3.6.0/Frameworks/Python.framework/Versions/3.6/lib/python3.6/collections/__init__.py", line 32, in <module>
from reprlib import recursive_repr as _recursive_repr
File "/usr/local/lib/python2.7/site-packages/reprlib/__init__.py", line 7, in <module>
raise ImportError('This package should not be accessible on Python 3. '
ImportError: This package should not be accessible on Python 3. Either you are trying to run from the python-future src folder or your installation of python-future is corrupted.
I've looked online for this error but most of the conversation was on fixing up the patch and then upgrading virtualenv. However, this still doesn't fix my issue.
python3 -V: Python 3.6.0
virtualenv --version: 15.1.0
env | egrep -i 'python|virtualenv': PYTHONPATH=/usr/local/lib/python2.7/site-packages:
Your environment contains PYTHONPATH=/usr/local/lib/python2.7/site-packages
This doesn't work with Python 3 for obvious reasons. To remove it:
unset PYTHONPATH
I solved my problem with below command
sudo pip install virtualenv --upgrade
virtualenv -p python3 env

BeautifulSoup4 in Sagemath

I'm trying to perform web scraping with BS4 and then do some algebra work with the results in Sage 6.2 (in Lion 10.7.5). I assumed that /Applications/Sage-6.2.app/Contents/Resources/sage/sage -i beautifulsoup4 would work, but the result is
Attempting to download package beautifulsoup4
>>> Checking online list of optional packages.
[Traceback (most recent call last):
File "<stdin>", line 35, in <module>
File "/Applications/Sage-6.2.app/Contents/Resources/sage/local/lib/python/urllib.py", line 240, in retrieve
fp = self.open(url, data)
File "/Applications/Sage-6.2.app/Contents/Resources/sage/local/lib/python/urllib.py", line 208, in open
return getattr(self, name)(url)
File "/Applications/Sage-6.2.app/Contents/Resources/sage/local/lib/python/urllib.py", line 359, in open_http
return self.http_error(url, fp, errcode, errmsg, headers)
File "/Applications/Sage-6.2.app/Contents/Resources/sage/local/lib/python/urllib.py", line 376, in http_error
return self.http_error_default(url, fp, errcode, errmsg, headers)
File "<stdin>", line 17, in http_error_default
IOError: [Errno 404] Not Found: '//www.sagemath.org/spkg/optional/list'
Error: failed to download http://www.sagemath.org/spkg/optional/list, aborting
Next, I tried /Applications/Sage-6.2.app/Contents/Resources/sage/sage -sh <<< "easy_install --verbose pip" to get bs4 via pip. That succeeded; however /Applications/Sage-6.2.app/Contents/Resources/sage/local/bin/pip2.7 install beautifulsoup4 failed with error message
Traceback (most recent call last):
File "/Applications/Sage-6.2.app/Contents/Resources/sage/local/lib/python2.7/site.py", line 548, in <module>
main()
File "/Applications/Sage-6.2.app/Contents/Resources/sage/local/lib/python2.7/site.py", line 530, in main
known_paths = addusersitepackages(known_paths)
File "/Applications/Sage-6.2.app/Contents/Resources/sage/local/lib/python2.7/site.py", line 266, in addusersitepackages
user_site = getusersitepackages()
File "/Applications/Sage-6.2.app/Contents/Resources/sage/local/lib/python2.7/site.py", line 241, in getusersitepackages
user_base = getuserbase() # this will also set USER_BASE
File "/Applications/Sage-6.2.app/Contents/Resources/sage/local/lib/python2.7/site.py", line 231, in getuserbase
USER_BASE = get_config_var('userbase')
File "/Applications/Sage-6.2.app/Contents/Resources/sage/local/lib/python2.7/sysconfig.py", line 516, in get_config_var
return get_config_vars().get(name)
File "/Applications/Sage-6.2.app/Contents/Resources/sage/local/lib/python2.7/sysconfig.py", line 449, in get_config_vars
import re
File "/Applications/Sage-6.2.app/Contents/Resources/sage/local/lib/python2.7/re.py", line 105, in <module>
import sre_compile
File "/Applications/Sage-6.2.app/Contents/Resources/sage/local/lib/python2.7/sre_compile.py", line 14, in <module>
import sre_parse
File "/Applications/Sage-6.2.app/Contents/Resources/sage/local/lib/python2.7/sre_parse.py", line 17, in <module>
from sre_constants import *
File "/Applications/Sage-6.2.app/Contents/Resources/sage/local/lib/python2.7/sre_constants.py", line 18, in <module>
from _sre import MAXREPEAT
ImportError: cannot import name MAXREPEAT
Next, I tried upgrading to Sage 6.6. That went smoothly, as did the installation of bs4. However, when I opened the notebook, I was unable to run code cells, because the "Shift-Enter" command only registered as "Enter" and gave me a new line instead of evaluating the code. Additionally, there was no "evaluate" button. Any recommendations to solve any of these issues would be greatly appreciated.
Unfortunately, Sage has changed how it handles optional packages like BS so that older versions may not be able to use them. You can always go to a mirror, though, like http://mirrors.mit.edu/sage/spkg/optional/ download it, and put it in your (old Sage's) optional spkg directory and try doing sage -i path/to/file.
As to the notebook issue, that should be a matter of doing a "hard cache reset" in the browser due to different jQuery versions, see e.g. here.

Python - ValueError: unknown locale: UTF-8 [duplicate]

This question already has answers here:
Pelican 3.3 pelican-quickstart error "ValueError: unknown locale: UTF-8"
(6 answers)
Closed 7 years ago.
I run the python script that contain Pandas (that one cause the problem) library I got this error:
Traceback (most recent call last):
File "test.py", line 2, in <module>
import pandas
ImportError: No module named pandas
But if I import from package path to make sure it detects Pandas library, I got this error message
Traceback (most recent call last):
File "test.py", line 3, in <module>
import pandas
File "/usr/local/lib/python2.7/site-packages/pandas/__init__.py", line 44, in <module>
from pandas.core.api import *
File "/usr/local/lib/python2.7/site-packages/pandas/core/api.py", line 9, in <module>
from pandas.core.groupby import Grouper
File "/usr/local/lib/python2.7/site-packages/pandas/core/groupby.py", line 16, in <module>
from pandas.core.frame import DataFrame
File "/usr/local/lib/python2.7/site-packages/pandas/core/frame.py", line 41, in <module>
from pandas.core.series import Series
File "/usr/local/lib/python2.7/site-packages/pandas/core/series.py", line 2864, in <module>
import pandas.tools.plotting as _gfx
File "/usr/local/lib/python2.7/site-packages/pandas/tools/plotting.py", line 28, in <module>
import pandas.tseries.converter as conv
File "/usr/local/lib/python2.7/site-packages/pandas/tseries/converter.py", line 7, in <module>
import matplotlib.units as units
File "/usr/local/lib/python2.7/site-packages/matplotlib/__init__.py", line 1131, in <module>
rcParams = rc_params()
File "/usr/local/lib/python2.7/site-packages/matplotlib/__init__.py", line 975, in rc_params
return rc_params_from_file(fname, fail_on_error)
File "/usr/local/lib/python2.7/site-packages/matplotlib/__init__.py", line 1100, in rc_params_from_file
config_from_file = _rc_params_in_file(fname, fail_on_error)
File "/usr/local/lib/python2.7/site-packages/matplotlib/__init__.py", line 1018, in _rc_params_in_file
with _open_file_or_url(fname) as fd:
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/contextlib.py", line 17, in __enter__
return self.gen.next()
File "/usr/local/lib/python2.7/site-packages/matplotlib/__init__.py", line 1000, in _open_file_or_url
encoding = locale.getdefaultlocale()[1]
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/locale.py", line 543, in getdefaultlocale
return _parse_localename(localename)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/locale.py", line 475, in _parse_localename
raise ValueError, 'unknown locale: %s' % localename
ValueError: unknown locale: UTF-8
I already update my .bash_profile and .bashrc with these lines but still not working even I already restart the terminal and my machine.
export LANG="it_IT.UTF-8"
export LC_COLLATE="it_IT.UTF-8"
export LC_CTYPE="it_IT.UTF-8"
export LC_MESSAGES="it_IT.UTF-8"
export LC_MONETARY="it_IT.UTF-8"
export LC_NUMERIC="it_IT.UTF-8"
export LC_TIME="it_IT.UTF-8"
export LC_ALL="it_IT.UTF-8"
I'm also enabled Set locale environment variables on startup in the terminal preferences.
I'm afraid the problem caused because of El Capitan.
Edit: Pandas, and its dependencies, had localization bugs that were discovered in non-C locales and fixed in recent versions.
When I downloaded the latest version of Pandas onto an OS X Yosemite computer via sudo pip install pandas in a terminal set to it_IT.UTF-8, and then imported it in a new Python session, I wasn't able to reproduce this issue.
My best guess now - and I'd emphasize this is only a guess - is that the version of Pandas in that folder predates those fixes and is broken in it_IT.UTF-8. (I do think this is, on balance, more likely than the issue being specific to El Capitan.)
Your LC_ALL= is unset. That seems unusual; based on other answers here I think you should try setting it to LC_ALL="it_IT.UTF-8" and remove the other LC_ settings.
Then save your .bash_profile, open a new terminal tab, and try again.

Categories

Resources