Python 3.5 MySQL Connector - python

I'm somewhat new to python and figured playing around with mySQL databases would be a good idea.
Now the error I am having is simply installing the mySQL connector. I have tried on both my Windows PC, and now here on my mac.
Each time I download the connector and install it, all goes ahead and installs, yet when I import mysql.connector I receive a traceback, ImportError saying that mysql is not a package.
I've been searching the internet trying to find information or ways to help this, but non have been successful.
It should be noted that I have restarted my computer, still with no success.
I installed python 3.5 via the official python website, and the mysql connector via the official mysql website.

You need to provide more information. Could tell us how you installed the connector? easy_install? pip? Are you on Python2 or Python3. On windows are you using the official Python installer or did you install Python via Cygwin?
Typically, after you install a Python package, you'll find it in the following location on Mac/Linux:
/usr/lib/python<version>/site-packages/
On Windows you'll find site-packages under the Python directory in C:\Program Files.
Which MySQL connector have you installed (there are several)?
Also, ensure you've installed the connector for the correct Python version. If you're using Python2, but are using pip3 to install the package, then pip will install it to the python3 site-packages and you won't be able to access it from Python2.

Related

Problem In Installing MySql Connector for Python

Hi I have just started learning sql language in MySql and have completed basic level of the language.
Now I want to access mysql databases from python. I got to know that we need to install MYSQL_Connector for Python to achieve this goal.
But, When i tried to install python-connector for mysql it gives an error that python version not found/
I tried to install it but it failed even though i have python 3.11.0 installed on my pc.
I tried to Reinstall both python and mYsql but it Doesn't worked.
Please help me with this problem
With the error that you've described, it seems that you're using the Windows MSI installer. But there's an issue in the Connector/Python 8.0.31 installer for Python 3.11, that will be fixed in the upcoming release, see https://bugs.mysql.com/bug.php?id=108911
Meanwhile, the solution is performing the installation using the wheel package, actually it's the recommended way of installing Connector/Python.
As described by Oscar in the bug report above, you can run:
Console (CMD or PowerShell)
--------------------------------
> pip install mysql-connector-python
or
> python -m pip install mysql-connector-python

NoSuchModuleError: sqlalchemy-access

I have a script that queries and updates an access table. I've used it successfully on my computer, but after installing anaconda and spyder on a different computer (same versions as the original installation on the original computer) it doesn't work on the new computer.
To clarify: I installed the package using
pip install sqlalchemy-access
on the anaconda prompt, and when running
pip list|findstr access
I get
sqlalchemy-access 1.1.3. However, when I run the script in spyder I get the NoSuchModuleError: Can't load plugin: sqlalchemy.dialects:access.pyodbc error.
Do you have several different python versions on your computer?
Maybe installing the package with
pip3 install sqlalchemy-access
Could fix this.
I don't know why, but after trying multiple times, I checked again (pip list|findstr access) and found that the installation of sqlalchemy-access, which I managed to find before in the anaconda prompt, has disappeared. I installed it again (for the third or fourth time) and now it works.

Python modules not found even though installed

Python Version: 3.2.3
I've spent hours working on this issue and I'm still scratching my head furiously out of confusion. I'm testing an application built with python in a windows 7 device. I went and installed python and its dependencies. I also installed pip and the following packages: mysql-connector, and mysqlclient. However, when I tried running the script that imports mysql.connector, the debugger returns:
import mysql.connector
ImportError: No module named mysql.connector
I went and check the list of packages via pip list and saw that the packages we're definitely installed. They are listed as:
mysql-connector-python 8.0.26
mysqlclient 2.0.3
So, I compared this with my windows 10 device that has the script running without issues and saw that the packages were also installed the same way. I thought there were no issues in the package installation.
However, when I checked the python modules in help("modules"), I found something. The mysql and pip are not listed in the windows 7 device whereas, in my personal device, they were there.
I tried uninstalling and reinstalling the packages, yet the issue remains. For some reason, python is not able to detect the packages. I also tried to upgrade the pip via python -m pip install --upgrade pip and as expected, the python can't find the pip. I'm honestly confused at this point. Am I missing something?
UPDATE
It might be worth noting that, since my python version has no pip, I had to install it and copy its path to the system environment variables manually. Could it be connected the source of issue?

clean up python versions mac osx

I tried to run a python script on my mac computer, but I ended up in troubles as it needed to install pandas as a dependency.
I tried to get this dependency, but to do so I installed different components like brew, pip, wget and others including different versions of python using brew, .pkg package downloaded from python.org.
In the end, I was not able to run the script anyway.
Now I would like to sort out the things and have only one version of python (3 probably) working correctly.
Can you suggest me the way how to get the overview what I have installed on my computer and how can I clean it up?
Thank you in advance
Use brew list to see what you've installed with Brew. And Brew Uninstall as needed. Likewise, review the logs from wget to see where it installed things. Keep in mind that MacOS uses Python 2.7 for system critical tasks; it's baked-into the OS so don't touch it.
Anything you installed with pip is saved to the /site-packages directory of the Python version in which you installed it so it will disappear when you remove that version of Python.
The .pkg files installed directly into your Applications folder and can be deleted safely like any normal app.

How to install pymssql to Python 3.4 rather than 2.7 on Ubuntu Linux?

I'm not overly familiar with Linux and am trying to run a Python script that is dependent upon Python 3.4 as well as pymssql. Both Python 2.7 and 3.4 are installed (usr/local/lib/[PYTHON_VERSION_HERE]). pymssql is also installed, except it's installed in the Python 2.7 directory, not the 3.4 directory. When I run my Python script (python3 myscript.py), I get the following error:
File "myscript.py", line 2, in
import pymssql
ImportError: No module named 'pymssql'
My belief is that I need to install pymssql to the Python 3.4 folder, but that's my uneducated opinion. So my question is this:
How can I get my script to run using Python 3.4 as well as use the pymssql package (sorry, probably wrong term there)?
I've tried many different approaches, broken my Ubuntu install (and subsequently reimaged), and at this point don't know what to do. I am a relative novice, so some of the replies I've seen on the web say to use ENV and separate the versions are really far beyond the scope of my understanding. If I have to go that route, then I will, but if there is another (i.e. easier) way to go here, I'd really appreciate it, as this was supposed to just be a tiny thing I need to take care of but it's tied up 12 hours of my life thus far! Thank you in advance.
It is better if when you run python3.4 you can have modules for that version.
Another way to get the desire modules running is install pip for python 3.4
sudo apt-get install python3-pip
Then install the module you want
python3.4 -m pip install pymssql
The easiest way is to use virtual environments instead of system paths or environment scripts. See official Python package installation guide.
All you need to do is to
# Create fresh Python environemnt
virtualenv -p python3.4 my-venv
# Activate it in current shell
source my-venv/bin/activate
# Install packages
pip install mysqlclent
Note that mysqlclient is Python 3.x compatible version.

Categories