How to control which Python version plpython3 uses? - python-3.9

I have a postgres 11 database running on CentOS 7 and am trying to use PL/python, but need to point to a specific version of the python interpreter. I need to use python3.9 whereas it is using python3.6. I am not able to uninstall python3.6 at the moment, so was hoping to point plpython3 at my python3.9 interpreter somehow.
I have installed the package postgresql-plpython3:
sudo yum install -y postgresql-plpython3
I have created an extension in PG and can run a simple PL/python function that reports the version used:
CREATE OR REPLACE FUNCTION pyver ()
RETURNS TEXT
AS $$
import sys
pyversion = sys.version
return pyversion
$$ LANGUAGE 'plpython3u';
Executing it returns this:
# select pyver();
pyver
-----------------------------------------
3.6.8 (default, Nov 16 2020, 16:55:22) +
[GCC 4.8.5 20150623 (Red Hat 4.8.5-44)]
(1 row)
On my operating systems I have the following python interpreter files, and the versions they are using:
$ /usr/bin/python3 --version
Python 3.9.6
$ python3 --version
Python 3.9.6
$ python3.6 --version
Python 3.6.8
Something within the plpython3 module seems to be hard-coded to point to my python3.6 version.

postgresql uses an embedded python interpreter, as stated here. Changing it requires re-compiling the pl/python extension (afaik). Compilation instructions here show the relevant bits: the option --with-python and the env var PYTHON

Related

opencv on M1 wheel built from source results in "is not a supported wheel on this platform."

I tried to build opencv-python from source since there is no wheel yet for my Apple M1 laptop.
that runs numpy 1.20.1, pip 21.0.1 python 3.9.1
So after cloning the git and altering the pyproject.toml to support numpy 1.20.1 and python 3.9.1 the wheel was built using
python -m pip wheel .
resulting in
opencv_python-4.5.1.48-cp39-cp39-macosx_11_2_arm64.whl
which looks correct from the tags
however when installing it using
python -m pip install opencv_python-4.5.1.48-cp39-cp39-macosx_11_2_arm64.whl
ERROR: opencv_python-4.5.1.48-cp39-cp39-macosx_11_2_arm64.whl is not a supported wheel on this platform.
how is that possible when it was build on the same system a minute ago. Does anyone have an idea?
could the problem be that python -vv tells me that I have a clang version?
Python 3.9.1 (default, Feb 18 2021, 23:17:57) [Clang 12.0.0 (clang-1200.0.32.29)]
I could not find any other question where the wheel was build from source on the same machine.

MonetDB set specific embedded python version

In a Linux environment, I'd like to be able to set the embedded python3 to a specific python version. My current monetDB install seems to use 3.7 even though all default python paths point to 3.8.6.
Is there a way to set my 3.8.6 install as the default embedded python3 version?
After some experimentation, the problem seems to be the following: because you are installing MonetDB using apt, the installation pulls the python version that the distribution has packaged in apt. I assume that you are building your container starting from python:3.8. This is based on Debian Buster that packages Python 3.7.
In a bit more detail:
I built a container using the following Dockerfile:
FROM python:3.8
RUN apt-get update
RUN apt-get upgrade -y
COPY ./monetdb.list /etc/apt/sources.list.d/
COPY ./MonetDB-GPG-KEY /
RUN apt-key add /MonetDB-GPG-KEY
RUN apt-get update
RUN apt-get install -y monetdb5-sql monetdb-client monetdb-python3
with the files monetdb.list and MonetDB-GPG-KEY as described in the downloads page.
I then created a database farm and a new database in the container, setting embedpy3 to true:
root#bd0420e945e8:/# monetdbd create /tmp/dbfarm
root#bd0420e945e8:/# monetdbd start /tmp/dbfarm
root#bd0420e945e8:/# monetdb create -p monetdb pytestdb
created database with password for monetdb user: pytestdb
root#bd0420e945e8:/# monetdb set embedpy3=yes pytestdb
Using mclient I created a Python UDF that returns as a string the version of the embedded python interpreter:
CREATE FUNCTION pyversion ()
RETURNS STRING
LANGUAGE python {
import sys
return sys.version
};
When I called it I got the following result:
sql>select pyversion();
+-----------------------------------------------------+
| %2 |
+=====================================================+
| 3.7.3 (default, Jul 25 2020, 13:03:44) |
: [GCC 8.3.0] :
+-----------------------------------------------------+
1 tuple
I repeated the above process starting from a different distribution (Ubuntu Focal) that packages a different version of Python (It seems that Ubuntu has updated to Python 3.8.5 since the release of Focal).
FROM ubuntu:20.04
RUN apt-get update
RUN apt-get upgrade -y
RUN apt-get install -y gnupg ca-certificates
COPY ./monetdb.list /etc/apt/sources.list.d/
COPY ./MonetDB-GPG-KEY /
RUN apt-key add /MonetDB-GPG-KEY
RUN apt-get update
RUN apt-get install -y monetdb5-sql monetdb-client monetdb-python3
In this container the function pyversion returns the following:
sql>select pyversion();
+-----------------------------------------------------+
| %2 |
+=====================================================+
| 3.8.5 (default, Jul 28 2020, 12:59:40) |
: [GCC 9.3.0] :
+-----------------------------------------------------+
1 tuple
In conclusion, I would suggest to either build MonetDB from source in the container (see the README for instructions), or build your container starting from a distribution that packages Python 3.8 in its package manager.

