Is MathDOM 0.8 compatible with Python 2.7? - python

I want to convert AsciiMath to MathML. I just want to get the XML content but I need not to display on browser.
So, I have installed MathDOM 0.8, lxml 2.3, pyparsing 1.5.6. I have not installed PyXML because MathDOM uses PyXML or lxml, and pyparsing.
I then run three examples in MathDOM directory such as dom.py, infix.py and ldom.python.
dom.py and infix.py output an error: ImportError: No module named Element
Otherwise, ldom.py outputs other error: AttributeError: 'NoneType' object has no attribute 'setParseAction'
I have also tried to install PyXML but I could not run the examples, too.
Please help me.
Thanks.

I ran into exactly the same issue — many thanks to you and Jon Olav Vik for pointing me in the direction of a solution.
I'm using virtualenv and pip, so installing the old version through the usual mechanisms was actually preferable to the manual bundling Jon describes. Unfortunately, just doing pip install pyparsing==1.4.2 doesn't work, but pointing pip at SourceForge certainly does. In one line:
$ pip install http://downloads.sourceforge.net/project/pyparsing/pyparsing/pyparsing-1.4.2/pyparsing-1.4.2.tar.gz

MathDOM 0.8 (which installs module mathml) works only with the older pyparsing 1.4.2.
Here's a way to override pyparsing with the older version, affecting mathml only. Tested on Python 2.7 on Windows 7:
Download and extract MathDOM 0.8.
Download revision 68 of pyparsing.py (version 1.4.2 according to the SVN commit messages, though there are no tags in the repository) and save it in the mathdom-0.8/mathml folder that you extracted. This will take precedence over the installed pyparsing, but only for the mathml package.
Navigate to mathdom-0.8/ and install (e.g. python setup.py install or pip install ., perhaps appending --prefix=$HOME/usr or somesuch).
Test with python -c "from mathml import termparser"; it should succeed where it previously failed with AttributeError: 'NoneType' object has no attribute 'setParseAction'.
You can also verify that python -c "from mathml import pyparsing; print pyparsing.__version__" prints 1.4.2, whereas python -c "import pyparsing; print pyparsing.__version__" prints 1.5.6.
Hope this helps!

I happened to face pyparsing missing for matplotlib on python 2.7 in windows 7. I downloaded the zip version from https://pypi.python.org/pypi/pyparsing/1.5.7 , extracted, Opened a command prompt inside the extracted directory where I have the setup.py and ran python setup.py install It worked! The only additional thing was I had to add python location to my path variable. Like this: set path=%path%+;C:\python27 before executing the previous command.

Related

Ways of installing python module

I'm new to python, about a month.
I know installing python modules can be done by using pip or easy_install. But when I was trying to install the regex module it gave me an error.
Typing pip install re in cmd gave me the following errors;
ERROR: Could not find a version that satisfies the requirement re (from versions: none)
ERROR: No matching distribution found for re
So I went to PyPI and downloaded a file there and now PyCharm doesn't give error when I import the module anymore.
So are there any difference between these ways of downloading Python modules or it doesn't matter ?
I'm using Windows 10 and have Python 3.8 and 3.8.1.
re is a built-in module, therefore you are not required to install this with pip.
Python Built-In Modules
re is part of the Python standard library so there is no need to install it separately. There are many ways to 'install' a package, e.g. using easy_install, pipx, venv, poetry, etc., but pip install --user is likely the way you're going to want to go to get started until you run into a compelling reason to explore other options. Either way, all these tools are essentially just various ways to move packages into PYTHONPATH, the place that Python looks for packages by default.

Syntax error when trying to import Cntlr from arelle module

My goal is to use Arelle (open-source platform for XBRL community) to parse XBRL docs from the SEC.
I am following instructions found here.
I successfully git cloned Arelle's code into the Lib directory of Anaconda. However, when I try from arelle import Cntlr I get the following syntax error.
File "arelle\Cntlr.py", line 573
print(logEntry, file=file)
^
SyntaxError: invalid syntax
I am using Python 2.7.12. in Anaconda.
Any feedback is appreciated and I can provide further information upon request.
The instructions you found are rather old (from 2014), and appear to be outdated.
I was able to install the package with the following steps:
# This is needed because the 3to2 library can't be installed as an egg; if
# you don't install it with `pip` first the installation of Arelle will fail.
$ pip install 3to2
# Install Arelle directly from GitHub, this will take a while
$ pip install git+https://github.com/Arelle/Arelle
With 3to2 installed, the installation script setup.py proceeds to translate the Arelle sourcecode back to a Python 2 compatible form. Translation takes several minutes, be patient.

Trouble installing geopy with Python 3.2

