I want to use Stanford parser in order to get typed dependency of a text. I was trying to follow the instructions provided in https://bitbucket.org/torotoki/corenlp-python, however, I got an error, both while launching the server and using the python library:
from corenlp import *
corenlp = StanfordCoreNLP("./stanford-corenlp-full-2014-08-27/")
This is the error:
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/
pexpect/__init__.py", line 1554, in expect_loopraise EOF(str(err) + '\n' + str(self))
pexpect.EOF: End Of File (EOF). Empty string style platform.
It seems the problem is about pexpect package. I already installed it as it is explained in the insturctuion. I saw similiar problem here(EOF when using pexpect and pxssh), but it is different from my case. I am using Mac and Python 2.7.
Could you please help me!
This is not the solution you wanted.
Are you sure that it is the same error if you use corenlp using the package implementation ?
pexpect is required only when there is interaction with the interactive shell of corenlp, which is present in the server implementation. In the package implementation, a file containing a list of input files is given to the parser. (using batch_parse)
In the server implementation, there is a JSON-RPC server created by the wrapper. If you want to use the server implementation, you have to remotely call one of the procedures and you don't need the package on the client end. I guess, you have mistaken in putting the right code here.
PS:
I, myself is one of the corenlp users but i used a different wrapper.
I hit the same issue while on mac. For posterity, just follow verbatim the instructions at https://bitbucket.org/torotoki/corenlp-python to use python wrapper around Stanford-corenlp. This package gets around the "End Of File (EOF). Empty string style platform." error that throws up on the some mac (or other OS, didnt check though but I know someone who also got it on windows) versions.
Also don't forget to download the stanford-corenlp-full-2014-08-27.zip instead of the latest version.
The solution of using expect(pexpect.EOF) didn't work for me (https://github.com/pexpect/pexpect/blob/master/doc/overview.rst) as the Stanford-corenlp jar was not loading properly in this case.
I also tried https://github.com/dasmith/stanford-corenlp-python as well as https://github.com/Wordseer/stanford-corenlp-python but neither of them worked. Both threw up the EOF error
Related
i have a couple of different questions regarding importing modules and another non-related syntax question.
So, i'm using a module called netmiko to automate networking scripts, this isn't a networking question but a python one, i create the scripts in Pycharm and then run them but when i tried to do one last night for the first time using Netmiko it's coming up with an import module failed exception which is confusing me because i've installed it using "pip install netmiko" and i saw it install AND if i do "import netmiko" using the command line on Windows then it works as well with no exceptions. So i've been building the scripts in Pycharm but having to copy/paste them into then cli which isn't great. Does anybody know what the issue may be here?
The second question is just a general syntax question. I've seen "+=" used when using the same variable names in Python (mainly used in netmiko scripts but i assume it's obviously used in other Python scripts to) such as:
output = net_connect.send_command(cmd, expect_string=r'Destination filename')
output += net_connect.send_command('\n', expect_string=r'#')
....the rest of the script isn't import, but i'm wondering what the "+=" is actually doing here because to me it seems no different than doing:
output = net_connect.send_command(cmd, expect_string=r'Destination filename')
output = net_connect.send_command('\n', expect_string=r'#')
Can anyone shed some light on this as well?
Thanks as usual everyone!!
I have a Windows machine in which some Python code works, but now needs to work on new machine.
I have installed the same Python version 3.6.5.
First issue was that when I run the code, it can not find a re.py library, which is in fact in Python's Lib folder. So I have added sys.path.append('C:\Python\Lib') and now it can find it.
But now I get the syntax error from that library, where I say import re, that lines throws an error regarding some line in re.py library. If I import getopt, I also get syntax error on some line.
How is that even possible? Syntax error in pythons Lib files which came with installation?
And the thing is that on machine 1 it works, same file contents, same python version. I am under impression that I have wrong in python.exe version for this version of libraries, but I have simply downloaded Windows installer and installed it.
I don't even know what to google for, does someone has any idea? I am importing re in WeblogicAuto.py on line 5.
D:\Jenkins\workspace\weblogic-full-deployment-copy\weblogic-deployment>MainAutoDeployment.py -f DEV -v 2.61.0.12
Initializing WebLogic Scripting Tool (WLST) ...
Welcome to WebLogic Server Administration Scripting Shell
Type help() for help on available commands
Problem invoking WLST - Traceback (innermost last):
File "D:\Jenkins\workspace\weblogic-full-deployment-copy\weblogic-deployment\WeblogicAuto.py", line 5, in ?
File "C:\Python\Lib\re.py", line 247
b"_abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ01234567890")
^
SyntaxError: invalid syntax
You are using WLST (WebLogic Scripting Tool).
WLST is very specific distribution of python:
it's jython
it roughly corresponds with python 2.7
And you trying to import libs from your CPython 3.6.5 distribution.
You need to:
remove your sys.path.append that you added earlier
check python libraries in jython library path. Which could be $HOME/.jython or WLST-specific path (look in WebLogic documentation)
OK many thanks to ya all, I've found the solution, it was about Jython libraries. I will try to elaborate a bit if someone stumbles upon this issue.
What I do here is that I deploy java modules to Oracle Weblogic application server. So this answer will also help someone trying to deploy to Weblogic from python.
From the start I was avoiding to install Webloglogic software on a machine from where I do the deploy (and that is a Jenkins slave which runs these python file, simple job).
I noticed that first machine (first Jenkins slave) has Weblogic installed, but I like to keep it minimal :)
What you do need is weblogic.jar and (not sure at this moment) wlfullclient.jar which is generated on Weblogic server (google how if needed or you may already have it).
The thing is that even though I have pure python code, when you call another python code with java weblogic.WLST pythonCode.py, it will be run with jython application! And it needs its libraries in its sys path.
In jython file I've added print(sys.path) then run in on both machines (slaves). I've noticed that path is different on those machines, even though if you type it in command prompt you get the same, but different then when Jenkins runs it.
So instead of looking how to fix those paths and copy files to them, I have created folders where it expects them, and copied them from first machine (easy fix, I may look into it later).
These are the sys.path and files that were needed, present on first machine:
['D:\\Jenkins\\weblogic\\Lib', '__classpath__', 'C:/bea10/wlserver_10.3/server/lib/weblogic.jar', 'C:/bea10/wlserver_10.3/common/wlst/modules/jython-modules.jar/Lib', 'C:/bea10/wlserver_10.3/common/wlst', 'C:/bea10/wlserver_10.3/common/wlst/lib', 'C:/bea10/wlserver_10.3/common/wlst/modules', '.']
This was sys.path on second machine, so I simply copied there:
['D:\\Jenkins\\weblogic\\Lib', '__classpath__', 'D:/Jenkins/server/lib/weblogic.jar', 'D:/Jenkins/common/wlst/modules/jython-modules.jar/Lib', 'D:/Jenkins/common/wlst', 'D:/Jenkins/common/wlst/lib', 'D:/Jenkins/common/wlst/modules', '.']
Note that jython-modules.jar is a file, so /Lib should be from that file if I get how java works.
Feel free to contact me for more details.
Primarirly I am c++ developer trying to use python for certain tasks for me.
I have made a python module in python 3.6 and got it pre-compiled in windows 7 using the following command
python -m py_compile myfile.py
using information from this link. I get "myfile.pyc" created
Now I want to use this in a python file which is using python 2.7
so, I use information from this and this & write
mod=imp.load_source('myfile.func', 'c:/folder1/folder2/myfile.pyc')
But the above statement gives me exception
[name 'o' is not defined]
Is this because I am using pre-compiled in 3.6 & using in 2.7?
What is that am I missing here
First python 3.6 is not backwards compatible with python 2.7. Secondly its usually better to import the module as normal and let the compiler handle caching library code as compiled byte code. Also the function load_source is meant for loading uncompiled source files, the function you want is load_compiled. Check here
https://docs.python.org/2/library/imp.html
Lastly, if you are looking for performance improvements this will only help reduce compile time, and only on the first compile or when the imported file changes.
What is __pycache__?
This is the complete solution of my problem. ( If you do not want to go through all the comment & discussion & figuring out the solution )
As Mr. Garrigan Stafford aptly pointed out that I am using the wrong API for loading the module.
The API for loading a compiled module is load_compiled & not load_source.
When I started using this API, ran in to the error of magic number: Bad magic number.
This happens because while creating the file, the compiler inserts certain values to basically identify what file is it. ( more info : can be found here.).
In my case, compiled my lib is 3.6 & used in 2.7 which was causing the problem.
To overcome, I basically went back to the original code & compiled my lib in 2.7 & then used it in the client code.
Volla !!!!
All works fine now.
Thanks to stackoverflow community as whole & Mr. Stafford in particular for helping out.
I have downloaded the pyivi.0.08 package but experience an error when run the command import pyivi. I have also installed the NI Visa and the 488.2 package.
Is there any other package to be installed before running this command.
I am trying to communicate with a Keysight/Agilent Network analyzer through a GPIB using python scripting.
Thanks in advance.
The package pyivi.0.08 is supported on the Python package index and has a nice set of documentation here: https://pypi.python.org/pypi/pyivi/0.0.8
If the documentation doesn't get you started, please list the specific error, and mention how far you were able to work through the documentation. I'll update my answer to respond to your error message.
I am a newbie to Stack Overflow (first post), but really see the use of this website.
I'm stumped. We are trying to setup IIS 7.0 to run with WinPython 2.7 on a Windows 7 machine.
I am an IIS newb, but veteran Python user. IIS 7 can NOT find a library, which python finds, and executes, perfectly when ran on it's own. When executed via IIS, the script fails with a traceback, and IIS returns the 502.2.
I found this thread http://forums.iis.net/p/1209465/2073173.aspx?HTTP+Error+502+2+Bad+Gateway+Frustrations but the advised solution is simply another troubleshooting suggestion.
I found IIS's description (http://support.microsoft.com/kb/942057) of the error helpful, but futile.
I found Python's start-up options/parameters helpful (http://docs.python.org/2/using/cmdline.html), but futile.
I found IIS's advice for configuring Python helpful (http://support.microsoft.com/kb/276494, but (questionably?) incomplete.
This thread on manually defining an alternate bin folder (http://forums.asp.net/t/1303052.aspx?Tell+IIS+to+load+dll+from+another+directory+not+Bin+web+config+) might be where my solution lies, but I don't think it is because of the fact that this all worked on 2.6 without doing that to IIS.
IIS seems to allow python to import any module that is just a python script. As soon as it gets to a *.pyd (basically just python's version of a dll file) file, it screams. I'm no pro when it comes to DLLs and windows environments, but wouldn't IIS have to have paths to a bin folder of some kind? Do I have to manually edit them, as discussed in the last link above?
ACTUAL ERROR Details below for DLL failed Load:
The Error :
" HTTP Error 502.2 - Bad Gateway The specified CGI application
misbehaved by not returning a complete set of HTTP headers. The
headers it did return are "Traceback (most recent call last): File
"\estorage.equitable.int\riskmgmt\Quants\web\LinksPage.py", line 2,
in import pyweb File
"\estorage.equitable.int\riskmgmt\Quants\Common2014\Python\pyweb__init__.py",
line 5, in from core import * File
"\estorage.equitable.int\riskmgmt\Quants\Common2014\Python\pyweb\core.py",
line 2, in from pylib import pgdb File
"\estorage.equitable.int\riskmgmt\Quants\Common2014\Python\pylib\pgdb.py",
line 8, in from scikits import timeseries as ts File
"C:\WinPython-32bit-2.7.6.2-20140401\python-2.7.6\lib\site-packages\scikits.timeseries-0.91.3-py2.7-win32.egg\scikits\timeseries__init__.py",
line 13, in import const File
"C:\WinPython-32bit-2.7.6.2-20140401\python-2.7.6\lib\site-packages\scikits.timeseries-0.91.3-py2.7-win32.egg\scikits\timeseries\const.py",
line 79, in from cseries import freq_constants ImportError:
DLL load failed: The specified module could not be found. ".
I'm confident that the python environment is configured properly, as the script runs from the same executable (python.exe) via a command line. I'm thinking that I don't have IIS configured properly, for the new Python 2.7 install. The same script worked yesterday, on IIS and python 2.6. But during our upgrade from 2.6 to 2.7, a bunch of PATH and PYTHONPATH parameters all changed, plus we went from ActivePython to WinPython. WinPython is "registered" on the machine.
What I've tried
confirming python's sys.path is as expected at run-time in both IIS and command line - it is.
using the module from python command line.
recompiling the failing module using two different compilers (ming32 and VS2008).
putting duplicates of my new 2.7 modules in the old python26 folder.
pulling out lots of hair and other hacky stuff.
My next step, is to post this same message on a python forum. If anybody can advise on a good one for python-IIS related challenges, that would be appreciated.
Please help! Thanks in advance.
I got this 502.2 error when doing a clean installation of PHP 5.5 in Windows Server 2012 R2 with IIS 8.5.
It turns out PHP is a Visual C++ application which needs the library MSVCR110.dll in order to run properly. My computer does not have Visual Studio 2012 installed and thus it does not have this file. I got my problem solved by installing the Visual C++ Redistributable Packages https://www.microsoft.com/en-us/download/details.aspx?id=30679#
(Note: jc77 is my associate, and I'm actually the OP, as this was an x-post from IIS forums.)
We solved the problem.
tl,dr; portable python + sloppy/rookie compiling = strange behaviour + frustrations.
Bottom line, compile properly. For scikits.timeseries, using ming32 everything will walk, talk, and sound like it works in Spyder.exe, but not in python.exe. You have to use VS2008, if you want it to work in both.
More Info:
Winpython (as well as others) presents itself as identical to any other python installations, if you "register" the installation. It works great, 99% of the time. We learned the hard way, that "Winpython Interpreter.exe" and "python.exe" provided in the install are in fact different. Can't explain why, but the two executables gave different behavior. We were doing all our testing in Spyder, which must use "winpython interpreter.exe". The module which IIS couldn't find, would import and run no problem in Spyder. Then, in IIS, using python.exe, the module wouldn't import. We were operating on the assumption that the IDE would use python.exe, and that the stack was identical. As, 99% of the time, they appear to be. The way we were compiling scikits worked in winpython interpreter.exe. We were making a rookie mistake when compiling scikits, but it went un-noticed because it was working fine in our IDE (Spyder).
I'm adding these keywords for others : Anybody else who receives errors like this is likely using a portable python installation AND not compiling something properly. Winpython, Portable Python, eGenix, [and possibly?] Active State and Enthought Canopy.
While trying to configure CGI to run Perl in Windows 8.1, I had HTTP Error 502.2, but then I read loste's post and solved the problem. I had previously installed both Perl64 and Strawberry Perl. Although the IIS EventHandler pointed to only the Perl64 directory, both directories appeared in my Windows PATH variable. I prefer Strawberry Perl, so I changed the EventHandler to point to the Strawberry Perl directory and deleted the paths to Perl64 from the Windows PATH variable to solve the error.
Try this
print("Content-Type: text/html\n")
print("Hello Python World!")
You must specify the type of document