abhigenie92#ubuntu:~/Desktop/pygame-1.9.1release$ which python
/home/abhigenie92/anaconda/bin/python
abhigenie92#ubuntu:~/Desktop/pygame-1.9.1release$ sudo apt-get install python-pygame
Reading package lists... Done
Building dependency tree
Reading state information... Done
python-pygame is already the newest version.
0 upgraded, 0 newly installed, 0 to remove and 224 not upgraded.
abhigenie92#ubuntu:~/Desktop/pygame-1.9.1release$ python
Python 2.7.10 |Anaconda 2.3.0 (64-bit)| (default, May 28 2015, 17:02:03)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-1)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
Anaconda is brought to you by Continuum Analytics.
Please check out: http://continuum.io/thanks and https://binstar.org
>>> import pygame
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named pygame
What is happening above? It seems to not install for anaconda. But it is directing to the right from path.
You are installing things into the system Python. You need to install into the Anaconda Python, using pip install pygame (note that sudo pip is likely going to use the system Python again, and using sudo with the Anaconda Python is not recommended anyway).
Related
When I type in which python I get /usr/bin/python as expected. However, I wanted to install matplotlib and running sudo apt-get install python-matplotlib says
Reading package lists... Done
Building dependency tree
Reading state information... Done
python-matplotlib is already the newest version.
0 upgraded, 0 newly installed, 0 to remove and 1 not upgraded.
Fair enough, I thought that the library was installed, but when I tried to import it I got an error:
[ivaylo#ivaylo-K55VD ~]$ python
Python 2.7.9 (default, Apr 24 2015, 12:56:53)
[GCC 4.8.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import matplotlib
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named matplotlib
>>>
So it turns out I have matplotlib installed for my default implementation, yet it cannot be found. I checked the contents of /usr/bin/ and there are multiple python executables:
python refers to, as you can see, version 2.7.9 and is the only version where matplotlib is not available.
python2 python2.7 and python2.7.6 all map to version 2.7.6 and there the library is available.
python3 and python3.4 map to version 3.4.3 where matplotlib is also available, but only after I installed it with sudo apt-get install python3-matplotlib.
So my question is, why is the default python 2.7.9 and why doesn't apt install the library for the correct version?
My Ubuntu is 14.04 if that matters.
I've installed OpenCV in Ubuntu through sudo apt-get install libopencv-dev and then pip install python-opencv in Anaconda, but if I try to import the cv2 module I get error:
Python 2.7.11 |Anaconda 4.0.0 (64-bit)| (default, Dec 6 2015, 18:08:32)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-1)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
Anaconda is brought to you by Continuum Analytics.
Please check out: http://continuum.io/thanks and https://anaconda.org
>>> import cv2
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named cv2
>>>
How can I make it work?
If you want to install OpenCV in Anaconda, you must use 'conda' command in the terminal.
I have answered a similar question and you can follow this link below for detailed instruction on how to install it on Anaconda. Here is the link where I answered it:
Installing opencv 3.1 with anaconda python3?
This is command that I used to install it. Note that you must have an internet connection for this to work.
conda install -c menpo opencv3
The above command will install the latest version of OpenCV which is 3.10.
I hope that helped you =)
I have installed a python library MySQLdb, and it works yesterday. But today when I tried to run it, it goes on as following:
czhao#opx790:~$ python
Python 2.7.7 |Anaconda 2.0.1 (64-bit)| (default, Jun 2 2014, 12:34:02)
[GCC 4.1.2 20080704 (Red Hat 4.1.2-54)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
Anaconda is brought to you by Continuum Analytics.
Please check out: http://continuum.io/thanks and https://binstar.org
>>> import MySQLdb
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named MySQLdb
It is really strange, so I try to re-install it, but it seems I do have the library in my computer:
czhao#opx790:~$ sudo apt-get install python-mysqldb
[sudo] password for czhao:
Reading package lists... Done
Building dependency tree
Reading state information... Done
python-mysqldb is already the newest version.
The following packages were automatically installed and are no longer required:
libgooglepinyin0-dev linux-headers-3.2.0-27 linux-headers-3.2.0-41
linux-headers-3.2.0-37 linux-headers-3.2.0-43 linux-headers-3.2.0-61
patchutils linux-headers-3.2.0-37-generic linux-headers-3.2.0-27-generic
linux-headers-3.2.0-61-generic linux-headers-3.2.0-43-generic dpatch
linux-headers-3.2.0-41-generic
Use 'apt-get autoremove' to remove them.
0 upgraded, 0 newly installed, 0 to remove and 16 not upgraded.
I do not know why, I have the library but python keep tell me I do not have it.
You are using Anaconda Python, but the package installed with apt-get was installed for the system Python. These two different distributions have different library directories, so packages/modules installed with one are not available for the other.
To get around this, use the pip program that came with Anaconda and run sudo pip install MySQL-python.
I have two versions of Python installed on my centOS server.
[ethan#demo ~]$ python2.6 --version
Python 2.6.6
[ehtan#demo ~]$ python --version
Python 2.7.3
The older version (2.6) is required by some essential centOS packages so I can't remove it.
When I install packages using pip, they are being installed in Python 2.6. But instead I want them to be installed to Python 2.7.
How can I change this behaviour?
For example, here is what happened when I tried installing Wand
[ethan#demo ~]$ pip install Wand
Requirement already satisfied (use --upgrade to upgrade): Wand in /usr/lib/python2.6/site-packages
Cleaning up...
[ethan#demo ~]$ python2.6
Python 2.6.6 (r266:84292, Jul 10 2013, 22:48:45)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-3)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import wand
>>> exit()
[ethan#demo ~]$ python
Python 2.7.3 (default, Oct 11 2013, 15:59:28)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-3)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import wand
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named wand
>>> exit()
Edit
I found this answer but it didn't work for me https://stackoverflow.com/a/4910393/3384340
You need to install pip for each python version separately.
In order to install pip for Python2.7, run
sudo easy_install-2.7 pip
Use pip-2.7 to install Wand
sudo pip-2.7 install Wand
I thought I'd move from using Tkinter to wxPython, but I'm having some troubles. All I get is this:
>>> import wx
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named wx
I have installed wxPython. When I run the uninstaller I clearly see that wxPython IS installed:
1. wxPython3.0-osx-cocoa-py2.7 3.0.0.0
Enter the number of the install to examine or 'Q' to quit:
When I start Python I see that my version should match the version of wxPython:
Python 2.7.1 (r271:86832, Jul 31 2011, 19:30:53)
[GCC 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2335.15.00)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
I'm on OS X 10.7.5 32-bit.
Any help would be awesome! :)
Macs can have multiple versions of Python installed. Are you sure that you installed wxPython for the same python you invoke with the interpreter?
Try, which python, and make sure that this version of python has a wxredirect.pth file in site-packages pointing to the wxPython installation. (If it doesn't search for wxredirect.pth.)
Here's one version on my system...
> which python2.6
/Library/Frameworks/Python.framework/Versions/2.6/bin/python2.6
> more /Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/wxredirect.pth
import site; site.addsitedir('/usr/local/lib/wxPython-3.0.0.0/lib/python2.6')
#import site; site.addsitedir('/usr/local/lib/wxPython-2.9.1.1/lib/python2.6')
#import site; site.addsitedir('/usr/local/lib/wxPython-unicode-2.8.12.1/lib/python2.6')
Here, btw, I can comment out lines in the wxredirect.pth to choose the version of wxPython I want to use.
I just find the same problem.
I used brew install wxpython to install it on mac.
I try the method above but no use.
I happen to find the solution when I install another package, it showen below:
brew install tbb
Downloading https://homebrew.bintray.com/bottles/tbb-2017_U7.sierra.bottle.t
############################################################ 100.0%
==> Pouring tbb-2017_U7.sierra.bottle.tar.gz
==> Caveats
Python modules have been installed and Homebrew's site-packages is not
in your Python sys.path, so you will not be able to import the modules
this formula installed. If you plan to develop with these modules,
please run:
mkdir -p /Users/ningrongye/.local/lib/python2.7/site-packages
echo 'import site; site.addsitedir("/usr/local/lib/python2.7/site-
packages")' >> /Users/ningrongye/.local/lib/python2.7/site-
packages/homebrew.pth`
this is what homebrew said and I just try those, and it works.
ningrong
I have Python 2.7 and 3.7 .
In /usr/local/bin/ there are symbolic links for 2.7 and 3.7 Python versions and also symbolic links for pip.
I've installed wxPython with pip3
pip3 install -U wxPython
Then i checked the installation for Python3
myname$ python3
Python 3.7.2 (v3.7.2:9a3ffc0492, Dec 24 2018, 02:44:43)
[Clang 6.0 (clang-600.0.57)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import wx
>>> wx.version()
'4.0.4 osx-cocoa (phoenix) wxWidgets 3.0.5'
Antonio
In my case it worked by resetting the brew environment to 2.7:
brew link --overwrite python#2