How do I pip install pattern packages in python 3.5? - python

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?

pip install pattern3 - Python 3.x
pip install pattern - Python 2.7.x

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

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!

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.

For Mac OS:
brew install mysql
export PATH=$PATH:/usr/local/mysql/bin
pip3 install mysql-connector
pip3 install https://github.com/clips/pattern/archive/python3.zip

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.

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)

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.

Related

I deleted default python on fedora and now getting errors

I recently deleted the default python version on Fedora 31 and installed python 3.9 then made it as default, now I have multiple versions of python.
If I type: whereis python in my terminal this list appear:
python: /usr/bin/python /usr/bin/python3.9 /usr/bin/python3.7 /usr/bin/python3.9-config /usr/bin/python3.7m /usr/bin/python3.9-x86_64-config /usr/lib/python3.9 /usr/lib/python2.6 /usr/lib/python3.7 /usr/lib64/python3.9 /usr/lib64/python3.7 /usr/local/bin/python3.7m-config /usr/local/bin/python3.7 /usr/local/bin/python3.7m /usr/local/lib/python3.7 /usr/include/python3.9 /usr/include/python3.7m /usr/share/man/man1/python.1.gz /usr/src/Python-3.7.4/python
If I type pip then I get ModuleNotFoundError: No module named 'pip'
Also multiple packages are broken such as dnf, argcomplete, pip, etc.
I cannot update or install anything.
How can I solve this problem ?
Grab/Download the original python RPMs for your distro and reinstall them that way if they're not still cached under /var ....
With Python 3.9 you should use pip3...So install python3-pip.
That should do the trick
I tried many solutions and didn't work, however I ended up backing up my data and completely deleting the OS, then I downloaded the last version of fedora and restored my data on it.
thanks for your time
I ran into this unfortunate situation as well on Fedora 35. dnf, yum, and a bunch of other things broke.
I didn't manage to get Python 3.10 back through dnf, yum, or apt-get. I downloaded the rpm from https://fedora.pkgs.org/35/fedora-x86_64/python3-3.10.0-1.fc35.x86_64.rpm.html. It did require a dependency of python3-libs which I downloaded from: https://fedora.pkgs.org/35/fedora-x86_64/python3-libs-3.10.0-1.fc35.x86_64.rpm.html.
I installed python3-libs first with sudo rpm -i python3-libs-3.10.0-1.fc35.x86_64.rpm --force as there were some file writing conflicts. I ran the same command for the python3.10 rpm with the --force flag as well since there were 2 conflicts. After that, everything worked perfectly! Managed to dodge having to do a full reinstall.

Python, Cygwin - ImportError: No module named _psycopg

