I have python-2.7.9 installed on my machine and I am trying to install numpy, matplotlib, pyopengl, and pyqt4.
I've installed pyqt4 using the source file and it imports fine when using python, however, i get an error for the remaining packages.... no module named numpy.
I installed numpy and matplotlib using the following commands:
sudo apt-get install python-numpy
sudo apt-get install pyhton-matplotlib
I also tried using pip and aptitude but I still get the same error..im not sure what I am doing wrong or how to fix these issues. Does anyone have any advice?
UPDATE:
Using Ubuntu 14.04.1 LTS
These are the errors I get:
Python 2.7.9 (default, Feb 5 2015, 11:24:57)
[GCC 4.8.2] on linux2
Type "help", "copyright", or "license" for more information.
import numpy
Traceback (most recent call last):
File "", line 1, in
ImportError: Mo module named numpy
In ubuntu 14.04, the packages you want are not called simply numpy and matplotlib. Instead they are python-numpy and python-matplotlib. Thus to install them you need:
sudo apt-get install python-numpy
sudo apt-get install python-matplotlib
EDIT:
Based on the comments below, the issue was a different version of python 2.7than the one provided by Ubuntu. More info in comments. An alias to the ubuntu's python seems to solved the problem.
Related
Note - I already check numpy import error related threads but none helped
I am using debian 8 where default python is 2.7.9. I installed python 3.4.2 and created virutal env.
Within virtual environment -
python -V
Python 3.4.2
pip -V
pip 1.5.6 from /path/venv34/lib/python3.4/site-packages (python 3.4)
I have python3 numpy package - python3-numpy_1.12.0-2~pn0_amd64.deb
which I have installed with sudo dpkg -i python3-numpy_1.12.0-2~pn0_amd64.deb
which successfully completed.
Now when I do
python
Python 3.4.2 (default, Feb 7 2019, 06:08:06)
[GCC 4.9.2] on linux
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'
>>>
Any clue what's wrong here?
python3.4 -m pip install numpy==1.12.0-2
ok since my repo is less than 50 i can not add comments, so take this answer as a comment to your question.
I think numpy is installed but not in your virtualenv, make sure your virtualenv is active when you are trying to install any library, you will see virtualenv name in every command line if it is activated.
(venv) C:\Users\seventeen\sprint25>
Try python -m pip install numpy==1.12.0. This should help you.
+--------+-----------------------------------+
| OS | Ubuntu 12.04 |
+--------+-----------------------------------+
| Python | 2.7, 3.2 and source installed 3.6 |
+--------+-----------------------------------+
Since there are 2 versions of Python 3, anything installed from the repository doesn't work for Python 3.6. The latest version of Python in the repositories is 3.2, so I need source installs or through pip3.6.
After starting python3.6 I tried to import tkinter, which gave the following error. Even though help('modules') returned a list of modules which included tkinter.
import tkinter
ModuleNotFoundError: No module named '_tkinter'
I tried doing the same in python3.2 and there were no errors. tkinter._tkinter gave the location of tkinter library for python3.2
I cd'd into the python3.6 directory which has all library files and indeed it was missing the tkinter.so object file.
How do I fix the error?
I would like to get tkinter/tkagg working as it seems all the modules/ package are already installed.
After googling some more, I found I need to build python3.6 again, but this time with Tcl/Tk options while running configure. I'd rather not. It takes 1hr approx to install python3.6 from scratch.
Is there some other way where I can tell python3.6 where Tcl/Tk is located?
The problem isn't telling python where tcl/tk is. After messing around with python3.6's source code, and then comparing python3.6 with python3.2, I found out that tkinter calls _tkinter which isn't a python file, it's an .so(shared object) file that python builds during installation via setup.py that uses gcc, that somehow may involve distutils.
The new and more appropriate question is how do I build,
_tkinter.cpython-36m-i386-linux-gnu.so from tcl/tk?
Note : I do have tcl/tk installed, which I have confirmed using tclsh and wish.
run from terminal:
sudo apt-get install python3.6-tk
or just reinstall completly:
sudo apt-get install python3.6
Python version 3.6.4 (Ubuntu 18.04 LTS)
sudo add-apt-repository main
sudo apt-get install python3-tk
I faced a similar problem to yours, I am giving the details of it and how I solved it.
On Ubuntu 16.04 LTS, I have Python 3.5.2 and Python 2.7.12 but I would like to experiment Python3.6 (for various reasons like this one, for example). So I relied on this post:
sudo add-apt-repository ppa:deadsnakes/ppa
sudo apt-get update
sudo apt-get install python3.6
When I tried to run a module using tkinter, I got this error message:
Traceback (most recent call last):
File "/usr/lib/python3.6/tkinter/__init__.py", line 37, in <module>
import _tkinter
ModuleNotFoundError: No module named '_tkinter'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "bill.py", line 3, in <module>
from tkinter import Canvas, Label, Tk, StringVar, Button, LEFT
File "/usr/lib/python3.6/tkinter/__init__.py", line 39, in <module>
raise ImportError(str(msg) + ', please install the python3-tk package')
ImportError: No module named '_tkinter', please install the python3-tk package
I tried to install tkinter as the message above asks:
sudo apt-get install python3-tk
[sudo] password for begueradj:
Reading package lists... Done
Building dependency tree
Reading state information... Done
python3-tk is already the newest version (3.5.1-1).
0 upgraded, 0 newly installed, 0 to remove and 8 not upgraded.
Obviously, I still can not use tkinter for Python 3.6. How to fix this problem?
My first blind attempt did not work:
sudo apt-get install python36-tk
Reading package lists... Done
Building dependency tree
Reading state information... Done
E: Unable to locate package python36-tk
The second one works:
sudo apt-get install python3.6-tk
Reading package lists... Done
Building dependency tree
Reading state information... Done
Suggested packages:
tix python3.6-tk-dbg
The following NEW packages will be installed:
python3.6-tk
0 upgraded, 1 newly installed, 0 to remove and 8 not upgraded.
Need to get 74.6 kB of archives.
After this operation, 165 kB of additional disk space will be used.
Get:1 http://ppa.launchpad.net/deadsnakes/ppa/ubuntu xenial/main amd64 python3.6-tk amd64 3.6.5-1+xenial1 [74.6 kB]
Fetched 74.6 kB in 0s (301 kB/s)
Selecting previously unselected package python3.6-tk:amd64.
(Reading database ... 324106 files and directories currently installed.)
Preparing to unpack .../python3.6-tk_3.6.5-1+xenial1_amd64.deb ...
Unpacking python3.6-tk:amd64 (3.6.5-1+xenial1) ...
Setting up python3.6-tk:amd64 (3.6.5-1+xenial1) ...
And that solved my problem:
~/python3.6
Python 3.6.5 (default, Mar 29 2018, 03:28:50)
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import tkinter
>>>
Python version 3.6.4 (Ubuntu 18.04 LTS)
I was having the same error: tkinter module not found. Even after trying to install via pip
$ pip install tkinter
I got this error, below
Collecting tkinter
Could not find a version that satisfies the requirement tkinter (from versions: )
No matching distribution found for tkinter
I did this tried to install tkinter for Python3.6 by running the command. It worked for me.
$ sudo apt-get install python3.6-tk
Installed python3.8.2 on ubuntu 20.04, tried importing tkinter but failed. Got this error:
da0xxx:~/python_trn/pygui$ python3 -m tkinter
/usr/bin/python3: No module named tkinter
but ran:
da0xxx:~/python_trn/pygui$ sudo apt-get install python3-tk
now able to import tkinter!
da0xxx:~/python_trn/pygui$ python3
Python 3.8.2 (default, Apr 27 2020, 15:53:34)
[GCC 9.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
import tkinter as tk
Thanks above!
Try these lines, It might help
os.environ['TCL_LIBRARY'] = r'C:\Users\asus\AppData\Local\Programs\Python\Python36-32\tcl\tcl8.6'
os.environ['TK_LIBRARY'] = r'C:\Users\asus\AppData\Local\Programs\Python\Python36-32\tcl\tk8.6'
Recheck path before executing.
I am attempting to teach myself programming and keep running into problems downloading modules I need for basic tutorials.
My latest attempt has been to get the matplotlib module into my Python 3 environment. I have tried so many different install packages and so many advice I found on the internet that I cannot remember how I originally got the module. But it seemed that everything went well with the installation process.
I am using a Raspberry Pi2 throughout all of this with the Raspbian OS installed.
Python 3.2.3 (default, Mar 1 2013, 11:53:50)
[GCC 4.6.3] on linux2
Type "copyright", "credits" or "license()" for more information.
>>> import matplotlib
Traceback (most recent call last):
File "<pyshell#0>", line 1, in <module>
import matplotlib
ImportError: No module named matplotlib
It may be possible that you actually installed the library for python 2. I would use pip to install the modules that you need. If you don't already have it installed, run this first command in the shell:
sudo apt-get install python3-pip
This program can be called with "pip3" or maybe "pip-3.2" in the shell.
To install mathplotlib with it, try running:
pip3 install matplotlib
or
pip-3.2 install matplotlib
That should install the Python 3 module for you.
I'm trying to use OpenCV from within Python on an system using Ubuntu 14.04. When I try to import cv2, I get the following error:
me#Bedrock1:~$ python
Python 2.7.6 (default, Mar 22 2014, 22:59:56)
[GCC 4.8.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import cv2
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: libavcodec.so.53: cannot open shared object file: No such file or directory
A search for libavcodec.so.53 reveals that my system has only libavcodec.so.54.
A search of the internet reveals that libavcodec.so.53 has been removed from the 14.04 repository (http://www.ubuntuupdates.org/package/core/trusty/universe/base/libavcodec53). This, probably, explains my inability to apt-get install this library:
me#Bedrock1:~$ sudo apt-get install libavcodec53 libavcodec-extra-53
...
E: Package 'libavcodec53' has no installation candidate
E: Package 'libavcodec-extra-53' has no installation candidate
Unfortunately, now I'm truly stuck.
Is there a way to get the cv2 module to use libavcodec.so.54, or a way to find & install libavcodec.so.53?
NOTE: I just tried reinstalling by following the instructions at https://help.ubuntu.com/community/OpenCV
but I still am getting the same libavcodec.so.53 error....
Try this script. Ubuntu man page has an old version of this script. This should work.
https://github.com/jayrambhia/Install-OpenCV/blob/master/Ubuntu/2.4/opencv2_4_9.sh
Check if reinstalling opencv resolves the issue
sudo apt-get install --reinstall python-opencv
BTW how did you install it before ?
I got the same problem on Ubuntu 14.04 64bit, as reported here:
https://bugs.launchpad.net/ubuntu/+source/opencv/+bug/1161485/comments/2
I tried downloading the source package and recompiling, in order to get the correct libraries linked, but with no luck.
At the end, I recompiled from source, following these instructions:
http://docs.opencv.org/doc/tutorials/introduction/linux_install/linux_install.html
Everything goes fine except for the python module compilation, which was disable at configure time (listed in Opencv modules: Unavailable: section).
I used cmake-gui to configure the build and generate makefiles. The configuration step was correctly setting PYTHON2_INCLUDE_DIR, PYTHON2_INCLUDE_DIR2 and PYTHON2_LIBRARY, but it was NOT setting PYTHON_INCLUDE_DIR, PYTHON_INCLUDE_DIR2 and PYTHON_LIBRARY.
In order to actually build the python module, you should set these PYTHON_ variables equal to their corresponding PYTHON2_ variables. Then, the make step will build also cv2.so.
I'm reading the book Introduction to Computer Science Using Python and Pygame by Paul Craven (note: legally available for free online). In the book, he uses a combination of Python 3.1.3 and Pygame 1.9.1 . In my Linux Ubuntu machine, I have Python 3.1.2 but even after I sudo apt-get installed python-pygame (version 1.9.1), Python 3.1.2 can't import pygame.
Python 3.1.2 (r312:79147, Sep 27 2010, 09:45:41)
[GCC 4.4.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import pygame
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named pygame
Python 2.6.5 imports it without fuss, however,
Python 2.6.5 (r265:79063, Apr 16 2010, 13:09:56)
[GCC 4.4.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import pygame
>>>
Are you aware of any issues for Linux/Ubuntu's Python 3.1.2 (Prof. Craven used Windows in his book)? How come Pygame 1.9.1 worked for Python 3.1.3 but not for 3.1.2?
Thanks for any pointers. (--,)
PyGame on Python 3 remains experimental, but these steps worked for me on Ubuntu 11.10:
sudo apt-get install mercurial python3-dev libjpeg-dev libpng12-dev libportmidi-dev libsdl-image1.2-dev libsdl-mixer1.2-dev libsdl-ttf2.0-dev libsdl1.2-dev libsmpeg-dev libx11-dev ttf-freefont libavformat-dev libswscale-dev
hg clone -u 01b2cb16dc17 https://bitbucket.org/pygame/pygame
cd pygame
python3 config.py
2to3 setup.py -w
python3 setup.py build
sudo python3 setup.py install
(You may remove the -u 01b2cb16dc17 to try the latest version; 01b2cb16dc17 worked for me.)
I hate to re-open an old post, but I had the hardest time installing pygame with a version of python that was not Ubuntu's default build. So I created this tutorial/ how to:
Install python3.1 and pygame1.9.1 in Ubuntu
I hopes this helps the next unfortunate soul to try this.
I installed pygame for python3 quite easily using the pip3 (a tool for installing and managing Python packages) command on Ubuntu 16.04.7 LTS.
Open a terminal and install pip3, type sudo apt install python3-pip
Now use it to install pygame for python3, type pip3 install pygame
That's it! Import the library and confirm that everything works:
# I'll try it out using the python 3 interpreter.
python3 --version
Python 3.5.2
robert#robert-E7212:~/Source/Python/python_crash_course/alien_invasion$ python3
Python 3.5.2 (default, Oct 7 2020, 17:19:02)
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
# No errors, pygame was imported successfully!
>>> import pygame
pygame 2.0.0 (SDL 2.0.12, python 3.5.2)
Hello from the pygame community. https://www.pygame.org/contribute.html
>>>
I followed #Søren 's method, but without the -u number.
The only complication was a few compilation errors at the last line, all due to syntax and unicode differences between Python 2 and Python 3, but with a little checking of the web documentation it was a matter of a few minutes with a text editor modifying the following files (all paths are relative to the pygame directory created during the download):
gedit build/lib.linux-x86_64-3.2/pygame/colordict.py
gedit build/lib.linux-x86_64-3.2/pygame/tests/test-utils/png.py
gedit build/lib.linux-x86_64-3.2/pygame/examples/movieplayer.py
The line numbers from the compiler error messages are great for giving you where to start. The things to look out for are:
1 remove all references to u"xxxx" colours
2 use Python3 syntax for exceptions
3 change all print commands to Python3 equivalents
Then re-issue the final compilation command:
sudo python3 setup.py install
If you miss one or two or get it wrong, just keep going round the loop editing and re-compiling till it works.
BTW I deliberately did not give details of the compiler messages, because I expect they will depend on the current build you download. The files I needed to change were for version '1.9.2pre' downloaded as of the date on this post.
Just use the below command to install pygame for Python3. I could install pygame correctly on Ubuntu 16.04 and Python Python 3.5.2.
pip3 install pygame
It's because installing the python-pygame package installs it for the default version of Python on your system, 2.6.5 in this case. You should download the pygame package and use setup.py to install it in 3.1.2.
The python-pygame package is only compiled for python2.6 and python2.7 where I am. You'll have to install it again, possibly from a python3 branch of the source.