I've upgraded to Python 2.7 from Python 2.6 on Ubuntu Maverick Meerkat (10.10) and I'm unable to import PyQt4.
austin#gerald:~$ python2.7
Python 2.7.0+ (r27:82500, Sep 15 2010, 18:04:55)
[GCC 4.4.5] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import PyQt4
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named PyQt4
I installed both Python 2.7 (python2.7) and PyQt4 (python-qt4) from the Ubuntu repositories. I installed PyQt a while back, but I installed Python 2.7 recently.
If I try Python 2.6 (since it's shipped with Ubuntu, the command is simply python), it works perfectly. Watch:
austin#gerald:~$ python
Python 2.6.6 (r266:84292, Sep 15 2010, 15:52:39)
[GCC 4.4.5] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import PyQt4
I know what the problem is: the PyQt4 modules are accessible by Python 2.6 but not 2.7. My question is, how do I get Python 2.7 to find the PyQt4 module(s)? Help!
Note: sorry if this belongs in Super User, I was just programming when I encountered this problem.
As PyQt is not using setup.py it cannot be installed using pip or easy_install
Here you have a tutorial showing how to build and install PyQt for python2.7:
http://problemssol.blogspot.com/2010/12/compile-and-install-pyqt4-for-python27.html
Update:
For Ubuntu 12.04+ just use apt-get:
apt-get install python-qt4
Under Ubuntu system, you could install it via apt-get
apt-get install python-qt4
OSX 10.8.2 tested:
sudo pip install SIP
got IOError: [Errno 2] No such file or directory: '/tmp/pip-build/SIP/setup.py'
It's ok then:
cd /tmp/pip-build/SIP
sudo python configure.py
make
sudo make install
download PyQt from: http://sourceforge.net/projects/pyqt/files/PyQt4/PyQt-4.9.6/PyQt-mac-gpl-4.9.6.tar.gz
unzip it.
cd PyQt-mac-gpl-4.9.6
sudo python configure.py
make
it will take a while, after make then:
sudo make install
Enjoy it :)
You can download any version of PyQt4 here for any version of Python but since you asked for python 2.7, Here is the link for the download for python 2.7:
https://sourceforge.net/projects/pyqt/files/PyQt4/PyQt-4.11.4/
You should install PyQt4 in the Python 2.7 environment. To do this run
easy_install2.7 PyQt4
If easy_install is not installed you will need to first download and install it by running
python2.7 setup.py install
Please install SIP module first,this is python and c/c++ lib tools, and PyQt4 lib
Related
I have this issue. I think it's best described when I show you my bash commands that I used to produce the problem. See here:
josch#oogway:~$ python
Python 2.7.9 (default, Jun 29 2016, 13:08:31)
[GCC 4.9.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import matplotlib
>>> #works
josch#oogway:~$ python3.5
Python 3.5.0 (default, Apr 26 2017, 21:03:53)
[GCC 4.9.2] on linux
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'
>>> #what??
Matplotlib was installed by:
sudo apt-get install python-matplotlib
The "default" python came with my OS installation, python3.5 was downloaded and then compiled/installed from source.
Can anyone help? Tried to solve it myselve for 2 hours now but google can't find answer
Edit: I'm trying to install a "second pip" that works with my second installation of Python, which is Python3.5. My default-Python that is managed by the OS is Python 2.7.9. Now, as suggested I did:
joschua#oogway:~/Downloads$ wget https://bootstrap.pypa.io/get-pip.py
and then:
python3.5 get-pip.py
which gave me:
joschua#oogway:~/Downloads$ python3.5 get-pip.py
Traceback (most recent call last):
File "get-pip.py", line 20061, in <module>
main()
File "get-pip.py", line 194, in main
bootstrap(tmpdir=tmpdir)
File "get-pip.py", line 82, in bootstrap
import pip
zipimport.ZipImportError: can't decompress data; zlib not available
Try installing pip3 with:
sudo apt-get install python3-pip
and then try installing matplotlib with:
sudo pip3 install matplotlib
I actually could solve the problem now.
See this link for a reasonable description on how to run two different versions of python on the same system (and as #Pierre de Buyl suggested) use two different pip versions on the same system
https://www.linkedin.com/pulse/20140815081557-89781742-how-to-install-and-use-python-with-different-versions-on-same-linux-machine
So, you installed python3.5 from source. What version of Debian are you using? (I suppose Jessie).
If you want to install packages for this Python interpreter, you must have a pip that actually uses it. Two solutions:
It is installed. If so,
python3.5 -m pip
will work and you can install packages with
python3.5 -m pip install matplotlib
or
python3.5 -m pip install --user matplotlib
It is not installed. You must install it following the instructions at https://packaging.python.org/installing/#requirements-for-installing-packages
apt-get will not install the appropriate pip for your needs. It will only install a pip that is related to the python3 (3.4 for jessie I believe) that is also in the apt-get system.
EDIT: in light of the update, you need also to re-compile python3.5 with zip enabled.
First let me start by giving an example of what happens when I install numpy using HomeBrew
brew install numpy
This successfully dowloads and pours. And now when I try to import in python it works properly.
>>>import numpy
>>>
Now I try to install pygtk through HomeBrew using
brew install pygtk
It successfully Downloads and pours. But when I import it in python I get
>>>import pygtk
Import Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named pygtk
>>>
Now I went and checked my /usr/local/lib/python2.7/site-packages/
numpy exists but pygtk does not. But pygtk exists in /usr/local/lib/
Why is brew doing this? Also am I getting something fundamentally wrong here?
Now I really don't know what to do exactly but I don't think copying pygtk from /usr/local/lib/ to /usr/local/lib/python2.7/site-packages/
Note: I am using MAC OS and I mainly work through the terminal and would prefer a solution through terminal itself.
Edit1: I have found a solution or rather a workaround.
Basically I am downloading the latest PyGTK.pkg and then installing it. And then copying all the files in the system default python to my python2.7
wget -P /Users/mac_test/Downloads/ https://sourceforge.net/projects/macpkg/files/PyGTK/2.24.0/PyGTK.pkg
installer -pkg /Users/mac_test/Downloads/PyGTK.pkg -target /
cp -r /opt/gtk/lib/python2.7/site-packages/ /usr/local/lib/python2.7/site-packages/
Not sure this is the best way though.
How it worked for me:
First of all I have python installed via brew:
which python && python --version
/usr/local/bin/python
Python 2.7.13
Then I installed pygtk through brew install pygtk and it was successful
After that:
python
Python 2.7.13 (default, Dec 18 2016, 07:03:39)
[GCC 4.2.1 Compatible Apple LLVM 8.0.0 (clang-800.0.42.1)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import pygtk
>>> help(pygtk)
It responds with this:
Help on module pygtk:
NAME
pygtk
FILE
/usr/local/lib/python2.7/site-packages/pygtk.py
So probably copy pygtk to site-packages might solve your issue.
I don't know specific reason you prefer brew over pip + virtualenv but I gently recommend you to try it instead of brew and global library installation.
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 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
After I install python 2.6 on CentOS by:
wget http://download.fedoraproject.org/pub/epel/5/i386/epel-release-5-4.noarch.rpm
sudo rpm -ivh epel-release-5-4.noarch.rpm
yum install python26
Then I install pyPdf by:
yum install pyPdf
However, the pyPdf is only available to the old python 2.4:
# python
Python 2.4.3 (#1, Jan 9 2013, 06:49:54)
[GCC 4.1.2 20080704 (Red Hat 4.1.2-54)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import pyPdf
>>> import sys
>>> print sys.path
['', '/usr/lib/python24.zip', '/usr/lib/python2.4', '/usr/lib/python2.4/plat-linux2', '/usr/lib/python2.4/lib-tk', '/usr/lib/python2.4/lib-dynload', '/usr/lib/python2.4/site-packages', '/usr/lib/python2.4/site-packages/Numeric', '/usr/lib/python2.4/site-packages/gtk-2.0']
it's not available to the newly install python 2.6:
# python26
Python 2.6.8 (unknown, Nov 7 2012, 14:47:34)
[GCC 4.1.2 20080704 (Red Hat 4.1.2-52)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> print sys.path
['', '/usr/lib/python26.zip', '/usr/lib/python2.6', '/usr/lib/python2.6/plat-linux2', '/usr/lib/python2.6/lib-tk', '/usr/lib/python2.6/lib-old', '/usr/lib/python2.6/lib-dynload', '/usr/lib/python2.6/site-packages']
>>> import pyPdf
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named pyPdf
How can I install pyPdf for python 2.6?
How about creating a virtualenv and install pyPdf with pip
$ curl -O https://pypi.python.org/packages/source/v/virtualenv/virtualenv-X.X.tar.gz
$ tar xvfz virtualenv-X.X.tar.gz
$ cd virtualenv-X.X
$ python26 virtualenv.py myVirtualenv
$ source myVirtualenv/bin/activate
$ pip install pyPdf
Read more about virtualenv here
Not sure how you're doing it. I have recently installed pyPdf on CentOS for Python 2.7. A simple yum worked for me.
yum install pyPdf
pyPdf is also available for newer versions. Check here
Edit:
May be having two different versions of Python is causing this issue
for you. CentOS comes with default installation of v2.4. Remove all
the previous versions and install again.
For CentOS version lower than 6, python 2.4 comes by default. For version 6 and above its python2.6 .
Now I would strictly advise not to upgrade the base Python installation i.e python2.4 in the earlier versions, as that would break lot of system level funcationalities that expect default python to be 2.4.
Your question can be solved in multiple ways :
yum install always does an installation for default python. If its 2.4 it will install the package for 2.4.
To install package for 2.6, download easy_install for 2.6 or PIP for 2.6 and then simply do easy_install {{package_name}} or pip install {{package_name}}
To keep your environments different, as suggested by #Dikei install a virtual-env and then install your packages. This is method is one of the best practices for maintaining multiple python environments.
Quick installation of Python !!!
Get the latest verion of Python 2.6.9
wget https://www.python.org/ftp/python/2.6.9/Python-2.6.9.tar.xz
Extract thae package
tar xf Python-2.6.9.tar.xz
Configure them
cd Python-2.6.9
./configure --prefix=/usr/local --enable-unicode=ucs4 --enable-shared LDFLAGS="-Wl,-rpath /usr/local/lib"
Install them
make && make altinstall
Check Version:
python --version
Python 2.6.9
Credits:https://danieleriksson.net
Hope this helps !!!