I used the article on https://github.com/nwcell/psycopg2-windows and https://bitbucket.org/topper/psycopg2-win64-py27/overview to get psycopg2 installed and working on Python2.7 and Cygwin.
The install ran fine and i see the package in the /usr/lib/python2.7/site-packages/psycopg2-2.5.3-py2.7.egg/ directory.
However the import does not work.. Any idea on this error?
Python 2.7.8 (default, Jul 25 2014, 14:04:36)
[GCC 4.8.3] on cygwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import psycopg2
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python2.7/site-packages/psycopg2-2.5.3-py2.7.egg/psycopg2/__init__.py", line 50, in <module>
from psycopg2._psycopg import BINARY, NUMBER, STRING, DATETIME, ROWID
ImportError: No module named _psycopg
Thanks,
Manish
I was getting this exact set of messages -- but not in my local Cygwin/Babun dev environment -- I got them when I pushed to the RHEL 7 server to test there. It took two days to flush it out, and how I solved it likely doesn't apply to you. But I learned some things that probably do.
Another cause of this error is argued at great length in these bug reports (with Python and psycopg pointing fingers at each other) -- and generally not worth the read -- read on below instead:
http://bugs.python.org/issue16047
https://psycopg.lighthouseapp.com/projects/62710/tickets/201
The gist of it? Look for some updates -- it looks like they both might have made some small changes that affect this.
Anyway... this is how I installed psycopg2 in Cygwin (assuming Babun's pact installer is available):
pact install libpq-devel
pip install psycopg2
Yup, that's it! (Some envs might also require a C compiler and python*-devel.)
An alternative to installing libpq-devel is to install Windows Postgres and add the location of its pg_config file to your PATH so that pip can compile psycopg2 -- but installing libpq-devel from the Cygwin shell is cleaner and it puts its pg_config where pip can already find it.
I installed pyscopg2 from within a virtual env but that shouldn't have mattered. What might matter, however, could be one of the following:
Python version: You were using 2.7.8 (almost the latest for the time), I was using 3.4.3. Try a later version of 2.7.
psycopg2 version: You were using 2.5.3, I was using 2.6.1.
Conflicting Python installs. Check the sys.path values from within Python to make sure it looks as you would expect. This doesn't appear to be your problem according to what you posted, but I mention it because this was ultimately my problem on RHEL 7 and how Apache was loading the virtual envs. ---- (Just another note here: I ultimately resolved the RHEL problem by compiling another mod_wsgi for Python 3.4.3, as per their instructions, to match my virtual envs. The previous mod_wsgi was running under Python 2.7.5 and that version was failing to import _psycopg from a C library. Besides, I didn't want 2.7 running at all.)
Env = python 2.7.10 (cygwin distribution), Windows 7, Cygwin 64
1) pip install psycopg2 failed as I didn't have pip
debug
2) Installed pip from here: pip.pypa.io/en/stable/installing/
3) pip install psycopg2 failed due to 'no pg_config...'
4) psycopg2 installer for win (www.stickpeople.com/projects/python/win-psycopg/) failed cause I am using cygwin's python install, not the python in the machine's registry and this installer won't allow user to install anywhere else other thatn the python that is registred with Windows
(Installer succeeded, but the files were not where I needd them.)
("Copying" the files didn't work.)
5) This (https://github.com/nwcell/psycopg2-windows) pip install "worked" (gave no errors) but when I tried to import, I got the message:
"ImportError: No module named psycopg2"
6) pip uninstall psycopg2
7) Tried to pip install libpq-dev and python-dev
"Could not find a version that satisfies the requirement libpq-dev (from versions: )
No matching distribution found for libpq-dev"
8) installed Postgres & pg_config from here http://www.enterprisedb.com/products-services-training/pgdownload#windows
9) added pg_config to path
10) pip install psycopg2 now worked
11) import psycopg2 in .py file caused core dump
Stack trace:
Frame Function Args
006001A5A60 0018007261A (000FFFFE3F4, 0000000E514, 00000000000, 000FFFFDE50)
006001A5B00 00180073DD0 (00077801FD6, 00000000000, 00000000140, 00000000000)
006001A5D50 0018012EF8F (00600010540, 00000000000, 003DB05FDB0, 6FFFFF28050)
006001A6040 0018012BC70 (0000000000D, 00000000000, 00000000000, 0018013D7DA)
00000000000 0018012C139 (006001A6030, 3630303030303030, 3036303030303030, 00000
00000B)
00000000000 0018012C30C (00000000000, 10000000A8E73, 6F007000650072, 61006C0074
0072)
00000000000 00180127BFB (00000000000, 10000000A8E73, 6F007000650072, 61006C0074
0072)
00000000000 00180071169 (01000000010, 00000000000, 00000000000, 000FFFFCE00)
000FFFFAA00 00180073D11 (B64000B00630079, 00000000088, 1D17578E1C375D4, 1D17578
E16661AE)
52004F00520052 64006F00630072 (00000000088, 1D17578E1C375D4, 1D17578E16661AE, 1
D175A09055FB4F)
52004F00520052 70002E00730065 (1D17578E1C375D4, 1D17578E16661AE, 1D175A09055FB4
F, 1D175A09055FB4F)
52004F00520052 B64000B00630079 (1D17578E16661AE, 1D175A09055FB4F, 1D175A09055FB
4F, 0000000180B)
52004F00520052 00000000088 (1D175A09055FB4F, 1D175A09055FB4F, 0000000180B, 0000
0002000)
52004F00520052 1D17578E1C375D4 (1D175A09055FB4F, 0000000180B, 00000002000, 01A0
0000020)
52004F00520052 1D17578E16661AE (0000000180B, 00000002000, 01A00000020, 45001600
000000)
52004F00520052 1D175A09055FB4F (00000002000, 01A00000020, 45001600000000, 4E004
500540058)
End of stack trace (more stack frames may be present)
(The above took ~2 days.)
12) pip install pg8000 worked
13) imported pg8000 to .py file and connected to DB
(Steps 12 and 13 took ~20 minutes.)
It's mandatory to install libpq, which sometimes is not installed as part of libpq-devel. As of now, I succedded installing libpq5.
You must use Cygwin package installer to install BOTH of the two packages:
libecpg6, for psycopg2 runtime library support, without it you will get
'ImportError: No module named _psycopg' when you run your script.
libecpg-devel, for compiling psycopg2 without it you will get a lot of
such as pthread_*** errors when you install psycopg2 using pip tool.
As time goes on, those package name may be changed, but you should know what's
you deficiency.

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.

Homebrew failing to install postgresql; python 64-bit errors

