I'm using Windows 8, and running python in eclipse with pyDev.
I installed Stanford coreNLP (python version) from the site:
https://github.com/relwell/stanford-corenlp-python
When I try to import corenlp, I get the following error message.
Traceback (most recent call last):
File "C:\Users\Ghantauke\workspace\PythonTest2\test.py", line 1, in <module>
import corenlp
File "C:\Python27\lib\site-packages\corenlp\__init__.py", line 13, in <module>
from corenlp import StanfordCoreNLP, ParserError, TimeoutError, ProcessError
File "C:\Python27\lib\site-packages\corenlp\corenlp.py", line 28, in <module>
import pexpect
File "C:\Python27\lib\site-packages\pexpect.py", line 85, in <module>
support it. Pexpect is intended for UNIX-like operating systems.""")
ImportError: No module named resource
A critical module was not found. Probably this operating system does not
support it. Pexpect is intended for UNIX-like operating systems.
Does that mean the python fork of it doesn't work in windows? Is there any way I can make it work in windows?
If not then could you suggest other alternatives that I could use in windows. I just need the parser.
This is a record of my attempts to get corenlp-python, the python wrapper for CoreNLP running on Windows Server 2012, as-is.
Disclaimer: should you only need to run an executable, check this first. Consider subprocess.
Starting out
Since corenlp-python uses pexpect fairly heavily, and that library works on UNIX only, my first thought was to find a Windows port.
wexpect.py was fairly easy to find and claims to be a drop-in replacement for Pexpect (emphasis mine):
In order to use WExpect, you must install CygWin, and then install the WExpect script into your system (dropping the py file into your working directory is usually good enough).
I’ve found the functionality is pretty much the same, so you should be able to use the PExpect manual and examples and apply them to this Microsoft Windows variant.
So I did just that, downloading and installing CygWin, then copying wexpect.py into C:\Python27\lib\ where all the other libraries were. I tried to import wexpect from a Python shell and got an error similar to when I first tried Pexpect on Windows:
ImportError: No module named pywintypes
This module requires the win32 python packages.
A critical module was not found. Probably this operating system does not
support it. Pexpect is intended for UNIX-like systems.
Et tu, wexpect?
No matter, this is standard frustration for finding equivalents. Press on.
I opened wexpect.py and saw that it would only try pywintypes on a Windows system. Logical, so I tried:
$ pip install -U pywintypes
...which failed, and led me to Google for the name of the python Win32 packages (this answer helped):
$ pip install -U pywin32
...which prompts for --allow-external and then --allow-unverified, both of which expect the package name, ergo:
$ pip install --allow-external pywin32 --allow-unverified pywin32 pywin32
Which, of course, does not work. No such package is found.
sf.net
So I head off to search for pywin32 on PyPI and realise that only a readme is left and I have to jump through four MORE hoops to get to something more substantial, then two more to find this list.
I downloaded Build 219 for Python 2.7 32-bit. At least now import wexpect doesn't puke.
What did you expect?
So I run the corenlp-python command again, and this time it's missing unidecode. This was easier to fix, and finally I got to a usable state - an error, no less, but familiar - where the path to the JARs was not correct.
OK.
When you run corenlp.py, since pexpect is invoked, remember to import wexpect as pexpect near the top and comment out the real import pexpect line, or you will get a NameError:
#import pexpect
import wexpect as pexpect
Even with Java installed, this does not seem to work, regardless of path.
$ python lib\corenlp\corenlp.py
It returns an ExceptionPexpect.
Related
I am very new to Python, and I am attempting to reproduce an example (not necessary to answer the question). If all I have is import threading from within the code I assumed I could just run pip install threading however the module is not found. When I searched for a different package name in the Python package manager I came across hundreds. Why doesn't the pip command work, and how do I know which package to install?
My exact error
:\Users\king\Desktop\_REPOS\misc\stock_analysis\forex\python\pythonv2>python trading.py
Traceback (most recent call last):
File "trading.py", line 1, in <module>
import Queue #pip install queuelib
ImportError: No module named 'Queue'
Version info
Python 3.5 32bit (64 bit OS)
The first hit on google (search: python threading) actually gave me:
https://docs.python.org/2/library/threading.html (the URL itself already indicate it)
This means it's a library module so it should be already available to you without extra installs.
In case your Python is limited in a way and doesn't have it by default, please update your question with your Python version and way it was installed.
For future reference, you were mostly doing the right thing, a lot of modules have the same name as their import statements, but otherwise, in almost all case, a simple Google search will suffice.
Could someone help, please? I can't understand why I see this.
I'm trying to use spwd module from Python. I just imported it, but see this, absolutely unexpected, error when running:
Traceback (most recent call last):
File "./library/system_users.py", line 25, in <module>
import spwd
ImportError: No module named pwd
I thought it should be available by default.
Python 2.7.10
pip 8.1.1 from /Library/Python/2.7/site-packages (python 2.7)
OS X El Capitan 10.11.4
I know sometimes pip install --upgrade pip can help. Unfortunately, not now.
Thank you for the advance.
As you guessed in your comment on this question, spwd is a built-in module, so it is usually built as you compile Python. For this reason, I would guess that spwd simply isn't supported on the system you are using—i.e. OS X 10.11—unless whoever built your installed version of Python made a configuration mistake or manually disabled the module.
However, we can do more than guess about this. When building Python, much of the system-specific configuration is handled in a script called setup.py. Support for many built-in modules is determined in the detect_modules method of the PyBuildExt class; the function contains the following code (taken from here).
if (config_h_vars.get('HAVE_GETSPNAM', False) or
config_h_vars.get('HAVE_GETSPENT', False)):
exts.append( Extension('spwd', ['spwdmodule.c']) )
else:
missing.append('spwd')
We can see that the function adds the Extension 'spwd' (which consists of the spwdmodule.c source file) to the lists of extensions only when config_h_var has either HAVE_GETSPNAM or HAVE_GETSPENT. The strings in config_h_vars correspond to the macros that are defined in the pyconfig.h header file that is generated when you run Python's configure script before compiling.
According to comments generated with the pyconfig.h file, HAVE_GETSPNAM is defined (to 1) if your system has the getspname function, and HAVE_GETSPENT is defined (again, to 1) if your system has the getspent function.
The problem is that OS X 10.11 (and, seemingly, newer versions of macOS) have neither of these functions. (The manual for gnulib confirms this, albeit for an older version of Mac OS X. See this page and this page.) Thus, when compiling Python on OS X/macOS, the spwd is not built, and so you see an ImportError when you try to import it on that system.
dooms's answer suggests installing spwd from Anaconda. Of course, this isn't expected to work since spwd is a built-in module, not a package you would expect to install from a package manager. I also don't see a spwd package on PyPI or any Anaconda channels.
However, since Python does not seem to prevent you from installing a module named spwd (at least when you don't have the built-in spwd), it is conceivable that you could install some sort of drop-in replacement spwd made for macOS. macOS and iOS use /etc/master.passwd instead of /etc/shadow, but maybe it might still be possible to make something work.
Unfortunately, as of this writing, it doesn't seem like any such replacement exists for macOS. I would treat any software that requires spwd as incompatible with macOS.
You should use Anaconda.
Anaconda is a completely free Python distribution (including for commercial use and redistribution). It includes more than 400 of the most popular Python packages for science, math, engineering, and data analysis. See the packages included with Anaconda and the Anaconda changelog.
After that, just type :
conda install spwd
From IDLE, I tried to run a script with a newly installed scrapy 1.0.3.
I'm using a script from a friend whom it worked for (but on Windows, I'm on a Mac).
From the import of scrapy on the first line, I get this error when running the program:
ImportError: No module named twisted.persisted.styles
The whole script, if it's helpful, points to this:
Traceback (most recent call last):
File "/Users/eliasfong/tutorial/tutorial/spiders/medspider.py", line 1, in <module>
import scrapy
File "/Library/Python/2.7/site-packages/scrapy/__init__.py", line 27, in <module>
from . import _monkeypatches
File "/Library/Python/2.7/site-packages/scrapy/_monkeypatches.py", line 20, in <module>
import twisted.persisted.styles # NOQA
ImportError: No module named twisted.persisted.styles
Any suggestions on how to tackle this problem?
Just try to force the update of twisted :
pip install twisted --upgrade
That works for me with python3.4 and Scrapy==1.1.0rc1
Either twisted is installed on your mac (I highly doubt it since it's not a standard library) and for whatever reason the IDE (i'm assuming that's what you mean since you typed "idle") or the terminal you are in doesn't have your updated environment variables, meaning it doesn't understand where your default python libraries are (again I highly doubt it), or you simple do not have twisted installed on your mac. If it's not installed you have a couple of options:
The easiest way to install a python package is through pip.
If that not an option you can try homebrew which is another package manager for macs. It offers an easy way to install packages correctly.
If that still is not an option for you or you simply don't want to attempt that you can download twisted directly from here (the .bz2 since you're on a mac), click on it and it should unzip it for you. Then just run setup.py and it should install it in the correct location on your mac.
If that still doesn't work and you have decent knowledge of unix. Use the "locate" command on the terminal and find out where your dist-packages directory is and put the source for twisted in there directly and then attempt to import twisted in your IDE or in the python interpreter to verify that it is installed.
note: If you're still having problems after it is installed trying restarting your IDE or messing with some setting to make sure your IDE has the right environment and python path. Hope that helps!
It could be related to having installed Python without bzip2. I had the same error and this helped me, see the accepted answer here:
Installing Twisted through pip broken on one server
Had this exact thing on FreeBSD. Solution (as root/sudo):
chmod -R go+rX /usr/local/lib/python2.7/site-packages
Some directory permissions weren't set up right on install.
I'm trying to run git-cola from Red Hat Enterprise Linux Server release 6.5 and receive:
Traceback (most recent call last):
File "....../bin/git-cola", line 24, in <module>
from argparse import ArgumentParser
ImportError: No module named argparse
I think I have all of the required packages installed:
* git-1.7.1-3.el6_4.1.x86_64
* python-2.6.6-51.el6.x86_64
* PyQt4.x86_64 0:4.6.2-9.el6
* /usr/lib/python2.6/site-packages/argparse-1.2.1-py2.6.egg
I read in other blogs that there may be a problem with Python 2.6 and may need to move to 2.7.
Additional information - #iljau noticed that argparse is in a 32 bit lib, while the rest of python is in 64 bits. I would have expected that:
easy_install argparse
would have sorted this out and installed the 64 bit version.
Additional question: Does anyone know how to install the 64 bit version of argparse. It is not apparent to me from searching the internet. I will continue looking.
I installed argparse by downloading the tar file and
python setup.py install
However, it still installed it in the lib rather than lib64 path - and it looks like a 64 bit install. So something else must be the problem in referencing argparse properly. I don't know Python enough to debug it, but I suspect that git-cola needs some work for Python 2.6.
As a simple solution copy argparse.py from https://code.google.com/p/argparse/source/browse/argparse.py to your project folder.
And indeed, for Python 2.6 argparse needs to be installed separately.
From: https://pypi.python.org/pypi/argparse
As of Python >= 2.7 .. the argparse module is maintained within the Python standard library. For users who still need to support Python < 2.7 .. it is also provided as a separate package, which .. also supports older Python versions.
But even after you install argparse, it may refuse to work for some mysterious reasons.
Additional debugging tips may be found in answers and comments to question "ImportError: No module named argparse".
I had the same problem on RHEL6 and the solution was installing the package python-argparse.noarch:
yum install python-argparse.noarch
then everything was fine.
The new packages were installed in the path:
/usr/lib/python2.6/site-packages
Installing them with sudo left the newly installed directories and files unreadable by all. A recursive chmod to open all the installed paths as readable to all solved the problem:
chmod -R u+rwX,go+rX,go-w <new directories and files>
Looks like argparse is missing.
yum install python-argparse
I'm trying to build an application using the new-ish Pyramid framework. I'm new to Pyramid and have no idea what Zope does (the importance of which will become apparent). I followed the basic tutorial, but when I try to run the application I get this traceback:
Traceback (most recent call last):
File "tasks.py", line 4, in <module>
from pyramid.config import Configurator
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/pyramid-1.2-py2.6.egg/pyramid/__init__.py", line 1, in <module>
from pyramid.request import Request
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/pyramid-1.2-py2.6.egg/pyramid/request.py", line 1, in <module>
from zope.deprecation import deprecate
ImportError: No module named deprecation
I tried install Pyramid using setuptools:
sudo easy_install pyramid
Which, among a lot of other output included this:
Searching for zope.deprecation
Reading http://pypi.python.org/simple/zope.deprecation/
Best match: zope.deprecation 3.5.0
Downloading http://pypi.python.org/packages/source/z/zope.deprecation/zope.deprecation-3.5.0.tar.gz#md5=1e7db82583013127aab3e7e790b1f2b6
Processing zope.deprecation-3.5.0.tar.gz
Running zope.deprecation-3.5.0/setup.py -q bdist_egg --dist-dir /tmp/easy_install-ZiLy8j/zope.deprecation-3.5.0/egg-dist-tmp-yGFSor
Adding zope.deprecation 3.5.0 to easy-install.pth file
Which I thought should cover it.
I also tried installing zope via macports:
sudo port install zope
sudo port install py26-zopeinterface
I've also tried to run sudo port load zope before running the script, but no help there.
I also tried downloading the source from http://pypi.python.org/pypi/zope.interface and building it manually in directory.
Any ideas what I'm doing wrong?
----EDIT----
One guess is that setuptools in installing its zope components into my system's default Python framework (which is an Enthought distribution), but my default python environment is the one that Macports installed, so perhaps the Macports zope module has some but not all of the components, such as zope.deprecate.
The documentation includes information about how to use a virtualenv to install Pyramid. It's very, very recommended to use a virtualenv this way. System packages already installed in your main Python will have weird interactions with Pyramid's requirements.
You may get an answer from someone more familiar with Pyramid, but the problem here is that pyramid.request depends on zope.deprecation and it isn't installed/available. You'll have to elaborate much more on "I've tried installing zope using ..." for me to help you more.
Be sure you're running pyramid from the same python that you did the installation to. If that's the case then the zope.deprecation package should be installed there. What do you get from python -c "import zope.deprecation ; print import zope.deprecation"?
I solved it by installing zope.deprecation OS package:
sudo apt-get install zope.deprecation
Just re-install pyramid to fix.
I have had problem with moving class into sub-module.
The problem was another component of software was importing class from "OLD" module. And also there was cycling problem with inheritance.
So the solution was to use zope.deferredimport. The code looks like this:
import warnings
import zope.deferredimport
warnings.simplefilter("default")
zope.deferredimport.initialize()
zope.deferredimport.deprecated(
"Import from openprocurement.contracting.core.tests.base instead",
BaseContractWebTest='openprocurement.contracting.core.tests.base:BaseContractWebTest',
)
So now, when any component of software, that uses import from "OLD"
module doesn't get ImportError. Class is imported from "NEW" module. And warning is displayed like this:
DeprecationWarning: BaseContractWebTest is deprecated. Import from openprocurement.contracting.core.tests.base instead
So this is it. The main part zope.deferred took care of cycle imports. That saved my life.