0

In the terminal, after I enter the python interpreter I use help('modules') to see which modules are installed but Numpy, matplotlib and scipy are not listed.

When I try to import them, I get the following:

ImportError: no module named xxx.

However, when I try to install these modules using apt-get install xxx I get a message saying:

python-xxx is already the newest version.

Is it possible I somehow have two versions of python one with matplotlib, the other without it? Could this be linked to a separate problem I'm having with Spyder where the interpreter no longer works? See here.

I am using python 2.7. When I run which python I get: /usr/local/bin/python.

When I run /usr/bin/local/python I get:

Python 2.7.9 (default, Mar 18 2016, 20:34:01) 
[GCC 4.8.4] on linux2

When I run dpkg -l spyder I get:

Desired=Unknown/Install/Remove/Purge/Hold
| Status=Not/Inst/Conf-files/Unpacked/halF-conf/Half-inst/trig-   aWait/Trig-pend
|/ Err?=(none)/Reinst-required (Status,Err: uppercase=bad)
||/ Name           Version      Architecture Description
+++-==============-============-============-    =================================
ii  spyder         2.3.0+dfsg-4 all          python IDE for scientists (Python
Community
  • 1
  • 1
TaxpayersMoney
  • 669
  • 1
  • 8
  • 26
  • 2
    `/usr/local/bin/python.` is not the default python. Try `/usr/bin/python` from the command line and then try to `import matplotlib` etc. If this works you may want to understand who installed the interpreter in `/usr/local/bin`. – gboffi Mar 21 '16 at 22:13
  • The '/usr/local/bin' version has the modules I want installed. How do I delete the other version? I tried 'sudo apt-get remove /usr/local/bin/python' but got the message: 'Unable to locate package /usr/local/bin'. – TaxpayersMoney Mar 22 '16 at 09:55
  • I don't understand. You have (at least) two different Python interpreters in your system (1) the system default, in `/usr/bin/python`, that according to your reports of `apt-get` output can access the `numpy` etc modules and (2) another interpreter, in `/usr/local/bin`, this one was NOT installed using `apt-get` (this implies that you cannot remove it using `apt-get`) and that, according to your initial report, does NOT access `numpy` etc. Now in your comment you tell that (2) has the modules, contradicting what you told us in the Q... Who installed (2)? which tools did they use? – gboffi Mar 22 '16 at 11:24
  • All errors are mine. I mistyped in the previous comment, apologies. I had an error with Spyder that I tried to correct by reinstalling python, which seems to have put another version of python. The version that has numpy and matplotlib is 2.7.6 and stored at /usr/bin/python, the version that does not have them is 2.7.9 and stored at /usr/local/bin. I have tried to install pandas to the 2.7.6 version, but have no luck. I do not remember how I installed the second version of python. I am just an idiot blindly following instructions getting myself deeper and deeper in the mire. – TaxpayersMoney Mar 22 '16 at 11:30
  • 1. please don't throw you down, especially for computer related stuff. 2. when you run simply `python` from the command line, you'll see that the interpreter introduces itself with one or more lines like `Python 2.7.11+ (default, Feb 22 2016, 16:38:42` + `[GCC 5.3.1 20160220] on linux2`, or for a different version on my system `Python 3.5.1 |Continuum Analytics, Inc.| (default, Dec 7 2015, 11:16:01` + `[GCC 4.4.7 20120313 (Red Hat 4.4.7-1)] on linux`. Could you please edit your question to add the info printed by `/usr/local/bin/python`. Another q., report the output of `dpkg -l spyder` – gboffi Mar 22 '16 at 12:06
  • Done, see edit in original question. – TaxpayersMoney Mar 22 '16 at 12:56
  • It seems to me that last Friday, March 18th, an user of your computer compiled from source and installed an up to date version of Python. You can uninstall it as well **going to the source directory** and typing `make uninstall` or, maybe, `sudo make uninstall`. Another possibility is that this new python was installed using a special repository, in this case `dpkg -S /usr/local/bin/python` will show you the name of the package to remove. – gboffi Mar 22 '16 at 17:58
  • Thanks for your help. The `make uninstall` resulted in `make: *** No rule to make target uninstall'. Stop.` The `dpkg -S /usr/local/bin/python` resulted in `dpkg-query: no path found matching pattern /usr/local/bin/python` – TaxpayersMoney Mar 22 '16 at 20:52
  • As a side note, I have now installed pycharm-community, and have found a way to point that to the version of python with matplotlib etc installed. No idea how I managed to bork Spyder, but at least I have a work around for the time being. And I guess having an additional version of python hanging around is not going to kill me. – TaxpayersMoney Mar 22 '16 at 21:10
  • From `dpkg` output you can tell that it was not installed using `apt`. I made an informed guess about `make uninstall` but it turns out that it won't work for Python... that;s life... [Here you can find instructions](http://stackoverflow.com/questions/3544378/uninstall-python-built-from-source) about what you can do next. Ciao. – gboffi Mar 22 '16 at 21:14

2 Answers2

0

Try

pip install <package-name>

(or /usr/local/bin/pip install matplotlib) For example, pip install matplotlib

a_sarana
  • 512
  • 3
  • 13
  • But this depends how the PATH is setup. `/usr/bin/pip` is different than `/usr/local/bin/pip` – OneCricketeer Mar 21 '16 at 22:23
  • I get the error message 'No such file or directory.' when I try to pip install to /usr/bin/python which seems to be my original version of python. – TaxpayersMoney Mar 22 '16 at 11:13
  • Maybe, you haven't pip installed for this python. Did you do this? sudo apt-get install python-pip python-dev build-essential sudo pip install --upgrade pip sudo pip install --upgrade virtualenv – a_sarana Mar 22 '16 at 13:36
0

This error might because you have multiple versions of python installed on your system. For example another version of Python is installed in an Anaconda app.

Bhargav Rao
  • 50,140
  • 28
  • 121
  • 140