stuck in using Megam in Python ( nltk.classify.MaxentClassifier) - python

I'm using ubuntu x64, after two days and searching all the net, still i've not been able to install Megam,
i've read all information in this page http://www.cs.utah.edu/~hal/megam/
and installed x64 version of o'calm from http://packages.ubuntu.com/precise/ocaml
but when i want to use "megam" as a classifier in python, it says:
"NLTK was unable to find the megam file! Use software specific
configuration paramaters or set the MEGAM environment variable.
could anybody tell me how can i install and make use of it in python?
i've downloaded "ocaml-3.12.1.tar.gz" but the "make" command doesn't work (as it's said in its readme).
i've downloaded "megam_i686.opt" too, but it's not executable and i cannot run it
any help?
thanks in advance

For the future users:
megam is now available on MAC through brew:
$brew tap homebrew/science
$brew install megam

Use config_megam() to tell NLTK where the Megam executable is located. See: http://nltk.googlecode.com/svn/trunk/doc/api/nltk.classify.megam-module.html for details and documentation.
You also need to build MEGAM with the right 32/64 bit setting for your system. "megam_i686.opt" is for x86 iirc, so you should compile it for 64 bit. It is a while since I did this, but a simple build on an x64 system was all I needed: "Make doesn't work" is not very useful: I'm sure it gave you a few error messages...? Probably paths not set or are read only?
Edit: Looks like the above link is currently broken. The main Megam site can be found at:
http://www.umiacs.umd.edu/~hal/megam/
although it hasn't been updated for a while.

Answer given by Hugh Perkins, helped me resolve the issue (due to low reputation can't add a comment to that answer). After downloading the zip file (from http://thinknook.com/wp-content/uploads/2012/11/MEGAM.zip), I needed to tell python where it was, and that was done by adding it in os.environ as:
os.environ["MEGAM"] = '<<Complete path followed by file name>>/megam-64'

I downloaded from http://thinknook.com/wp-content/uploads/2012/11/MEGAM.zip , which was linked from http://thinknook.com/nltk-megam-maximum-entropy-library-on-64-bit-linux-2012-11-27/ This worked ok for me, on ubuntu 14.04

I manged to get megam to run on my docker instance running debian 9.7 following the steps below. Based on steps for MacOS install steps suggested by Jack Hong here.
apt-get install make
apt-get install ocaml-nox (or apt-get install ocaml, if you want x window support)
download source from here
unzip source creating a megam_0.92 directory
Edit the Makefile in megam_0.92 and make the following changes. (The
first change was already done in my particular instance):
WITHCLIBS=-I /usr/local/lib/ocaml/caml
WITHSTR =str.cma -cclib -lcamlstr
Save the changes and run make inside your megam_0.92 directory
add nltk.config_megam('//megam_0.92/megam') to your script and all should be well.

Related

Python Docker Image ImportError: python-magic [duplicate]

I am trying to install python-magic for Windows and I have followed all the instructions in https://github.com/ahupp/python-magic and repeated the process several times but I am still getting this error:
ImportError: failed to find libmagic. Check your installation
I have magic1.dll (along with the two other files the docs specified) in C:\Windows\System32 so I am not sure what the issue is. I would appreciate any help or workarounds.
Go here and download the file "python_magic_bin-0.4.14-py2.py3-none-win32.whl", then
pip install python_magic_bin-0.4.14-py2.py3-none-win32.whl
now python-magic works
I know this is a Windows question, but i wanted to share a Debian solution:
apt-get install libmagic-dev
Kind regards.
The below original answer is now outdated. Please simply follow the instructions denoted under the "dependencies" section.
ORIGINAL ANSWER:
I was able to solve this problem by moving the 3 files from GNUWin32 project to a separate directory (not the \system32 directory the docs suggest) and adding them to the PATH environment variable
Follow the below steps.
go to > https://github.com/pidydx/libmagicwin64
download the 3 files (dll's) except readme.md file
Drop the 3 files (dlls ) in C:\Windows\System32 and python magic will
import correctly.
Installing Cygwin with libmagic libary and installing the most recent version of the module from Github solves this problem.
At the time this question was asked, https://github.com/ahupp/python-magic probably didn't support cygmagic-1.dll.

How to compile TeX file from Python

I'm trying to create a pdf file inside a python/django project. I'm using PyLatex, which helps, but it's generate_pdf method breaks when it calls pdflatex. I keep getting this error:
FileNotFoundError: [Errno 2] No such file or directory: 'pdflatex'
I tried everything - os.system() ... subprocess. Any way I try, it can't find pdflatex. I'm running on Windows, but I need to be able to to do this within the web-app anyway.
Thanks for any help!
You just need to install pdflatex (and you will need to install on your server when you release your web-app). Instructions for installing on windows can be found in the top answer here.
Do you have "pdflatex" installed? As per this question, you may have to install "MiKTeX" and point os.system() at C:\Program Files\MiKTeX <MikTeX version>\miktex\bin to make it work.
Hope that helps.
Do you have texlive installed? If yes, then the issue is with the system path variable. If not already added, add it to the system path.
#
Updated answer:
I took the time and decided to replicate your issue. I too use windows.
I copied the basic example from Pylatex and tested it on my machine, I was able to replicate the same error as you despite having TexLive installed. To solve it I did the following steps:
Installed MikTex (I believe you have it installed).
Tried running it again but failed with the error missing package latexmk.
Using MikTex package manager, I installed the latexmk package.
Tried running but still failed, error missing perl.exe command.
I had to install perl to my windows, use the following links -- https://learn.perl.org/installing/windows.html
When I tried again, it compiled successfully.
The issue was not having the package latexmk for MikTex and perl.exe of which you should have posted as part of the error logs. Try that and let me know if successful.

How do I install python on a windows machine using a cygwin terminal?

I am trying to install python through cygwin on a windows machine in order to make use of a statistical program that can only be implemented using python in a linux environment.
I have run setup-x86_64.exe and installed all python related cygwin packages in an attempt to install python, but when I open a terminal and type python I just get
$ python
-bash: python: command not found
which is the same for all python commands I try so clearly the installation has not occurred. However, I have found a path to Python-2.7.9 which appears to contain the files required to build python from source.
When I run ./configure it is successful, but when I then input make it fails due to:
File "build/temp.cygwin-1.7.35-x86_64-2.7/libffi/fficonfig.py", line 33, in <module>
ffi_sources += ffi_platforms['X86_WIN64']
KeyError: 'X86_WIN64'
Makefile:488: recipe for target 'sharedmods' failed
make: *** [sharedmods] Error 1
Anyone know why make won't work?
The options in ./configure --help are unfamiliar to me, could any of these options allow for successful installation?
Any ideas would be greatly appreciated, thank you.
Cygwin comes with an installer, called setup.exe or setup-x86_64.exe. Just run it and type python to the search box. Then let it install it for you.
python language interpreter is the basic package you need.
So, this question is 3 years old, but this error still happens with most recent versions of Python 2 (tested with 2.7.13 and 2.7.15)
I was able to get python to build by modifying the following file in the build directory.
--- build/temp.cygwin-2.11.1-x86_64-2.7/libffi/fficonfig.py~ 2018-11-03 14:51:53.290000000 -0400
+++ build/temp.cygwin-2.11.1-x86_64-2.7/libffi/fficonfig.py 2018-11-03 14:53:41.793000000 -0400
## -9,6 +9,7 ##
'X86': ['src/x86/ffi.c', 'src/x86/sysv.S', 'src/x86/win32.S'],
'X86_FREEBSD': ['src/x86/ffi.c', 'src/x86/freebsd.S'],
'X86_WIN32': ['src/x86/ffi.c', 'src/x86/win32.S'],
+ 'X86_WIN64': ['src/x86/ffi.c', 'src/x86/win64.S'],
'SPARC': ['src/sparc/ffi.c', 'src/sparc/v8.S', 'src/sparc/v9.S'],
'ALPHA': ['src/alpha/ffi.c', 'src/alpha/osf.S'],
'IA64': ['src/ia64/ffi.c', 'src/ia64/unix.S'],
The source files, in particular src/x86/win64.S, are present in the source tree. For some reason, ./configure does not seem to be properly adding the option to the dictionary in the fficonfig.py file, which causes the KeyError posted in the question. After making this modification, make and make install completed successfully and I was able to install an alternate version of python in addition to the normal Cygwin package.
I'm not yet sure why this happens, but I thought I would attempt to provide a solution to the question actually asked rather than just telling the asker to install a pre-compiled version using the package manager.
Since building Python from source was said to be a bad idea, I assumed my Cygwin was broken. I attempted to uninstall Cygwin following the instructions on the Cygwin website, but I was unable to remove it due to permission difficulties (I use a university-supplied Windows machine). My last resort was to run the Cygwin installation wizard setup-x86_64.exe and uninstall all packages, then run the wizard once more and select the necessary packages again as if starting from new. Miraculously, installing the required packages from scratch solved the problem and I am now running Python through my Cygwin terminal with no errors.
If you want to run Python on Cygwin, you might need to build it from source.
download the source
unpack it to the directory you could delete later, eg: build
run Cygwin, type: cd /path/to/build
run ./configure --help and read the help about the options you'll need
./configure #options
make

Nvim setup instructions for the layman?

I'm trying to install vim and nvim as a replacement for Notational Velocity. I recently migrated to Ubuntu (14.04) and I'm very new to how everything works. The instructions for installing nvim are kind of elliptic and not entirely clear to me as a beginner. I manage to get it running if I enter vim and then type :Nvim inside the directory where I store my .txt notes. However, the notes aren't visible in nvim and here's where I run into trouble. As a beginner I simply do not understand the instructions regarding PATH and :python that are given on the installation page. I've tried (successfully, I think) to install xapian as well (after having installed vim) but nothing changed. That is, I cannot specify a PATH for my nvim and I cannot get the nvim script to work as a command anywhere in the terminal.
More consequentially, when I type
:python nvimdb.rebuild_database()
inside vim, I get:
Traceback (most recent call last):
File "", line 1, in
NameError: name 'nvimdb' is not defined
What I would like to ask for are step by step instructions for making nvim work with an existing library of .txt notes targeted at the vim and linux novice.
The program looks great and appears to be exactly what I need for my note taking needs, and I would really appreciate your help! Thank you so much.
I believe this is probably because you haven't installed the xapian library as that is a required mentioned by nvim. You need to install the package xapian-core I believe, you can do that in ubuntu with something like this : sudo apt-get install xapian-core

Cannot find tk.h despite having the dev packages installed

I am trying to install wck. But I ran into the following error when running setup.py :
fatal error : tk.h : no such file or directory
But I already have all the -dev packages installed! I went on and installed tk-dev, tk8.5-dev and tk8.4-dev and the problem persists. I did a 'locate tk.h' and there was no tk.h anywhere in my system. Wherever this problem was reported, people were trying to get tcl.h too. So I did a sudo apt-get install tcl-dev and did a 'locate tcl.h'. Nothing! Where did all the header files go?
Your problem is, that WCKs setup.py and setuplib.py don't have a clue where to look with the layout on your system, so you will have to fix those to get it working.
I assume your using some variant of Debian Linux there, so maybe have a look at their guidelines for packaging Tcl/Tk.
Basically they recommend adding configure switches like:
--with-tcl=/usr/lib/tclX.Y
--with-tk=/usr/lib/tkX.Y
--with-tclincludes=/usr/include/tclX.Y
http://pkg-tcltk.alioth.debian.org/tcltk-policy.html/ap-debian_oddities.html
http://pkg-tcltk.alioth.debian.org/tcltk-policy.html/ch-tcltk.html
With that info, you might be able to get it to work by editing setup.py and simply adding a version of find_tk() that works for your system.

Categories