![]() |
Debian 10 Buster Environment - Python 3.x (MariaDB 10.4.21) | Working Connector? - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: Web Scraping & Web Development (https://python-forum.io/forum-13.html) +--- Thread: Debian 10 Buster Environment - Python 3.x (MariaDB 10.4.21) | Working Connector? (/thread-35582.html) |
Debian 10 Buster Environment - Python 3.x (MariaDB 10.4.21) | Working Connector? - BrandonKastning - Nov-19-2021 Hello again everyone! Admins, Mods (Thank you again for the prior threads, btw). I am now up against parsing a huge amount of Data and the only way to do so is by learning Python. I figure I would start with this thread; as I am at a stuck point with MySQL Connectors working with Debian 10 Buster and Python 3.x (No matter the solution; I cannot seem to get it working). Even the code from Oreilly Web Scraping with Python didn't work (I bought the Book). Continuing; I feel the best way to resolve this is to use a base line foundational block found from W3 Schools here https://www.w3schools.com/python/python_mysql_getstarted.asp Code found in that block for Python Connector to MySQL is : import mysql.connector mydb = mysql.connector.connect( host="localhost", user="yourusername", password="yourpassword" ) print(mydb)This is what happens when I run it: python3 w3.mysql.python.connector.py Traceback (most recent call last): File "w3.mysql.python.connector.py", line 1, in <module> import mysql.connector File "/home/brandon/.local/lib/python3.5/site-packages/mysql/connector/__init__.py", line 54, in <module> from .connection import MySQLConnection File "/home/brandon/.local/lib/python3.5/site-packages/mysql/connector/connection.py", line 451 f"This connection is using {tls_version} which is now " ^ SyntaxError: invalid syntax RE: Debian 10 Buster Environment - Python 3.x (MariaDB 10.4.21) | Working Connector? - snippsat - Nov-19-2021 You should upgrade your Python version they have dropped support for Python 3.5 as you use now,need at least Python 3.6 preferably 3.9 -->. f-sting(really good) that it fails now was one the update that was new in Python 3.6. Works like this. >>> tls_version = 2.2 >>> f"This connection is using {tls_version} which is now " 'This connection is using 2.2 which is now ' RE: Debian 10 Buster Environment - Python 3.x (MariaDB 10.4.21) | Working Connector? - ghoul - Nov-19-2021 Works for me with: mysql-connector-python==8.0.27And mariadb version 10.3.31 mysql Ver 15.1 Distrib 10.3.31-MariaDB, for debian-linux-gnu (x86_64) using readline 5.2Not sure this is relevant but all this in on Ubuntu 20.04.3 LTS. It confuses me how TLS is getting into all this... RE: Debian 10 Buster Environment - Python 3.x (MariaDB 10.4.21) | Working Connector? - snippsat - Nov-19-2021 (Nov-19-2021, 12:29 PM)ghoul Wrote: Not sure this is relevant but all this in on Ubuntu 20.04.3 LTS.Ubuntu 20.04 comes with Python3 by default,then version is Python 3.8.5. Then it will work,the problem is as mention that OP use Python 3.5(dropped support bye a lot of packages now). RE: Debian 10 Buster Environment - Python 3.x (MariaDB 10.4.21) | Working Connector? - BrandonKastning - Nov-20-2021 snippsat, Thank you sir! python3 --version Python 3.5.3 I am looking into an upgrade as I type this! I will report the working commands that brings Python to a new 3.7/3.8/3.9 (Shooting for latest; 3.9.x). It did not cross my mind that the python version was a factor in my problem(s) with Python and MariaDB. (This would deffinetly make Python more fun to learn; having data storage). (Nov-19-2021, 11:43 AM)snippsat Wrote: You should upgrade your Python version they have dropped support for Python 3.5 as you use now,need at least Python 3.6 preferably 3.9 -->. RE: Debian 10 Buster Environment - Python 3.x (MariaDB 10.4.21) | Working Connector? - BrandonKastning - Nov-20-2021 ghoul, Perhaps it's because I posted the incorrect version on the thread / OP. I truly believed I was on Debian 10 Buster; however, after doing a lsb_release -a No LSB modules are available. Distributor ID: Debian Description: Debian GNU/Linux 9.13 (stretch) Release: 9.13 Codename: stretch I am using Debian 9.13 Stretch. Let's see what an upgrade does! Thank you both! I do know that I tested on Debian 10 also. Maybe that is why I thought I was still on it. I have formatted a couple times over the last 6 months fiddling with Python and MariaDB. (Nov-19-2021, 12:29 PM)ghoul Wrote: Works for me with: RE: Debian 10 Buster Environment - Python 3.x (MariaDB 10.4.21) | Working Connector? - BrandonKastning - Nov-20-2021 Is this the correct output for a working MySQL connector within Python 3.9.9? brandon@FireDragon:~/Python/sgml.bs4$ python w3.mysql.python.connector.py <mysql.connector.connection.MySQLConnection object at 0x7fb325cfcac0> brandon@FireDragon:~/Python/sgml.bs4$Updated to 3.9.9 from source per the following Blogs/Tutorials: Source Blogs/Tutorials (Google Found): https://tecadmin.net/how-to-install-python-3-9-on-debian-9/ https://stackoverflow.com/questions/62742398/python-mysql-importerror-no-module-named-mysql apt update apt upgrade apt install wget build-essential libreadline-gplv2-dev libncursesw5-dev \ libssl-dev libsqlite3-dev tk-dev libgdbm-dev libc6-dev libbz2-dev libffi-dev zlib1g-dev wget https://www.python.org/ftp/python/3.9.9/Python-3.9.9.tgz tar xzf Python-3.9.9.tgz cd Python-3.9.9 ./configure --enable-optimizations error output : fi WARNING: Value for scheme.headers does not match. Please report this to <https://github.com/pypa/pip/issues/10151> distutils: /usr/local/include/python3.9/UNKNOWN sysconfig: /root/Python-3.9.9/Include/UNKNOWN WARNING: Additional context: user = False home = None root = '/' prefix = None Looking in links: /tmp/tmpi00_y1xa Processing /tmp/tmpi00_y1xa/setuptools-58.1.0-py3-none-any.whl Processing /tmp/tmpi00_y1xa/pip-21.2.4-py3-none-any.whl Installing collected packages: setuptools, pip WARNING: Value for scheme.headers does not match. Please report this to <https://github.com/pypa/pip/issues/10151> distutils: /usr/local/include/python3.9/setuptools sysconfig: /root/Python-3.9.9/Include/setuptools WARNING: Value for scheme.headers does not match. Please report this to <https://github.com/pypa/pip/issues/10151> distutils: /usr/local/include/python3.9/pip sysconfig: /root/Python-3.9.9/Include/pip Successfully installed pip-21.2.4 setuptools-58.1.0 WARNING: Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager. It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv root@FireDragon:~/Python-3.9.9# root@FireDragon:~/Python-3.9.9# python3.9 -V Python 3.9.9 root@FireDragon:~/Python-3.9.9# pip3.9 -V pip 21.2.4 from /usr/local/lib/python3.9/site-packages/pip (python 3.9) nano -c /home/brandon/.bashrc added the following 2 lines and saved: alias python=python3.9 alias pip=pip3.9 brandon@FireDragon:~/Python/sgml.bs4$ python -V Python 3.9.9 brandon@FireDragon:~/Python/sgml.bs4$ ./w3.mysql.python.connector.py bash: ./w3.mysql.python.connector.py: Permission denied brandon@FireDragon:~/Python/sgml.bs4$ python w3.mysql.python.connector.py Traceback (most recent call last): File "/home/brandon/Python/sgml.bs4/w3.mysql.python.connector.py", line 1, in <module> import mysql.connector ModuleNotFoundError: No module named 'mysql' brandon@FireDragon:~/Python/sgml.bs4$ brandon@FireDragon:~/Python/sgml.bs4$ pip install mariadb Defaulting to user installation because normal site-packages is not writeable Collecting mariadb Downloading mariadb-1.0.8.zip (85 kB) |████████████████████████████████| 85 kB 503 kB/s Using legacy 'setup.py install' for mariadb, since package 'wheel' is not installed. Installing collected packages: mariadb Running setup.py install for mariadb ... done Successfully installed mariadb-1.0.8 WARNING: You are using pip version 21.2.4; however, version 21.3.1 is available. You should consider upgrading via the '/usr/local/bin/python3.9 -m pip install --upgrade pip' command. brandon@FireDragon:~/Python/sgml.bs4$ pip install mysql brandon@FireDragon:~/Python/sgml.bs4$ pip install mysql Defaulting to user installation because normal site-packages is not writeable Collecting mysql Downloading mysql-0.0.3-py3-none-any.whl (1.2 kB) Collecting mysqlclient Downloading mysqlclient-2.1.0.tar.gz (87 kB) |████████████████████████████████| 87 kB 708 kB/s Using legacy 'setup.py install' for mysqlclient, since package 'wheel' is not installed. Installing collected packages: mysqlclient, mysql Running setup.py install for mysqlclient ... done Successfully installed mysql-0.0.3 mysqlclient-2.1.0 WARNING: You are using pip version 21.2.4; however, version 21.3.1 is available. You should consider upgrading via the '/usr/local/bin/python3.9 -m pip install --upgrade pip' command. brandon@FireDragon:~/Python/sgml.bs4$ brandon@FireDragon:~/Python/sgml.bs4$ python w3.mysql.python.connector.py Traceback (most recent call last): File "/home/brandon/Python/sgml.bs4/w3.mysql.python.connector.py", line 1, in <module> import mysql.connector ModuleNotFoundError: No module named 'mysql' brandon@FireDragon:~/Python/sgml.bs4$ pip install mysql-connector Defaulting to user installation because normal site-packages is not writeable Collecting mysql-connector Using cached mysql-connector-2.2.9.tar.gz (11.9 MB) Using legacy 'setup.py install' for mysql-connector, since package 'wheel' is not installed. Installing collected packages: mysql-connector Running setup.py install for mysql-connector ... done Successfully installed mysql-connector-2.2.9 WARNING: You are using pip version 21.2.4; however, version 21.3.1 is available. You should consider upgrading via the '/usr/local/bin/python3.9 -m pip install --upgrade pip' command. brandon@FireDragon:~/Python/sgml.bs4$ RE: Debian 10 Buster Environment - Python 3.x (MariaDB 10.4.21) | Working Connector? - ghoul - Nov-20-2021 (Nov-20-2021, 03:57 AM)BrandonKastning Wrote: Is this the correct output for a working MySQL connector within Python 3.9.9? Yeah, that is what I get, presumably the expected/correct output. RE: Debian 10 Buster Environment - Python 3.x (MariaDB 10.4.21) | Working Connector? - BrandonKastning - Nov-20-2021 ghoul, Excellent Tim! Thank you! Alright! Time to roll up my sleeves for another go at Python Parsing to MariaDB! I will make threads to track my progress and share with the world my pain and successes provided I have any. Best Regards, Brandon (Nov-20-2021, 04:55 AM)ghoul Wrote:(Nov-20-2021, 03:57 AM)BrandonKastning Wrote: Is this the correct output for a working MySQL connector within Python 3.9.9? RE: Debian 10 Buster Environment - Python 3.x (MariaDB 10.4.21) | Working Connector? - BrandonKastning - Jan-04-2022 I am currently on my Debian 10 Buster machine. Currently has Python 3.7.x on it. I followed these directions that I used to get my Debian 9 Stretch up to 3.9.9 and realized I forgot a step. After line 16 on installation (above): After ./configure make altinstallthen nano ~/.bashrcadd the following lines: (source by Abhishek in comments of top URL in source links) which allows it to be the default for "python3" -- python 3.9.9 alias python=python3.9 alias pip=pip3.9Save and Exit! (Should be in root) ![]() |