Python modules not installing - python-2.7

I had some code that was running just fine, and over the course of the day, I broke something, and now I cannot install any python modules. Specifically, I need numpy, matplotlib, and pillow. I cannot install any of them.
But the weird part is that they both appear to install just fine:
$ sudo pip install numpy
Collecting numpy
Downloading numpy-1.11.0-cp27-cp27mu-manylinux1_x86_64.whl (15.3MB)
100% |████████████████████████████████| 15.3MB 94kB/s
Installing collected packages: numpy
Successfully installed numpy-1.11.0
Or when I try:
$ sudo apt-get install python-numpy
Reading package lists... Done
Building dependency tree
Reading state information... Done
Suggested packages:
python-nose python-numpy-dbg python-numpy-doc
The following NEW packages will be installed:
python-numpy
0 upgraded, 1 newly installed, 0 to remove and 20 not upgraded.
Need to get 0 B/1,763 kB of archives.
After this operation, 9,598 kB of additional disk space will be used.
Selecting previously unselected package python-numpy.
(Reading database ... 221259 files and directories currently installed.)
Preparing to unpack .../python-numpy_1%3a1.11.0-1ubuntu1_amd64.deb ...
Unpacking python-numpy (1:1.11.0-1ubuntu1) ...
Processing triggers for man-db (2.7.5-1) ...
Setting up python-numpy (1:1.11.0-1ubuntu1) ...
I am using python 2.7, and I am on Ubuntu 16.04.
$ python
Python 2.7.5 (default, May 12 2016, 13:11:58)
[GCC 5.3.1 20160413] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import numpy
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named numpy
>>>
It does this for any module I try and install. Any help would be greatly appreciated.

This is a result of the default python and the default pip not matching up. To ensure that packages are being installed to the correct location, use:
python -m pip install $PACKAGE
This results in running the pip assigned to the desired python rather than the first one found in your path.

Related

python - pip installs but cannot import

I've read a lot of posts about this but none of the solutions have worked for me. I'm trying to get a module called nsxramlclient installed, shows successful installation with pip but cannot import from any location outside of the /Users/Nathan/Library/Python/2.7/lib/python/site-packages.
Uninstall does work after some fidgeting with brew using the recommendations found with brew doctor. Here are some vitals:
Running OSX python 2.7.10
PIP 18.1
which -a pip = /usr/local/bin/pip
which -a python = shows 2 directories:
/usr/local/bin/python
/usr/bin/python
python -c 'import sys; print(sys.path)'
['', '/usr/local/Cellar/python#2/2.7.15_1/Frameworks/Python.framework/Versions/2.7/lib/python27.zip', '/usr/local/Cellar/python#2/2.7.15_1/Frameworks/Python.framework/Versions/2.7/lib/python2.7', '/usr/local/Cellar/python#2/2.7.15_1/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-darwin', '/usr/local/Cellar/python#2/2.7.15_1/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac', '/usr/local/Cellar/python#2/2.7.15_1/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac/lib-scriptpackages', '/usr/local/Cellar/python#2/2.7.15_1/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk', '/usr/local/Cellar/python#2/2.7.15_1/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-old', '/usr/local/Cellar/python#2/2.7.15_1/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload']
pip list | grep nsxramlclient
nsxramlclient 2.0.7
It has to be a path issue since I'm able to import it from the directory that the module is located. I just don't know the proper method to repair this since I'm fairly new to Python and I don't want to mess it up worse that it is already.
Looks like I did end up getting it to work finally. What I had to do was to re-install python with brew:
brew re-install python#2
then I needed to re-install the modules I needed with pip. Having OTHER issues now but at least this one is fixed.

PIL.ImageTk import and/or installation error

