How can I install ZODB for Python 3? I installed python-ZODB3 in Fedora, but I can use ZODB only in Python 2:
$ python
Python 2.7.5 (default, Sep 25 2014, 13:57:38)
[GCC 4.8.3 20140911 (Red Hat 4.8.3-7)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import ZODB
>>> quit()
$ python3
Python 3.3.2 (default, Jun 30 2014, 17:20:03)
[GCC 4.8.3 20140624 (Red Hat 4.8.3-1)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import ZODB
Traceback (most recent call last):
File "/usr/lib64/python3.3/code.py", line 90, in runcode
exec(code, self.locals)
File "<console>", line 1, in <module>
ImportError: No module named 'ZODB'
Which package am I missing?
In general, the Fedora name for Python package foo for Python 3.x is python3-foo, not python-foo3.
In particular, python-ZODB3 is the Python 2.x package for ZODB3. (ZODB3 is the obsolete version 3 of ZODB, still provided for backward compatibility.) Both the old 3.x and new 4.x versions of ZODB work for both Python 2.x and 3.x; that means there are (at least potentially) packages named python-ZODB (ZODB 4.x for Python 2.x), python3-ZODB (4.x for 3.x), python-ZODB3 (3.x for 2.x), and python3-ZODB3 (3.x for 3.x). It's the second one you want, not the third.
I can't guarantee that your Fedora version and repos have a python3-ZODB RPM, but from a quick search, I found this, so at least some Fedora-based systems have one.
If there's not a Fedora RPM for that, you can probably install it via pip, something like pip3 install ZODB.
Related
I have been using lirc in Python 2.7 and Python 3.5.3 on Rpi3. Now I have installed Python 3.8.7 from source code, but I am not able to use lirc in this version of Python, but it still works in Python 3.5. apt-get reports that python3-lirc is already the newest version (1.2.1-2). How to get lirc work in both Python 3.5 and 3.8?
pi#RPi3:~ $ python
Python 3.8.7 (default, Jan 7 2021, 08:59:27)
[GCC 6.3.0 20170516] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import lirc
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'lirc'
>>>
pi#RPi3:~ $ python3.5
Python 3.5.3 (default, Nov 18 2020, 21:09:16)
[GCC 6.3.0 20170516] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import lirc
>>> sockid=lirc.init("myProg", blocking = False)
>>>
It means that you installed lirc on only one of the two pythons.
Use the pip from your Python 3.8 to install lirc so that the module will also be accessible to your Python 3.8.
Module lirc has to be uninstalled with pip, then python-lirc can be installed in Python 3,8 as described in https://github.com/tompreston/python-lirc/issues/26 after installing cyhton with pip.
I'm trying to develop a Python script, and I seem to be running into a conflict between two of the libraries that I want to include.
The first dependency that I have is pymoos (https://github.com/msis/python-moos), which is necessary to connect to my communication architecture. I've built the code and manually installed the resultant pymoos.so in the following places:
/usr/lib/python3.6/site-packages/pymoos.so
/usr/lib64/python2.7/lib-dynload/pymoos.so
/usr/lib64/python3.6/lib-dynload/pymoos.so
/usr/local/lib/python3.7/lib-dynload/pymoos.so
However, only python2.7 will allow me to 'import pymoos' from the interpreter. Attempting from either of the Python3 versions produces this:
Python 3.6.8 (default, Jun 11 2019, 15:15:01)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-39)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import pymoos
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: dynamic module does not define module export function (PyInit_pymoos)
The second dependency is pydantic, which I have only managed to install using pip3, apparently meaning that it's only available from either of the versions of Python3 that I have installed. Attempting to import from Python2 gives the following:
Python 2.7.5 (default, Jun 11 2019, 14:33:56)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-39)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import pydantic
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named pydantic
Since I know where the pymoos.so library is, I think that my easiest path forward is to put that in the right place so it works with python3, but I can't seem to find the right place!
as per my comment:
it should be as simple as pip install path/to/pymoos/code, but you might be better off using a more widely used database library like asyncpg or psycopg.
Regarding having to use sudo, you might consider using virtualenv or similar to setup a dedicated python environment for your application.
I downloaded the source code of python 2.7.14 and built it and installed it on linux ( Red Hat 4.8.5-16 ). I have earlier installed python-magic and requests libraries. Now when I try to import modules installed using pip, I get this:
$ python2
Python 2.7.14 (default, Nov 9 2017, 09:05:45)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-16)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import magic
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named magic
>>> import requests
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named requests
while similar thing works perfectly fine in python 2.7.5 (default with the RHEL system)
$ python
Python 2.7.5 (default, May 3 2017, 07:55:04)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-14)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import magic
>>> import requests
>>>
Am I missing any configuration step here?
The modules installed via pip are only available to the standard python version. You need to install your desired packages for the non-standard python versions as well (see also Installing Python Modules)
python2 -m pip install python-magic
python2 -m pip install requests
your pip is default set for version
$ python
Python 2.7.5
SO if you want to install module for
$ python2
Python 2.7.14
use python2 -m pip install module_name
The sys.path must be different for the two installations. That's a list of folders that Python checks for imports.
It's probably simplest to just symlink the one for wherever pip installs to into the modules folder for 2.7.14.
I wanted to check out which Python interpreter was running under my virtual env so I just entered the virtualenv and used getsitepackages. This is what came out.
(test)~/Documents/Development/test$ python
Python 2.7.9 (default, Apr 7 2015, 07:58:25)
[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.57)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import site
>>> print site.getsitepackages()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'module' object has no attribute 'getsitepackages'
>>>
Is this normal behaviour when operating under a virtualenv? If possible how would I correct, or should I even bother?
A user has the same problem as you.
There is a known bug, that Python 2.7 isn't compatible with site.py.
This bug is still open, since November 2012.
You have to leave virtualenv or use another version of Python.
I have python installed in two locations, in os default it's 2.6.6 and in /usr/local/bin/python2.7 has 2.7.
I have installed cairo (cairo-1.12.18) via source using configure/make/make install, but it appears to have installed under python 2.6.6. How do I install it for python2.7?
[root#xxxxx ~]# python
Python 2.6.6 (r266:84292, Oct 12 2012, 14:23:48)
[GCC 4.4.6 20120305 (Red Hat 4.4.6-4)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import cairo
>>>
[root#xxxxx ~]# /usr/local/bin/python2.7
Python 2.7.8 (default, Nov 18 2014, 11:15:00)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-3)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import cairo
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named cairo
>>>
Thank you.
Be sure to install it using python 2.7 and not python 2.6 (run make and make install using python 2.7). I assume you use Linux OS so your default Python is 2.7, you can change your default Python but it's not recommended due to several reasons. Please look at this StackOverflow question and answers for more informations:
Two versions of python on linux. how to make 2.7 the default