可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
How do I pip install pattern packages in python 3.5?
While in CMD:
pip install pattern
syntaxerror: missing parentheses in call to 'print'
Shows error:
messageCommand "python setup.py egg_info" failed with error
code 1 in temp\pip-build-3uegov4d\pattern
seaborn
and tweepy
were all successful.
How can I solve this problem?
回答1:
pip install pattern3 - Python 3.x
pip install pattern - Python 2.7.x
回答2:
As of writing, Python 3.6 support is still not merged with master. However, it is available in the python3 branch.
To install via pip:
pip install https://github.com/clips/pattern/archive/python3.zip
Note that ThReSholD's answer for Python 3 (pattern3) is for a:
deprecated pattern3 repository which contains a completely different code base that is not maintained anymore
回答3:
It looks like from the documentation that, for python 3, pattern is only supported in 3.6 and up. https://github.com/clips/pattern#installation
This worked for me to get pattern.en working in python 3.6:
git clone -b development https://github.com/clips/pattern
cd pattern
sudo python3.6 setup.py install
https://github.com/clips/pattern/issues/62
I had some SSL errors during installation on my mac (10.11.6) that were fixed by running this code in python (3.6):
import nltk
import ssl
try:
_create_unverified_https_context = ssl._create_unverified_context
except AttributeError:
pass
else:
ssl._create_default_https_context = _create_unverified_https_context
nltk.download('wordnet_ic')
apparently there's a better way to deal with ssl stuff like this fwiw:
https://stackoverflow.com/a/41351871/8870055
sanity check:
user@USDR00253 ~> python3.6
Python 3.6.4 (v3.6.4:d48ecebad5, Dec 18 2017, 21:07:28)
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>>
>>> from pattern.en import conjugate, lemma, lexeme, parse
>>>
>>> print(parse('ridden', relations=True, lemmata=True))
ridden/VBN/B-VP/O/O/ride
>>>
pattern.en finally running in python 3!
回答4:
The short answer at the moment is - you can't. They haven't quite finished the port to python3 yet.
There is alleged compatibility in the development branch but the recommended manual setup didn't work for me (in virtualenv) - it fails in a different way.
https://github.com/clips/pattern/tree/development
The porting issue thread is here, spanning 2013 to yesterday:
https://github.com/clips/pattern/issues/62
The official A contributing port repo is here, but it's not finished yet (the readme says there is no Python3 support).
https://github.com/pattern3/pattern
So you could try pip install pattern3
which does install it - but it has a different package name, so you would have to modify any references to it. For me this is "impossible" as it's required by other 3rd party packages like GenSim.
UPDATE
I did get it working in the end in Python3 with Gensim, by manually installing it from the development branch as suggested and fixing up a few problems both during install and execution. (I removed the mysql-client dependency as the installer isn't working on Mac. I manually downloaded the certs for the NTLK wordnet corpus, to fix an SSL error in the setup. I also fixed a couple of scripts which were erroring, e.g. an empty 'try' clause in tree.py). It has a huge set of dependencies!
After reading more on the port activity, it seems they're almost finished and should release in a few months (perhaps early 2018). Furthermore the pattern3 repository is more of a "friend" than the official Python3 fork. They have already pulled the changes from this contributor into the main repo and they are preparing to get it released.
Therefore it should become available on pip
in the main pattern
package (not the pattern3 one which I presume will be removed), and there should be no package name-change problems.
回答5:
In the upgrade from python 2.x to 3.x, the print statement was made into a function call rather than a keyword. What used to be the line print "Hello world!"
is now the line print("Hello world!")
. So now all code written for 2.x that prints to the console does not work in version 3.x, as the compiler hits a runtime error on the print statement.
There are really only two fixes to this problem: Use version 2.x instead, or find a library built for version 3.x.
回答6:
Additionally, I was facing :
"BadZipFile: File is not a zip file" error while importing from pattern.
This is because sentiwordnet
which is out of date in nltk. So comment it in :
C:\Anaconda3\Lib\site-packages\Pattern-2.6-py3.5.egg\pattern\text\en\wordnet\_init.py
Make sure the necessary corpora are downloaded to the local drive
for token in ("wordnet", "wordnet_ic"): , "sentiwordnet"
try:
nltk.data.find("corpora/" + token)
回答7:
Using Windows Subsystem for Linux, I made pattern to work using conda from (miniconda) in
Python 3.6:
conda create -n test -c conda-forge python=3.7 pattern
conda activate test
works without issues
Python 3.7:
conda create -n test -c conda-forge python=3.7 pattern
conda activate test
I discovered that there is a bug with StopInteration due to PEP-479, and replacing raise StopIteration
with return
in pattern\text\__init__.py
fixes it.
To find the location if the file, I executed
cd $(python -c "from distutils.sysconfig import get_python_lib;print(get_python_lib())")
nano pattern/text/__init__.py
Line 605, just above class Lexicon(lazydict): ...
replace raise StopIteration
with return
.
And all is working fine.
![](https://www.manongdao.com/static/images/pcload.jpg)