When I get to my beloved Spyder console and it welcomes me with
Python 2.7.12 (default, Dec 4 2017, 14:50:18)
Type "copyright", "credits" or "license" for more information.
IPython 2.4.1 -- An enhanced Interactive Python.
? -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help -> Python's own help system.
object? -> Details about 'object', use 'object??' for extra details.
%guiref -> A brief reference about the graphical user interface.
I go on and type this:
In [1]: from PIL import Image
And it goes and shows another line like everything was right.
Then, on the next line, I type this:
In [2]: from PIL import ImageTk
And it returns this:
Traceback (most recent call last):
File "<ipython-input-2-47edf18ebb7f>", line 1, in <module>
from PIL import ImageTk
ImportError: cannot import name ImageTk
Okay, this means I should have a problem with my libraries. No sweat.
A fellow programmer had a similar error here, and:
I am sure there are no typos in my import
Ubuntu reports the python-imaging package as up-to-date:
Ubuntu reports the following on the python-imaging-tk package:
These Bash lines:
python-imaging is already the newest version (3.1.2-0ubuntu1.1).
<more bash lines />
The following packages have unmet dependencies:
python-imaging-tk : Depends: python-imaging (= 1.1.7-4) but 3.1.2-0ubuntu1.1 is to be installed
This is the juiciest part. When I go back to Spyder and type to get the version of PIL.Image, it returns this:
In [3]: Image.VERSION
Out[3]: '1.1.7'
I am at a loss here. Please send help.
Doing a
sudo apt-get install python-imaging=1.1.7-4
and then
sudo apt-get install python-imaging-tk
solved the problem.
It still bothers me why but at least my dependencies are working now.
sudo apt-get install python-imaging-tk
this just solved my problem. This is for python 2.7

nltk module installation in pip through cmd

When I tried to run this command:
c:\python27\scripts\pip install nltk-3.2.1-py2.py3-none-any
I am getting the error:
no matching distribution found
Although i have installed nltk from
http://www.lfd.uci.edu/~gohlke/pythonlibs/#nltk
Kindly help.
I am working on Windows 8 64-bit Version
Installing new modules can be a nightmare if you are new to Python.First delete any old versions of NLTK if already installed. Open cmd navigate to C:\Users\user\AppData\Local\Programs\Python\Python35-32\Scripts, the default directory, using the command cd path_name_comes_here. Otherwise goto the path where you have installed python and goto the Scripts subfolder and use this path here onwards. Now the most preferred way is to use pip install module_you_want_to_install for anything in python. Pip automatically fetches everything it needs to install said module.
Simply use pip install nltk.
Another method is to use easy_install requirement_or_URL.
Some rare occasions its best to download the wheel from http://www.lfd.uci.edu/~gohlke/pythonlibs and from there you can simply use pip install downloaded_wheel_name again. But make sure to copy the name of the wheel EXACTLY.
Post installation make sure that your package is accessible from C:\Users\user\AppData\Local\Programs\Python\Python35-32\Lib\site-packages or a similar path depending on where you installed python.
Try Anaconda - Instead . Always works
C:\Users\sanan>conda install -c anaconda nltk
Fetching package metadata .............
Solving package specifications: .
Package plan for installation in environment C:\Users\sanan\Miniconda3:
The following NEW packages will be INSTALLED:
nltk: 3.2.4-py36_0 anaconda
The following packages will be UPDATED:
conda: 4.3.23-py36_0 --> 4.3.25-py36_0 anaconda
The following packages will be SUPERSEDED by a higher-priority channel:
conda-env: 2.6.0-0 --> 2.6.0-0 anaconda
Proceed ([y]/n)? y
conda-env-2.6. 100% |###############################| Time: 0:00:00 22.84 kB/s
nltk-3.2.4-py3 100% |###############################| Time: 0:00:02 774.24 kB/s
conda-4.3.25-p 100% |###############################| Time: 0:00:00 578.90 kB/s
After installation is complete .
import nltk
print(nltk.__version__)
C:\Public\Code\textnorm>python attempt1.py
3.2.4

AttributeError with pip install matplotlib

