This question already has answers here:
Modules between multiple versions of Python Linux
(2 answers)
Closed 9 years ago.
CentOS 6.4 on my desktop had python 2.6.6 already installed
$ which python
/usr/bin/python
$ python
Python 2.6.6 (r266:84292, Feb 22 2013, 00:00:18)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-3)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>>
I installed python 3.3.0 from source side-by-side to the existing python 2.6.6 version.
However, when I am trying to use the lxml module in python 3, I get a ImportError as below:
$ which python3
/usr/local/bin/python3
$ python3
Python 3.3.0 (default, Oct 8 2012, 21:38:46)
[GCC 4.4.6 20120305 (Red Hat 4.4.6-4)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from lxml import etree
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named 'lxml'
>>>
Any pointers on how do I get the lxml module under python 3.3.0 would be greatly appreciated.
You need to install lxml for each Python version you want to use it with.
Related
I am trying to get the GPIO module working on a Raspberry Pi 3B+. I have installed the libraries as below. It works fine in Python2 but not Python 3 (version 3.9). Any ideas would be appreciated.
pi#raspberrypi:/usr/bin $ sudo apt-get install python-rpi.gpio python3-rpi.gpio
Reading package lists... Done
Building dependency tree
Reading state information... Done
python-rpi.gpio is already the newest version (0.6.5~stretch-1).
python3-rpi.gpio is already the newest version (0.6.5~stretch-1).
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
pi#raspberrypi:/usr/bin $ python2
Python 2.7.13 (default, Aug 22 2020, 10:03:02)
[GCC 6.3.0 20170516] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import RPi.GPIO
>>>
pi#raspberrypi:/usr/bin $ python3
Python 3.9.0 (default, Jan 27 2021, 16:17:29)
[GCC 6.3.0 20170516] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import RPi.GPIO
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'RPi'
>>>
My system has python3 as the default for python command.
when I try to import flask on python command line I get this:
Python 2.7.15rc1 (default, Apr 15 2018, 21:51:34)
[GCC 7.3.0] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import flask
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named flask
>>>
but in python3 i get this:
Python 3.6.5 |Anaconda, Inc.| (default, Apr 29 2018, 16:14:56)
[GCC 7.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import flask
>>>
How do i correct this?
It looks you are using two different packaging systems: pip and conda. For Python2, try pip2 install flask.
We have a setup based on CentOS 6.4 but with Python 2.7 (due to historical reasons). Note that CentOS 6 brings Python 2.6. Python 2.7 has been compiled from a Fedora 20 SRPM. In addition, to make it possible to freely use Python RPMs from CentOS 6 along with the 2.7 interpreter, we have created a /usr/lib/python2.7/site-packages/setup.pth file with the contents:
/usr/lib64/python2.6/site-packages
/usr/lib/python2.6/site-packages
Things used to work fine till the need to use protobuf-python-2.3.0-9.el6.x86_64 arose. This RPM has been downloaded from the EPEL repo and is available: here.
$ /usr/bin/python2.7
Python 2.7.4 (default, Mar 17 2015, 00:48:39)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-4)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import google.protobuf
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named google.protobuf
One thing that could be helpful is that the import error does not come with Python 2.6:
$ /usr/bin/python
Python 2.6.6 (r266:84292, Jan 22 2014, 09:42:36)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-4)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import google.protobuf
This error does not come with other import statements (e.g. import pip.vcs). It is somehow related to protobuf-python. What could be the reason? Any insight will be appreciated.
EDIT: The protobuf-python RPM installs files into /usr/lib/python2.6/site-packages/google/protobuf and the the 2.7 interpreter's sys.path is:
$ /usr/bin/python2.7 -c 'import sys; print sys.path' | sed -e 's/,/\n/g'
[''
'/usr/lib64/python27.zip'
'/usr/lib64/python2.7'
'/usr/lib64/python2.7/plat-linux2'
'/usr/lib64/python2.7/lib-tk'
'/usr/lib64/python2.7/lib-old'
'/usr/lib64/python2.7/lib-dynload'
'/usr/lib64/python2.7/site-packages'
'/usr/lib/python2.7/site-packages'
'/usr/lib64/python2.6/site-packages'
'/usr/lib/python2.6/site-packages']
After manual updating python and python3 in Fedora 19 or Fedora 20 (x86_64) to versions 2.7.6 and 3.3.3 respectively I have got this error:
python
Python 2.7.6 (default, Dec 17 2013, 23:13:55)
[GCC 4.8.2 20131212 (Red Hat 4.8.2-7)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
import pygtk
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named pygtk
Same happens if running python2 or python2.7.
After that I manually installed pygtk (from web site pygtk.org version 2.24, I hope it is the very version I need), but it haven't helped.
user#ubuntu:~/Documents/MongoDB$ python2
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.
>>> from pymongo import Connection
>>>
user#ubuntu:~/Documents/MongoDB$ python3
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.
>>> from pymongo import Connection
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named pymongo
Question> I don't know why pymongo doesn't work with my python 3. Any idea?
// Updated solution for this OP based on the helps below //
First, still don't understand why this post got down-vote!
Step1> http://pypi.python.org/pypi/pymongo3#downloads
Step2> Download pymongo3-1.9b1.tar.gz
Step3> unzip it by using tar xzf pymongo3-1.9b1.tar.gz
Step4> cd pymongo3-1.9b1
Step5> sudo python3 setup.py install
If you followed all above instructions, the pymongo should be ready
for your P3:)
Probably because you didn't install it for Python 3. You have to install a module for each version of Python that you have in order to access it from that version.This is all assuming that the module is compatible with each version of Python that you have.