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.
Related
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 recently installed openalpr on my mac using brew install openalpr with success. I would like to use the openalpr library with python 2.7 but I am having difficulty binding the two and could use some help.
I currently get the following in my projects file location:
Python 2.7.11 (default, Jan 22 2016, 08:29:18)
[GCC 4.2.1 Compatible Apple LLVM 7.0.2 (clang-700.1.81)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from openalpr import Alpr
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named openalpr
>>>
When I move to /usr/local/Cellar/openalpr/2.3.0/lib/python2.7/dist-packages/openalpr
The import works. How can I bind this library? Thanks
EDIT: I think I've seen that running the setup.py for openalpr is how you bind but I have no idea where to find it in my file system.
I had to do the following command:
echo /usr/local/opt/openalpr/lib/python2.7/dist-packages/ >> /usr/local/lib/python2.7/site-packages/openalpr.pth
I try to visualize graph with matplotlib in python but I have few problem in my mac (Yosemite 10.10.2). I already installed matplotlib, and I know that I have 2 version of python installed in my computer, which are 2.7.8 and 2.7.6
Using default interpreter which is python 2.7.8, I got this error
dhcPlus-mbp:~ macbook$ python
Python 2.7.8 (v2.7.8:ee879c0ffa11, Jun 29 2014, 21:07:35)
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
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
But if I try this one, it works on terminal. But I can't build straight from my Sublime with Ctrl+B
dhcPlus-mbp:~ macbook$ /usr/bin/python
Python 2.7.6 (default, Sep 9 2014, 15:04:36)
[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.39)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import matplotlib
>>>
My question is, how could I change default python interpreter so I can use the 2.7.6 in my environment?
Any help is greatly appreciated. Thank you very much.
This problem solved by removing the extra Python libraries on Mavericks by
sudo rm -rf /Library/Frameworks/Python.framework/
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.
I am trying to test some 32 bit software on an Ubuntu 11.04 64 bit machine. After getting the 32 bit libraries installed, it now fails with :
Python 2.7.2 (default, Nov 4 2011, 19:26:59)
[GCC 4.5.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from pyexpat import *
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: /usr/local/lib/python2.7/lib-dynload/pyexpat.so: undefined symbol: PyUnicodeUCS4_Decode
Any ideas on where to find PyUnicodeUCS4_Decode? I installed PyXML-0.8.4, but that didn't help.
Thanks !
This thread seemed to explain that it might be due to python supporting two different Unicode modes UCS2 (the default), and UCS4. It suggests recompiling from scratch.
You can download the package directly and then compile on your machine by running:
python setup.py build
python setup.py install