How can i download paho and pip on my Windows 10

I am currently programming in IronPython 2.7 and would like to integrate Paho.
Since I became IronPython 2.7, I have to download Python 2 and not Python 3.
when I get the command
pip install paho-mqtt
heard in my Windows 10 terminal
what error message appears:
DEPRECATION: Python 2.7 reached the end of its life on January 1, 2020. Please update your Python as Python 2.7 is no longer maintained. pip 21.0 will end support for Python 2.7 in January 2021. Further information on Python 2 support in pip can be found at https://pip.pypa.io/en/latest/development/release-process/#python-2- support
Requirement already fulfilled: paho-mqtt in c: \ python27 \ lib \ site-packages (1.5.0)
has an idea what I have to do?
Python you are using must be below the minimum supported version of for Python 2, and that's why you get the error.
Paho-MQTT does not work with Python versions below 2.7.9, according to their
documentation.
Try this:
Delete your current Python.
Install the newest python from their website, install it on PATH.
Verify that your installation was successful with cmd -> python (should show your version, i.e Python 3.8.3)
Install your package with cmd -> pip install paho-mqtt

pip3 packages are being installed in ~/.local folder

I recently upgraded to ubuntu 20.04 LTS. As python3.8 was preinstalled, I installed pip using the command sudo apt install python3-pip , and I started installing python3 libraries. All the libraries I install are being installed into ~/.local/lib/Python3.8/site-packages folder. If I remember correctly, these packages should be installed into /usr/local/lib/python3.8/dist-packages.
madhan#madhan:~$ pip3 show tensorflow
Name: tensorflow
Version: 2.2.0
Summary: TensorFlow is an open source machine learning framework for everyone.
Home-page: https://www.tensorflow.org/
Author: Google Inc.
Author-email: packages#tensorflow.org
License: Apache 2.0
Location: /home/madhan/.local/lib/python3.8/site-packages
After the packages are installed, I get a warning saying ~/.local/bin is not included in $PATH variable.
Installing collected packages: appdirs, cachelib, pygments, cssselect, lxml, pyquery, howdoi
WARNING: The script pygmentize is installed in '/home/madhan/.local/bin' which is not on PATH.
Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
WARNING: The script howdoi is installed in '/home/madhan/.local/bin' which is not on PATH.
Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
Successfully installed appdirs-1.4.4 cachelib-0.1 cssselect-1.1.0 howdoi-1.2.1 lxml-4.5.1 pygments-2.6.1 pyquery-1.4.1
even if ~/.local/bin is not included in $PATH variable, I am still able to import the packages.
madhan#madhan:~$ python3
Python 3.8.2 (default, Apr 27 2020, 15:53:34)
[GCC 9.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import tensorflow
>>>
Does anybody know why this is happening? How do I change the default folder to which pip3 packages are installed. Is it okay leave the packages in ~/.local folder or will it be a problem in the future?

gcloud command says `pyenv: python2: command not found` even if python2 is valid in terminal

I'm using macOS Mojave 10.14.2, and pyenv 1.2.7 .
And these are my configs of pyenv.
python2 seems to work in the terminal.
$ pyenv versions
system
* 2.7.14
3.6.4
$ pyenv global
2.7.14
3.6.4
$ pyenv local
2.7.14
$ python2
Python 2.7.14 (default, Sep 12 2018, 16:35:37)
[GCC 4.2.1 Compatible Apple LLVM 9.0.0 (clang-900.0.39.2)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> (It works!)
But when I use gcloud command, it fails saying it cannot find python2.
$ gcloud config list
pyenv: python2: command not found
The `python2' command exists in these Python versions:
2.7.14
On the other hand, npm command, which requires python2 too, works fine.
It get fixed by pyenv shell command temporarily, but it is valid only until I close the terminal.
(The solution is referred here: https://github.com/pyenv/pyenv/issues/1159)
$ pyenv shell 2.7.14 3.6.4
$ gcloud config list -> Works!
How to fix this problem permanently ?
I was recently encountering this error and found a solution. I am using pyenv with virtual env (pyenv-viritualenv) and I was attempting to run gcloud from inside my python 3 virtual environment.
The issue is that when you run gcloud from a location within the virtualenv, it only knows of the python versions specified in the .python-version file for that directory. You therefore have to specify a python 2 version to run in addition to your python 3 version:
pyenv local <virtualenv name> <python 2 version>
I did this in addition to doing the CLOUDSDK_PYTHON bit mentioned in answers on other related questions:
export CLOUDSDK_PYTHON=$(which python2)
I added this to my .bash_profile
if when you type python on the terminal, it shows different python versions. for example you want to point out to 3.9.0 version. you can type pyenv global 3.9.0

Resources