I'm trying to install ntlk for a Django project. I followed the intstructions on NTLK's website, and I they worked because when I try to install again with pip, I get:
➜ Word_Maker git:(master) sudo pip install -U numpy
Requirement already up-to-date: numpy in /Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3/site-packages
Cleaning up...
➜ Word_Maker git:(master) sudo pip install -U pyyaml nltk
Requirement already up-to-date: pyyaml in /Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3/site-packages
Requirement already up-to-date: nltk in /Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3/site-packages
Cleaning up...
However, when I do import ntlk from python3, I get:
Python 3.3.3 (v3.3.3:c3896275c0f6, Nov 16 2013, 23:39:35)
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import nltk
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3/site-packages/nltk/__init__.py", line 37
except IOError, ex:
^
SyntaxError: invalid syntax
^
SyntaxError: invalid syntax
import numpy works, however. Any help would be appreciated!
It seems you made a spelling mistake:
Requirement already up-to-date: nltk in /Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3/site-packages
And you're trying to import ntlk. Try using import nltk.
As for the import error, the following from their website:
NLTK requires Python versions 2.6-2.7. (A version supporting Python 3 is available at http://nltk.org/nltk3-alpha/).
So NLTK does not (yet) support python 3.3 fully.
First remove NLTK using pip: sudo pip uninstall nltk
Then download the source. And install using sudo python setup.py install
And try again. Be aware this is an alpha, so expect some methods to randomly throw errors or generate unexpected output.
If you still have this error after fixing the spelling, the issue is that PyPI is installing an older NLTK package (2.x). Check this by looking at the first message in the terminal immediately after your run sudo pip install nltk.
To install the latest version of NLTK (3.x) that is compatible with Python 3, first sudo pip uninstall nltk.
Then use:
sudo pip install nltk==3.0.0b2
The latest version number is found here: https://pypi.python.org/pypi/nltk
Sometimes the versions of dependent packages may cause issues. The main issue is old, but I found a slightly different problem when using the parser - which internally was going into scipy. Solved using:
pip3 uninstall nltk scipy matplotlib
pip3 install -U nltk scipy matplotlib
Related
How should I remove multiple python versions due to which pip is pointing to some other version ?? due this even after successful installation the module is not getting imported??
Following is the error I was getting when I installed imutils successfully but still getting import error.
User-MacBook-Pro:~ user$ sudo pip install imutils
Collecting imutils
Installing collected packages: imutils
Successfully installed imutils-0.5.1
User-MacBook-Pro:~ user$ -H
-bash: -H: command not found
User-MacBook-Pro:~ user$ sudo -H pip install imutils
Requirement already satisfied: imutils in /usr/local/lib/python2.7/site-packages (0.5.1)
Installed imutils for Python2.7
and when I checked whether it is importing imutils library successfully or not then it displayed the following error message:
User-MacBook-Pro:~ user$ python
Python 2.7.14 (v2.7.14:84471935ed, Sep 16 2017, 12:01:12)
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>>import imutils
Traceback (most recent call last):
File "", line 1, in
ImportError: No module named imutils
What is the problem here and how to fix it??
And following is my bin directory which has multiple python versions but I am not able to understand which one to remove??enter image description here
If there are multiple versions of Python on your computer, that's probably because you need different versions for the Software you have installed on your computer, or simply because you are working with different versions for different Projects.
Seeing that dependencies and the resolution thereof are a fairly intricate topic, it might be a good idea to use virtual environments to manage different versions, without interfering with an otherwise stable system python.
Once you wrap your head around virtual enviroments, they are not only convenient, but also elegant. Here's an introduction to get you started
I'm wondering about the following importError which I can't get ride off. I have a local virtualenv (venv) in which I've installed multiple modules:
(venv) stam#stam:~$ pip list --local
cryptography (1.5.2)
cvxopt (1.1.9)
cycler (0.10.0)
Cython (0.25.1)
matplotlib (1.5.3)
more-itertools (2.2)
ndg-httpsclient (0.4.2)
numpy (1.11.2)
pandas (0.19.0)
paramiko (1.15.2)
Pillow (2.8.1)
pip (8.1.2)
psycopg2 (2.6)
python-apt (0.9.3.12)
python-dateutil (2.5.3)
python-debian (0.1.27)
scipy (0.18.1)
setuptools (28.6.1)
simplejson (3.8.2)
urllib3 (1.9.1)
wheel (0.24.0)
You are using pip version 8.1.2, however version 9.0.1 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
(venv) stam#stam:~$
now starting a python interpreter and trying to import cvxopt (note it is in the list above) gives me a importError. Why is this? I'm using the right python version, I work on the venv so everything should work out of the box.
(venv) stam#stam:~$ python
Python 2.7.9 (default, Aug 13 2016, 16:41:35)
[GCC 4.9.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import cvxopt
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named cvxopt
>>>
I'm a bit lost and don't know how exactly I can resolve this issue. It seems the right python version is started, at least the one I've attached to the virtualenv.
Additional outps asked for in the comments
(venv) stam#stam:~$ which python
/usr/bin/python
(venv) stam#stam:~$ which pip
/usr/local/bin/pip
Based on the output from which it seems clear that your python and pip belong to two different instances. So all libraries you install will be installed for some other python instance.
The acute fix is to force pip to run through your specified interpreter:
python -m pip list --local
python -m pip install cvxopt
Hello thanks for looking.
i am trying to import third party modules but having a hard time.
I have already done the edit to the environment variable and i get python to show up in cmd but I can not find the correct syntax to do the install.
based on the python org site i should use python -m pip install SomePackage
i have also read that i should use pip install SomePackage
I have tried both and have not had success. I am in windows 10 below is the command prompt of my attempts.
C:\Users\T****J>python
Python 3.5.2 (v3.5.2:4def2a2901a5, Jun 25 2016, 22:01:18) [MSC v.1900 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> -m pip install send2trash
File "<stdin>", line 1
-m pip install send2trash
^
SyntaxError: invalid syntax
>>> pip install send2trash
File "<stdin>", line 1
pip install send2trash
^
SyntaxError: invalid syntax
>>> python pip install send2trash
File "<stdin>", line 1
python pip install send2trash
^
SyntaxError: invalid syntax
>>> python -m pip install requests
File "<stdin>", line 1
python -m pip install requests
^
SyntaxError: invalid syntax
>>>
thanks again. searched the best i could and maybe i am missing something easy. I am new at this .
you are trying to give command line arguments within the interpreter...
If PIP is installed, you don't need to invoke the interpreter at all. Simply call:
C:\Users\T****J>pip install send2trash
from the command prompt.
otherwise, if you are using the pip module, you need to pass the command line arguments to the command line not to the interpreter...
C:\Users\T****J>python -m pip install send2trash
pip is a program itself, similar to how npm, bundler or nuget works.
What you are currently doing is firing up the Python interpreter, and writing the call to pip from there, it doesn't work like that.
What you're looking to do is to install a package with pip, like this:
C:\Users\T****J>pip install send2trash
and after that's done you can open the interpreter again and import the module like this:
C:\Users\T****J>python
>>> import send2trash
I strongly suggest, however, that you do a bit of research into virtualenv and how to use it, it will make your life easier on the long run
I'm trying to use fftw3 on python to compute ffts really fast (using all my cores!)
The problem is... I can't find the fftw3 package for python...
I know it exists because the function I need uses it if and only if it's installed.
This is the module that I use: https://github.com/keflavich/image_tools/blob/master/fft_psd_tools/convolve_nd.py
And as expected this is what I get if I try to import it:
>>> import fftw3
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named fftw3
>>>
And I've tried this:
sudo pip install fftw3
sudo apt-get install python-fftw3
sudo easy_install fftw3
And I have also tried googling for its location, or installation instructions, with nothing to be found!
I am also aware that fftw is a C library and that pyfftw exists as python wrappers for that package, but the function I use utilizes fftw3.
I am hoping someone could point me to where this module is located!
P.S. I am running Ubuntu 14.04 and I'm using python 2.7. I also tried importing it in python 3 but it's not there either.
Looks like the problem was with the package you were trying to pip. I had no errors with sudo pip install pyfftw3 then import fftw3
will#will-mint2 ~ $ sudo pip install pyfftw3
[sudo] password for will:
Downloading/unpacking pyfftw3
Downloading PyFFTW3-0.2.1.tar.gz
...
Successfully installed pyfftw3
Cleaning up...
will#will-mint2 ~ $ python
Python 2.7.9 (default, Mar 1 2015, 12:57:24)
[GCC 4.9.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import fftw3
>>> exit()
For windows
http://www.lfd.uci.edu/~gohlke/pythonlibs/#pyfftw
install it by:
pip install [filename].whl
import in your code by
import pyfftw as fftw
Edit: Before you start deleting/modifying installs, please glance over StvnW's answer/summary to make sure you are applying the solution that is appropriate for you.
I've installed python 2.7.5 and pip [edit: mac OSX Mountain Lion.] I've run "pip install praw" in terminal. All good. When I run python and run "import praw" I get:
...$ python
Python 2.7.5 (v2.7.5:ab05e7dd2788, May 13 2013, 13:18:45)
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import praw
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named praw
...same ImportError from a script.
when I install praw I get this:
$ pip install praw
Downloading/unpacking praw
Downloading praw-2.1.10.tar.gz (83kB): 83kB downloaded
Running setup.py egg_info for package praw
Requirement already satisfied (use --upgrade to upgrade): requests>=1.2.0 in
/usr/local/lib/python2.7/site-packages (from praw)
Requirement already satisfied (use --upgrade to upgrade): six in
/usr/local/lib/python2.7/site-packages (from praw)
Requirement already satisfied (use --upgrade to upgrade): update-checker>=0.6 in
/usr/local/lib/python2.7/site-packages (from praw)
Requirement already satisfied (use --upgrade to upgrade): setuptools in
/usr/local/lib/python2.7/site-packages/setuptools-1.1.6-py2.7.egg (from update-
checker>=0.6->praw)
Installing collected packages: praw
Running setup.py install for praw
Installing praw-multiprocess script to /usr/local/bin
Successfully installed praw
Cleaning up...
In python if I run help('modules') it isn't there.
Relatively new to python and I haven't been able to sort this out with google search. Any hints would be much appreciated.
Edit:
SitRep:
I've uninstalled 2.7.2, uninstalled praw, and uninstalled (homebrew) pip. I ran python 2.7.5 and it couldn't find the module (as you would suspect.) I then reinstalled pip with easy_install and now 2.7.5 is finding praw but giving this error:
$ python
Python 2.7.5 (v2.7.5:ab05e7dd2788, May 13 2013, 13:18:45)
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import praw
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Library/Python/2.7/site-packages/praw/__init__.py", line 43, in <module>
from update_checker import update_check
File "/Library/Python/2.7/site-packages/update_checker.py", line 11, in <module>
from pkg_resources import parse_version as V
ImportError: No module named pkg_resources
>>>
Thanks for the help so far, the spurious install was the root of problem 1.
The solution to the final problem can be found here:
No module named pkg_resources
I wish there were some way to summarize this for future readers, but I've done so many things that I no longer recall what addressed what. I basically uninstalled everything (python 2.7.2, 2.7.5, praw, pip,) reinstalled 2.7.5 from http://python.org/download/, reinstalled pip with easy_install (and sudo command) instead of homebrew, reinstalled praw with sudo command, and followed the directions for the subsequent module error in the link above. Hope that helps. :)
The OS X system versions of Python live in /System/Library/Frameworks/Python.Framework/<verson>, each of which links to /Library/Python/<version>/site-packages. Seems like you have installed another version of python and/or pip to /usr/local, but when you invoke python you are still getting the system version.
Try this:
$ /usr/local/bin/python
>>> import praw
I'd also recommend looking into tools like pyenv and virtualenv if you are going to do any amount of work with Python. Pyenv lets you easily manage and switch between multiple versions (including micro versions x.x.3, x.x.5, etc). Virtualenv lets you create isolated Python environments where you can pin down versions of site-packages specific to a particular project.
Edit (summarizing):
sudo easy_install pip will install pip under /System/Library/Python/<version>. Calling that pip will install packages to /Library/Python/<version>/site-packages
brew install python will install a second version of python — including pip — under /usr/local/. That pip will put packages in /usr/local/lib/python<version>/site-packages/`.
One version may not see packages installed to the other.
which python and which pip are helpful for troubleshooting.
Dean's final solution above results in user packages being installed to the system site-packages.
Despite Dean's choice to update the system Python, many would advocate instead using brew, pyenv, and virtualenv to isolate oneself from the system Python.
It's strange. I am suspecting you have another version of python2.7 on your mac os
If you are using a mac. Check the version of python on your shell's path using which python. Then make sure that the shebang line in the script you are trying to run uses the same version of python.
In my terminal I typed
which python and got the output /usr/local/bin/python
I went to the script I was trying to run and added the following to the first line
#!/usr/local/bin/python
Then I went back to my terminal. Checked that I was in the same directory as the script I wanted to run and typed
./my_script.py
If you don't see any output at this point make sure that you have execution permission enabled for your script by typing chmod +x my_script.py in ther terminal. Then try running the script again using ./my_script.py