MYSQLConnection call to #database.setter incorrectly routes to the _mysql_connector c-extenstion - mysql-connector-python

Running on Mac Big Sur 11.6.2
Using Python 3.8
Mysql 8.0.29 Homebrew
MYSQLConnection call to #database.setter, i.e. db_conn.database = my_db_name, incorrectly routes to the _mysql_connector c-extenstion, but I don not have the c extension installed, so the call raises an exception. After pip install mysql-connector-python the file WHEEL contains Root-Is-Purelibe: true and top_level.txt is missing _mysql_connector. I expect calling db_conn.database = my_db_name to execute the MySQLConnection class’ database(value) method in connection.py, not route the call to a non-existent _mysql_connector I have been unable to get pip to install the mysql-connector-python with c extension despite trying various suggestions in stackoverflow.

Sorry, I don't a reputation yet to reply in comment to Nuno-Mariz, so posting the following.
I work on the same team as #needpythonhelp, and we have nearly identical macbook pro laptops, they are not M1. We use the the same Pipfile to create a project-specific .venv. His does not get the _mysql_connector, and my .venv does (I don't remember how I got my python 3.8 version a year ago). See difference below. Could his lack of _mysql_connector have anything to do with missing CPPFLAGS or LDFLAGS when his Python version was installed (presumably built from source e.g. pyenv or annaconda)?
My system
clang --version
Apple clang version 12.0.0 (clang-1200.0.32.29)
Target: x86_64-apple-darwin19.6.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin
$ python3
Python 3.8.5 (v3.8.5:580fbb018f, Jul 20 2020, 12:11:27)
[Clang 6.0 (clang-600.0.57)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
cat .venv/lib/python3.8/site-packages/mysql_connector_python-8.0.23.dist-info/WHEEL
Wheel-Version: 1.0
Generator: bdist_wheel (0.35.1)
Root-Is-Purelib: false
Tag: cp38-cp38-macosx_10_14_x86_64
cat .venv/lib/python3.8/site-packages/mysql_connector_python-8.0.23.dist-info/top_level.txt
_mysql_connector
_mysqlxpb
mysql
mysqlx
ls -la .venv/lib/python3.8/site-packages/_mysql*
-rwxr-xr-x 1 brian staff 7876288 May 25 18:53 .venv/lib/python3.8/site-packages/_mysql_connector.cpython-38-darwin.so
-rwxr-xr-x 1 brian staff 3190548 May 25 18:53 .venv/lib/python3.8/site-packages/_mysqlxpb.cpython-38-darwin.so
needpythonhelp's system
$ clang --version
Apple clang version 11.0.3 (clang-1103.0.32.62)
Target: x86_64-apple-darwin20.6.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin
$ python3
Python 3.8.3 (default, Jul 2 2020, 11:26:31)
[Clang 10.0.0 ] :: Anaconda, Inc. on darwin
his WHEEL file has
Root-Is-Purelib: true
Tag: py2-none-any
Tag: py3-none-any
top_level.txt
mysql
mysqlx
he does not have either of these in .venv/lib/python3.8/site-packages
_mysqlxpb.cpython-38-darwin.so
_mysql_connector.cpython-38-darwin.so
Edit/Update to the above info
I did a test later today where I used pyenv to install the latest CPython 3.8.13, and built a new .venv from the same Pipfile as noted above. This .venv is like #needpythonhelp's .venv. So now I have one .venv (CPython 3.8.13) that does NOT have _mysql_connector and Root-Is-Purelib: false, etc., and another .venv (from my original CPython 3.8.5 installed a year ago) that does have it.
This is what my Pyenv install today looked like:
❯ pyenv install 3.8:latest
python-build: use openssl#1.1 from homebrew
python-build: use readline from homebrew
Downloading Python-3.8.13.tar.xz...
-> https://www.python.org/ftp/python/3.8.13/Python-3.8.13.tar.xz
Installing Python-3.8.13...
python-build: use tcl-tk from homebrew
python-build: use readline from homebrew
python-build: use zlib from xcode sdk
Installed Python-3.8.13 to /Users/brian/.pyenv/versions/3.8.13
Any ideas on how to consistently get the c-ext when I use pyenv to install new Python versions?

Related

python virtualenv failure after upgrade fedora from 31 to 33

When I upgraded fedora from 31 to 33, I found out that the base python package had been upgraded from 3.7.9 to 3.9, and that python references in virtual environment folders were now pointing to the new version of python.
There were no problems activating my python 3.7 virtual environment
[bou#bous-fed33 avguide]$ source ~/py37/bin/activate
(py37) [bou#bous-fed33 avguide]$ which python
~/py37/bin/python
However the python version was no longer 3.7.9 but 3.9, which came with fedora 33
(py37) [bou#bous-fed33 avguide]$ python -V
Python 3.9.0
Now when I tried running jupyter notebook get errors ModuleNotFoundError
(py37) [bou#bous-fed33 avguide]$ jupyter notebook --port 7777
[W 09:14:02.710 NotebookApp] Error loading server extension jupyterlab
ModuleNotFoundError: No module named 'jupyterlab'
Also get errors for other packages like pandas, numpy etc which had all been fine before.
(py37) [bou#bous-fed33 avguide]$ python
Python 3.9.0 (default, Oct 6 2020, 00:00:00)
[GCC 10.2.1 20200826 (Red Hat 10.2.1-3)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import pandas as ps
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'pandas'
I had tried to reinstall all the packages from existing requirements.txt file and manual reinstalls as well - all failed with errors. There was also no point in reinstalling python 3.7 as it was still there.
(py37) [bou#bous-fed33 avguide]$ pip3 install --force-reinstall -r requirements.txt
[bou#bous-fed33 avguide]$ sudo dnf install python37
Package python3.7-3.7.9-2.fc33.x86_64 is already installed.
I found a relatively simple FIX after a while.
The way python versions is managed is by using symbolic links in virtual env folders. So all we have to do is find the location of existing python binary for 3.7.9 or whatever python version your virtual environment uses and update the symbolic links to point to the correct python base packages.
These are the python versions installed in my fedora OS/base.
[bou#bous-fed33 ~]$ ls -ltr /usr/bin/python3*
-rwxr-xr-x. 2 root root 15536 Sep 22 19:23 /usr/bin/python3.7
-rwxr-xr-x. 1 root root 15536 Sep 25 23:37 /usr/bin/python3.8
lrwxrwxrwx. 1 root root 9 Oct 7 00:19 /usr/bin/python3 -> python3.9 <<<
-rwxr-xr-x. 1 root root 15536 Oct 7 00:20 /usr/bin/python3.9 <<<
Note how /usr/bin/python3 points to python3.9
Locate the symbolic links in virtual environment ~/py37/bin/ folder
[bou#bous-fed33 avguide]$ cd ~/py37/bin/
[bou#bous-fed33 bin]$ ls -ltr python*
lrwxrwxrwx. 1 bou bou 16 Dec 29 2019 python3 -> /usr/bin/python3
lrwxrwxrwx. 1 bou bou 7 Dec 29 2019 python -> python3
Note how python points to python3 and python3 in turn points to operating system package /usr/bin/python3 - which after the fedora python upgrade no longer points to /usr/bin/python3.7 but to the new version of python /usr/bin/python3.9
So all we need to do is remove existing softlinks
[bou#bous-fed33 bin]$ rm python3 python
And then create new files or symbolic links python3 and python that point to python3.7 binary in /usr/bin/python3.7
[bou#bous-fed33 bin]$ ln -s /usr/bin/python3.7 python3
[bou#bous-fed33 bin]$ ln -s python3 python
Activate virtual environment and check python version is correct.
[bou#bous-fed33 bin]$ ls -ltr python*
lrwxrwxrwx. 1 bou bou 18 Dec 2 10:03 python3 -> /usr/bin/python3.7
lrwxrwxrwx. 1 bou bou 7 Dec 2 10:04 python -> python3
[bou#bous-fed33 avguide]$ source ~/py37/bin/activate
(py37) [bou#bous-fed33 avguide]$ python -V
Python 3.7.9
(py37) [bou#bous-fed33 avguide]$ which python
~/py37/bin/python
(py37) [bou#bous-fed33 avguide]$ python
Python 3.7.9 (default, Sep 22 2020, 09:19:36)
[GCC 10.2.1 20200826 (Red Hat 10.2.1-3)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import pandas as pd
>>> quit()
We got the correct python version back for our virtual env and JupyterLab runs all right as well now.
(py37) [bou#bous-fed33 avguide]$ jupyter notebook --port 7777
[I 10:07:54.408 NotebookApp] JupyterLab extension loaded from /home/bou/py37/lib64/python3.7/site-packages/jupyterlab
[I 10:07:54.408 NotebookApp] JupyterLab application directory is /home/bou/py37/share/jupyter/lab
[I 10:07:54.410 NotebookApp] The Jupyter Notebook is running at:
[I 10:07:54.410 NotebookApp] https://bous-fed33:7777/
Hope this helps out someone running into similar problems with using their python virtual environment after base OS and/or python upgrade to a new version.
A better solution is to use pyenv, as it is specifically designed for this situation.
Pyenv will be available in your package repo... so yum search pyenv, then install.
See all available Python versions that pyenv can install for you:
$ pyenv install --list
Then pick form the list, eg. you'll see your missing Python 3.7.9. Install it to your local pyenv store, which will allow you to use it in your virtual environment:
$ pyenv install 3.7.9
You can then activate it in the directory containing your virtual env:
$ cd avguide
$ python --version
Python 3.9.0
$ pyenv local 3.7.9
$ python --version
Python 3.7.9
and it will automatically take care of you python binary links. See this tutorial and search for similar ones to get all the details.

ERROR: Could not find a version that satisfies the requirement tensorflow-data-validation (from versions: none)

I get this error with Python 3.7 and Windows 10 64-bit (which is supported).
It seems that there are only wheels for Windows for Python 3.5 and 3.6...
Thanks in advance.
pip install tensorflow-data-validation
Collecting tensorflow-data-validation
Note: you may need to restart the kernel to use updated packages.
ERROR: Could not find a version that satisfies the requirement tensorflow-data-validation (from versions: none)
ERROR: No matching distribution found for tensorflow-data-validation
Software and versions
-Windows 10 Enterprise. 64-bit
-import sys
!{sys.executable} --version
Python 3.7.3
(Python 3.7 version (Anaconda 2019.07 for Windows Installer https://www.anaconda.com/distribution/ , Jupyter Notebook))
-Successfully installed pip-19.2.3 (pip --version)
-ERROR: Cannot uninstall 'PyYAML'. It is a distutils installed project and thus we cannot accurately determine which files belong to it which would lead to only a partial uninstall. (pip install apache-beam)
-Successfully installed tensorboard-1.14.0 tensorflow-1.14.0 tensorflow-estimator-1.14.0 (pip install tensorflow)
-Successfully installed pyarrow-0.14.0 (pip install pyarrow==0.14.*)
-https://www.tensorflow.org/tfx/data_validation/install (https://pypi.org/project/tensorflow-data-validation/)
Supported platforms
TFDV is tested on the following 64-bit operating systems:
Windows 7 or later.
verbose
pip install -v tensorflow-data-validation
Collecting tensorflow-data-validation
Analyzing links from page https://pypi.org/simple/tensorflow-data-validation/
Config variable 'Py_DEBUG' is unset, Python ABI tag may be incorrect
Config variable 'WITH_PYMALLOC' is unset, Python ABI tag may be incorrect
[…]
Skipping link: none of the wheel's tags match: cp35-cp35m-win_amd64: files.pythonhosted.org/packages/d7/a1/b1f0c9c88713a60f206cf7bfaeb9391da1c9c8e3a6c98cd22078568777db/tensorflow_data_validation-0.14.0-cp35-cp35m-win_amd64.whl#sha256=eeff482c69ae1e49d84bbbef7c2ca058735e1d12cd640b643853f5f5fb05bc70 (requires-python:>=2.7,!=3.0.,!=3.1.,!=3.2.,!=3.3.,!=3.4.,<4)
Skipping link: none of the wheel's tags match: cp36-cp36m-win_amd64: files.pythonhosted.org/packages/bb/75/f3112982ca379481ae7706a94bf2755bd886fd4c8386e88ab978c5a0ae52/tensorflow_data_validation-0.14.0-cp36-cp36m-win_amd64.whl#sha256=611c23f718df87dcb6f34a6cf81d1a9699523254803607537e3d7e94e2c4712c (requires-python:>=2.7,!=3.0.,!=3.1.,!=3.2.,!=3.3.,!=3.4.,<4)
Skipping link: none of the wheel's tags match: cp35-cp35m-win_amd64: files.pythonhosted.org/packages/77/13/d0a90ccde514a4547b5d2ce3268f683aa6d5fb9f185c2b4d9a7db15eafca/tensorflow_data_validation-0.14.1-cp35-cp35m-win_amd64.whl#sha256=df5eb52ef53ee9db901aed5a30db183f272cda0a8b4f6981d9843cb6c52fc58a (requires-python:>=2.7,!=3.0.,!=3.1.,!=3.2.,!=3.3.,!=3.4.,<4)
Skipping link: none of the wheel's tags match: cp36-cp36m-win_amd64: files.pythonhosted.org/packages/54/3e/dec2c051d4a6dd04dcacfd73d4d02be3ad3cd56008ba2251e3bd8cc36adf/tensorflow_data_validation-0.14.1-cp36-cp36m-win_amd64.whl#sha256=2cba18c385d7de8d346b8db4b9bfec38e8535e1371a6a7f2f375ea51264dfeb8 (requires-python:>=2.7,!=3.0.,!=3.1.,!=3.2.,!=3.3.,!=3.4.,<4)
[…]
Given no hashes to check 0 links for project 'tensorflow-data-validation': discarding no candidates
PyPI Download Files
tensorflow_data_validation-0.14.1-cp35-cp35m-win_amd64.whl (1.7 MB)
Wheel cp35 Aug 22, 2019
tensorflow_data_validation-0.14.1-cp36-cp36m-win_amd64.whl (1.7 MB)
Wheel cp36 Aug 22, 2019
-https://pypi.org/project/tensorflow-data-validation/#modal-close
Works with Python 3.6.9 (e.g. Anaconda Navigator>Environments>Create)

Why is Travis CI's xenial VM finding gcc 5 and 7, but not 6?

I'm trying to have Travis CI build this C project, with this .travis.yml file. It works - almost. For some reason, building with GCC 6 fails, but not because of the project itself, but because this happens on the VM:
$ export MATRIX_EVAL="export CC=gcc-6"
$ export TRAVIS_COMPILER=gcc
$ export CC=gcc
$ export CC_FOR_BUILD=gcc
$ gcc --version
gcc (Ubuntu 5.4.0-6ubuntu1~16.04.11) 5.4.0 20160609
Copyright (C) 2015 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
before_install
0.00s$ eval "${MATRIX_EVAL}"
0.14s$ cmake . && make
CMake Error at /usr/local/cmake-3.12.4/share/cmake-3.12/Modules/CMakeDetermineCCompiler.cmake:48 (message):
Could not find compiler set in environment variable CC:
gcc-6.
Call Stack (most recent call first):
CMakeLists.txt:9 (project)
again, this does not happen with GCC 5 and GCC 6
The reason this happens is that GCC 6 is Ubuntu Xenial's distribution's default version. So it's not available as a versioned-name binary, and there's no need to download any packages for making it available.
Just replace:
- os: linux
addons:
apt:
sources:
- ubuntu-toolchain-r-test
packages:
- g++-6
env:
- MATRIX_EVAL="export CC=gcc-6"
with, say this:
- os: linux
env:
- MATRIX_EVAL="echo GCC 6 will be used by default in xenial"
in your .travis.yml and you should be set.

Visual Studio Code and pylint not finding module issues

First, I may have more of an issue with correct environment selection. I did a fresh install of Linux Mint 19 and apt dist-upgrade... etc... and then used apt-get and pip to install pymysql, pil.intertk and pylint for both python and python3 from the cli...
All is good from cli:
~$ python3 --version
Python 3.6.5
~$ pylint3 --version
No config file found, using default configuration
pylint3 1.8.3,
astroid 1.6.0
Python 3.6.5 (default, Apr 1 2018, 05:46:30)
[GCC 7.3.0]
python3
Python 3.6.5 (default, Apr 1 2018, 05:46:30)
[GCC 7.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import pymysql
>>> import PIL
>>>
After installing VSC.... the only two selection of python environments are 2.7.12 and 3.5.2 ?
I then modified VSC settings with: "python.pythonPath": "/usr/bin/python3"
Which still shows as Python 3.5.2 64-bit within VSC
But here comes my issue that I have tried many suggestions I have found from searching with no luck...
pylint is not finding any module I install. I assume its due to the mix match of version ? But not sure how to resolve that?
When I try to specify the pylint path : "python.linting.pylintPath": "/usr/bin/pylint3"
I get an invalid path error in VSC.. but its a valid path
~$ which pylint3
/usr/bin/pylint3
Any help would be greatly appreciated....
So after some frustrating trail and error I have fixed the issue by uninstalling the Flatpak version of Visual Studio Code listed in the Linux Mint's Software Center... and installing the deb package from the official site.
After installing the deb package... the proper version of python are showing and pylint is working correctly.

yum command : python version mismatch

I have Red Hat Linux (Red Hat Enterprise Linux Server release 6.5 (Santiago) ) and yum in not working with message
There was a problem importing one of the Python modules
required to run yum. The error leading to this problem was:
No module named yum
Please install a package which provides this module, or
verify that the module is installed correctly.
It's possible that the above module doesn't match the
current version of Python, which is:
2.7.8 (default, Nov 7 2014, 11:45:08)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-11)]
If you cannot solve this problem yourself, please go to
the yum faq at:
http://yum.baseurl.org/wiki/Faq
Current version of python is 2.7.8
Any help is appreciated.
CentOS 6 ships with python 2.6. Someone installed an incompatible version of python system-wide and that has broken things. That should not have been done.
You need to find out how the 2.7 version of python was installed and fix that (by removing the incorrect package or by removing the source-installed python or by fixing the $PATH or whatever else is appropriate).
To help figure out what the problem is exactly we need the output from the following commands (as a start).
What does rpm -qa python\* say?
What does which -a python say?