I'm getting errors when running
$ brew install postgresql
==> Downloading http://ftp.postgresql.org/pub/source/v9.1.2/postgresql-9.1.2.tar.bz2
File already downloaded in /Users/neil/Library/Caches/Homebrew
Warning: Detected a framework Python that does not have 64-bit support in:
/Library/Frameworks/Python.framework/Versions/Current/Python
e configure script seems to prefer this version of Python over any others,
you may experience linker problems as described in:
http://osdir.com/ml/pgsql-general/2009-09/msg00160.html
fix this issue, you may need to either delete the version of Python
own above, or move it out of the way before brewing PostgreSQL.
te that a framework Python in /Library/Frameworks/Python.framework is
e "MacPython" version, and not the system-provided version which is in:
/System/Library/Frameworks/Python.framework
==> ./configure --disable-debug --prefix=/usr/local/Cellar/postgresql/9.1.2 --datadir=/usr/local/Cellar/postgresql/9.1.2/shar
^C
Here's where python is located.
$ which python
/usr/local/bin/python
I modified my ~/.zshrc PATH from
export PATH=/Library/Frameworks/Python.framework/Versions/2.7/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/X11/bin
to
export PATH=/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/X11/bin
And although I'm getting python 64-bit errors, my version of python is 64-bit according to this SO post:
$ python -c 'import struct;print( 8 * struct.calcsize("P"))'
64
The problem pointed out in the referenced mailing list post is that the configure step isn't impacted by the PATH here. There's a whole other mechanism used to find things to link against; see Where do I set DYLD_LIBRARY_PATH on Mac OS X for a quick intro. You could try the suggested workaround given by the brew script--rename /Library/Frameworks/Python.framework/Versions/Current/Python to something else to get it out of the linker's search path, repeat the brew install, then put it back.
If you don't need Python bindings in your PostgreSQL, you can also just install it without Python bindings using brew install postgresql --no-python.
This command is installing the server, not the python bindings. Is that what you want? There is a installer for osx that will install the server for you.
Once you have done that, you can install the psycopg2 bindings directly from source.

Setuptools not found

I am switching from Linux to OSX and when I run our build's setup.py script, I get an error message that contains the text
This script requires setuptools version 0.6c7.
I have tried several times to install setuptools, and have verified that the setuptools egg exists in /Library/Python/2.6/site-packages. I have no idea why it is not being recognized.
It is very common to have multiple versions of Python on OS X systems. In recent releases of OS X, Apple has shipped two versions itself (in /usr/bin). You may have installed more recent versions using installers from python.org (which generally exist in /Library/Frameworks/Python.framework or using a package distributor like MacPorts (which install in /opt/local/Library/Frameworks/Python.framework). Keep in mind that each version of Python requires its own copy of setuptools.
Since the site package path you report is /Library/Python/2.6/site-packages, it is most likely you have used the Apple-supplied Python 2.6.1 in OS X 10.6 to try to install a new version of setuptools. Note that Apple already supplies setuptools for its Pythons (0.6c9 for 2.6.1 in 10.6); the corresponding easy_install commands are in /usr/bin.
$ /usr/bin/python2.6 -c 'import setuptools;print(setuptools.__file__,setuptools.__version__)'
('/System/Library/Frameworks/Python.framework/Versions/2.6/Extras/lib/python/setuptools/__init__.pyc', '0.6c9')
If you are using another non-Apple-supplied Python, follow the instructions to install a new version of setuptools (or Distribute) making sure you are invoking the right version of Python. Check your shell PATH and which python to make sure.
If that doesn't help, update your question with more information.
UPDATE: Based on your further comments, it seems something was amiss in your default site-packages directory. With that problem out of the way and having established that there is an Apple-supplied setuptools version 0.6c9 installed, it appears the package you are trying to install is looking for a specific, earlier version of setuptools, 0.6c7. If that is the case, you should first determine why that is and if it is necessary. Chances are that it is just an incorrect version specification in the package's setup.py file, i.e. using == rather than >=. If you can, edit the setup.py so it can use a newer version. In the unlikely event that the package really does need that specific older version of setuptools (which may not even work with that version of Python or OS X), you could try installing the older version, like so:
$ sudo /usr/bin/easy_install-2.6 setuptools==0.6c7
$ /usr/bin/python2.6 -c 'import setuptools;print(setuptools.__file__,setuptools.__version__)'
('/Library/Python/2.6/site-packages/setuptools-0.6c7-py2.6.egg/setuptools/__init__.pyc', '0.6c7')
But you really should avoid doing that if at all possible as that will install another older version of easy_install in /usr/local/bin and could cause problems with installing and using other packages.
Have you tried to import setuptools in your setup.pyscript?
import setuptools
This solved my setuptool-ish build problems in the past.

Categories