Mysql Connector issue in Python - python

I have installed MySQL connector for python 3.6 in centos 7
If I search for installed modules with below command
it's showing as below
pip3.6 freeze
mysql-connector==2.1.6
mysql-connector-python==2.1.7
pymongo==3.6.1
pip3.6 search mysql-connector
mysql-connector-python (8.0.6) -MYSQL driver written in Python
INSTALLED: 2.1.7
LATEST: 8.0.6
mysql-connector (2.1.6) - MySQL driver written in Python
INSTALLED: 2.1.6 (latest)
MySQL connector installed.But when trying to run the program using MySQL connector then its showing error no module installed MySQL connector.I am using MariaDB 10.0
python3.6 mysql1.py
Traceback (most recent call last):
File "mysql1.py", line 2, in
import mysql.connector as mariadb
File "/root/Python_environment/my_Scripts/mysql.py", line 2, in
import mysql.connector
ModuleNotFoundError: No module named 'mysql.connector'; 'mysql' is not a package
can any one know how to resolve

You must not name your script mysql.py — in that case Python tries to import mysql from the script — and fails.
Rename your script /root/Python_environment/my_Scripts/mysql.py to something else.

This is the problem I faced in Environment created by python.Outside the python environment i am able to run the script.Its running succefully.In python environment i am not able run script i am working on it.if any body know can give suggestion on this

Related

MySQL connection to Python in Spyder IDE says module not found?

So I'm trying to connect Python and MySQL in Spyder IDE to complete my school project, the error its giving me is:
File "C:\Users\aakar\AppData\Local\Programs\Spyder\pkgs\spyder_kernels\py3compat.py", line 356, in compat_exec
exec(code, globals, locals)
File "c:\users\aakar\.spyder-py3\databaseintegrationpractice\test1.py", line 1, in <module>
import mysql.connector as sqlcon
ModuleNotFoundError: No module named 'mysql'
I tried to use a youtube tutorial and my textbook too but everything gives me this error, I have it installed using pip.
On running pip3 install mysql-connector I get:
Requirement already satisfied: mysql-connector in c:\users\aakar\appdata\local\programs\python\python310\lib\site-packages (2.2.9)
Verify if you are installing packages in same environment you are using to run script. mysql-connector is a bit older, deprecated, and replaced by mysql-connector-python. If you want to stick with same, try downgrading your python version. I'm using it with python 3.8.8 and it is working fine.

pyodbc module not found

I am facing a situation where modules like pyodbc which used to work earlier (3 weeks back) are not working anymore in my laptop. I am repeatedly getting Module not found error.
To resolve it by myself, I have gone through similar articles in stack overflow and implemented some suggestions like this. Yet the issue still persists. My machine (Windows 10) has only one python version (python v3.7.2), and I have never created any virtualenv.
C:\Users\Kris\eclipse-workspace\SQLPyODBC>conntest.py --serverName "IDEA-PC\SQLEXPRESS" --name "SampleStore" --trustedConn "yes"
Traceback (most recent call last):
File "C:\Users\Kris\eclipse-workspace\SQLPyODBC\conntest.py", line 1, in <module>
import pyodbc
ModuleNotFoundError: No module named 'pyodbc'
The referenced package is available under C:\Users\Kris\AppData\Local\Programs\Python\Python37-32\Lib\site-packages directory. Also the path of python interpreter in eclipse IDE (PyDev) is pointing to correct python executable path.
Just to test, I have downloaded pymssql module, and guess what... it is also showing the same error message. I have uninstalled and re-installed packages. No solution.
If you're using Anaconda install using following code,
conda install -c anaconda pyodbc
Before importing pyodbc in python, you should install the module by using pip directly from cmd.
pip install pyodbc
if that does not work, try using pip to uninstall and install it again after a restart (Or kill all python related tasks). Hope it works

MySQLdb is hard to locate

I use this tutorial text as an example, there are others:
#!/usr/bin/python
import MySQLdb
If it produces the following result, then it means MySQLdb module is not installed −
Traceback (most recent call last):
File "test.py", line 3, in <module>
import MySQLdb
ImportError: No module named MySQLdb
To install MySQLdb module, use the following command −
For Ubuntu, use the following command -
$ sudo apt-get install python-pip python-dev libmysqlclient-dev
I have gone trough these steps, more or less as described above.
Problem is that the subdirectory "python" does not exist under /usr/bin/
in my file system. I run Linux Mint 18.3. Python 2.7 seems to be the native version installed in Mint (used for several purposes), but I have also installed Python 3.6.4 and wish to use this for development purposes.
Does anyone know in which directory I could expect to find MySQLdb?
Since #!/usr/bin/python is non existent I wonder - has MySQLdb been properly installed? If it has, I have not after several efforts succeded in locating it.

Installing MySQLDB on Python 2.7.3 under CentOS

I need to install Python 2.7 on a machine, from source, alongside the existing version on the machine (2.4). I have compiled and installed Python successfully, but when I try to run a script calling the MySQLDB module, it throws the following error:
[root#the-node1 bin]# interactive_recording_archive.py
Traceback (most recent call last):
File "/usr/local/bin/interactive_recording_archive.py", line 8, in <module>
import MySQLdb as mdb
ImportError: No module named MySQLdb
I have tried installing MySQLDB using the easy-install script but this fails to find any module by that name. I have MySQL installed and working on the machine.
What am I doing wrong?
The package is called MySQL-python:
easy_install MySQL-python
Do check the installation requirements; you have python and setuptools, but you need the mysql-devel package too.

ImportError : No module named _sqlite3 on GAE

While trying to start local Google App Engine (v1.3.8) Server on my Fedora 14 with Python 2.5 (installed from source) I get the importerror
ImportError: No module named _sqlite3
I have the following package installed - sqlite, sqlite-devel, python2.5, python2.7. I did some Google and it looks like this error comes when there is no C binding for sqlite. However, since I have both the sqlite and sqlite-devel installed C bindings should be present. I get this same error when I do
import sqlite3
on Python console. What possibly can I do to resolve this error?
Install sqlite-devel and rebuild Python.
This works equally on Ubuntu 10.10 using
$ sudo aptitude install sqlite3 libsqlite3-dev
and rebuilding Python.

Categories