I am attempting to install matplotlib with pip inside a virtualenv on Ubuntu Linux. I already have a bunch of packages installed successfully - this is the one that's failing. As the output indicates, This is python 2.7.3 and all of the dependencies are already present.
Is this specific to v1.4.3 of matplotlib? Should I perhaps install an earlier version? I've even manually installed mock (v1.3.0), since the install seems to fail on trying to import it, but that didn't help either.
Here is the output:
Collecting matplotlib
Using cached matplotlib-1.4.3.tar.gz
Complete output from command python setup.py egg_info:
============================================================================
Edit setup.cfg to change the build options
BUILDING MATPLOTLIB
matplotlib: yes [1.4.3]
python: yes [2.7.3 (default, Jun 22 2015, 19:33:41) [GCC
4.6.3]]
platform: yes [linux2]
REQUIRED DEPENDENCIES AND EXTENSIONS
numpy: yes [version 1.9.2]
six: yes [using six version 1.9.0]
dateutil: yes [using dateutil version 2.4.2]
pytz: yes [using pytz version 2015.4]
tornado: yes [tornado was not found. It is required for the
WebAgg backend. pip/easy_install may attempt to
install it after matplotlib.]
pyparsing: yes [using pyparsing version 2.0.3]
pycxx: yes [Couldn't import. Using local copy.]
libagg: yes [pkg-config information for 'libagg' could not
be found. Using local copy.]
freetype: yes [version 2.4.8]
png: yes [version 1.2.46]
qhull: yes [pkg-config information for 'qhull' could not be
found. Using local copy.]
OPTIONAL SUBPACKAGES
sample_data: yes [installing]
toolkits: yes [installing]
Traceback (most recent call last):
File "<string>", line 20, in <module>
File "/tmp/pip-build-mHyI6G/matplotlib/setup.py", line 155, in <module>
result = package.check()
File "setupext.py", line 666, in check
import mock
File "/home/awarnock/PyProjects/OMTO3dIMG/local/lib/python2.7/site-packages/mock/__init__.py", line 2, in <module>
import mock.mock as _mock
File "/home/awarnock/PyProjects/OMTO3dIMG/local/lib/python2.7/site-packages/mock/mock.py", line 71, in <module>
_v = VersionInfo('mock').semantic_version()
AttributeError: 'VersionInfo' object has no attribute 'semantic_version'
----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /tmp/pip- build-mHyI6G/matplotlib
Thanks in advance for any suggestions.
You can try with:
pip install oslo.utils
Or:
pip install testrepository
pip install oslo.utils
You can also install it with packages:
Debian / Ubuntu:
apt-get install python-matplotlib
Redhat / CentOS:
yum install python-matplotlib

Python 2.7.4 on Ubuntu 10.04, Import readline error(Tried many ways never work)

As in the title, my system version is Ubuntu 10.04. The default version of Python is 2.6.5.
When I start python2.6 in command line and
import readline
This works well.
Then I compile the python 2.7.4 (Downloaded from www.python.org/getit). Nightmare began.
Here is how I installed Python 2.7.4:
./configure --prefix=/usr
make
su root
make install
Then tried import readline:
Python 2.7.4 (default, Apr 11 2013, 11:17:09)
[GCC 4.4.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import readline
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named readline
Googled, firstly what I did is
sudo apt-get install libreadline5-dev
sudo ldconfig
Reinstall, does not work.
Then tried to install libpython and reinstall python 2.7.4, still does not work.
But the strange thing is that at the last few lines of command "make", the information is like this:
Python build finished, but the necessary bits to build these modules were not found:
_bsddb _sqlite3 bsddb185
bz2 dbm gdbm
sunaudiodev
To find the necessary bits, look in setup.py in detect_modules() for the module's name.
Seems there is no readline, but it just does not work!
BTW, here is another information might help:
/usr/bin/python -c "import readline; print readline.__doc__"
Importing this module enables command line editing using GNU readline.
Anyone can help me for this...
Thank you in advance.
I tried again, installed these packets:
sudo apt-get install build-essential
sudo apt-get install libreadline5-dev libncursesw5-dev libssl-dev libsqlite3-dev tk-dev libgdbm-dev libc6-dev libbz2-dev
Then remove everything about python2.7 including in /usr/local/bin, /usr/bin, etc and reinstall.
This time it works...
Ok...Hope this will help people who has the same problem with me.