I am trying to install a module on python 3.2 but am unable to. I am using Windows 7. I need to have the module installed only on Python 3.2, so solutions that work for other versions of Python won't be helpful to me (I had no problem installing modules in Python 2.7 or 3.3, 3,4) I got rid of all my other versions of python, because I thought that might be the problem.
I have tried both using pip install, and to manually install the package and neither works. At first glance it looks like I am installing setuptools and pip correctly. Here is the output I get when I try to install pip
Installed c:\python32\lib\site-packages\setuptools-7.0-py3.2.egg
Processing dependencies for setuptools==7.0
Finished processing dependencies for setuptools==7.0
PS C:\> python32 .\get-pip.py
Requirement already up-to-date: pip in c:\python32\lib\site-packages
Cleaning up...
PS C:\> pip install geopy
It looks fine, right?
Then when I try to use by entering pip install geopy Here is the output I get
pip: the termpipis not recognized as the name of a cmdlet, function or operable program etc. I made sure that python 3.2 was specified in the path environments, and uninstalled all other versions of pythons. I don't know what else I can do?
I also tried to manually install geopy. I went to the geopy page on github and pressed on "Download ZIP". I then extracted the folder to lib/site-packages directory in python32. When I tried to install using the setup.py (python32 setup.py install) Here is the error message that I got. I am not sure what this error message means
Traceback (most recent call last):
File "setup.py", line 6, in <module>
from geopy import __version__ as version
File "C:\python32\lib\site-packages\geopy-master\geopy\__init__.py", line 10, in <module>
from geopy.location import Location
File "C:\python32\lib\site-packages\geopy-master\geopy\location.py", line 21
def __init__(self, address=u"", point=None, raw=None):
Update: GeoPy 1.6.0 introduced support for Python 3.2, so update it and it should install and work.
Old answer:
This is a bug with geopy, and/or it doesn't support Python 3.2. With this Python release, strings cannot be in the form u"the string", since it is a SyntaxError. This was fixed with PEP-414 for Python 3.3.
While you can install the package, a quick fix for geopy is to edit the installed files to remove the u in several module files, such as "C:\python32\lib\site-packages\geopy-master\geopy\location.py" (as shown in your question).
For example:
Change address=u"" to address=""
Change signature_method=u"HMAC-SHA1" to signature_method="HMAC-SHA1"
Also watch out for single quote changes, e.g. u'the string'
etc.

import libtorrent not working

I installed libtorrent-rasterbar on a mac with brew. After I installed I check if it was good installed with the command:
brew install libtorrent-rasterbar
And I get:
Warning: libtorrent-rasterbar-0.16.10 already installed
So installation looks to be ok.
If I go to python and type "import libtorrent" y get an error.
Also if I type:
>>>help('modules')
I dont see libtorrent in the list.
What I'm doing wrong?
Brew has nothing to do with Python. It'll just install system libraries. If you want to install libraries/modules for Python, you should use pip (recommended) or easy_install.
I couldn't find very good Python support for libtorrent in particular, although there is great support for other torrent libraries like PyTorrent.
If you must use libtorrent-rasterbar, there's a great tutorial on how to do it on Super User

I've installed Bottle for Python 2.7, but how to access ir from Python 3.2?

I have installed bottle on my Ubuntu Linux server using
sudo pip install bottle
and it is installed to: /usr/local/lib/python2.7/dist-packages
But I also have Python 3.2 installed on my system, and I want to access bottle from Python 3.2. Python 3.2 does not seem to recognise that bottle is installed.
What am I doing wrong?
You'd have to separately install it for Python 3.2 (with e.g. sudo pip-3.2 install bottle).
It's currently in python2.7/dist-packages, meaning that only 2.7 is going to load it. You could try to add that to your PYTHONPATH or similar, but that will very rarely work between Python 2 and 3 because the source files aren't quite compatible. (Any C extensions are also certainly not going to work, though bottle doesn't have any of those.)
Unfortunately, although that command works, it looks like the version of bottle in pypi isn't Python 3-compatible even when installed through pip-3.2:
In [1]: import bottle
File "/Library/Frameworks/Python.framework/Versions/3.2/bin/bottle.py", line 373
except re.error, e:
^
SyntaxError: invalid syntax
The homepage claims that it works with 3.x, but I got that error installing with both pip and easy_install. The latest development version, which is just a single file linked from the homepage, seems to work, though.
You are not doing anything wrong. Pip uses the /usr/bin/python by default and only installs there.
Unless you want to setup virtualenv-s, you probably best copy the current pip to pip3.2 and edit that to call python 3.2:
sudo -s -H
p=$(which pip)
cat $p | sed "1s|/usr/bin/python|$(which python3.2)|" > $p"3.2"
chmod 755 $p"3.2"
exit
You now have a pip3.2 that will install bottle so python3.2 can use it. If you get an error running pip3.2 about not finding pkg_resources look at No module named pkg_resources
I'll answer this myself. Turns out the latest release version of pip does not include pip-3.2. You need to download the development version and use that, which includes pip-3.2.
Just download it manually from offsite. It is just one file.
Place it into the lib/site-packages folder and give the file proper rights.

Categories