I am very new in Python as wel as in backend develpoment. I want to connect my python code with database so I installed mysql-connector-python using C:\Users\CCU-012\AppData\Local\Programs\Python\Python37\Scripts>python -m pip install mysql-connector-python but when I use import mysql.connector in my python code I am getting error Traceback (most recent call last):
File "C:/Users/CCU-012/PycharmProjects/array/demo_mysql_connection.py", line 1, in <module>
import mysql.connector
ModuleNotFoundError: No module named 'mysql'
You've installed the module globally, but your project is using a virtualenv (as evident from the "Python 3.7 (array)" text in PyCharm's status bar).
Install the module within the virtualenv; the easiest way to do that through PyCharm is to open the Python Console (4th tab at the bottom there) and
pip install mysql-connector-python
Related
I'm using python 2.7.18 on Windows, and i saw that ipaddress library was exclusively for python3 so i installed py2-ipaddress using pip. When i ran pip list into cmd, it shows py2-ipaddress as installed, but when i try import ipaddress into a python file i get this
Traceback (most recent call last):
File "C:/Users/x/Downloads/main (2).py", line 1, in <module>
import ipaddress
ImportError: No module named ipaddress
Why i can't import it?
EDIT :
Actually, ipaddress works fine on python2.7.x, or it should, i installed now ipaddress using pip install ipaddress, it shows as installed when running pip show ipaddress but i still can't import it
#Matthias was right. It seems that my pip doesn't work properly, or i don't know how to use it properly. One quick fix, if you're running pycharm or any IDE with a built-in terminal is to install the module via IDE's terminal using pip install <module>.
I am trying to open mysql.connector in the REPL and am getting
>>> import mysql.connector
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'mysql'
I have run the following to create a virutal environment, activate it, and install the database connector.
python -m venv venv
source venv/bin/activate
pip install myqsql-connector
the contents of venv/lib64/python3.10/site-packages/
certifi mysql requests-2.26.0.dist-info
certifi-2021.10.8.dist-info mysql_connector-2.2.9-py3.10.egg-info setuptools
charset_normalizer mysqlx setuptools-57.4.0.dist-info
charset_normalizer-2.0.7.dist-info pip tests
_distutils_hack pip-21.3.1.dist-info urllib3
distutils-precedence.pth pipreqs urllib3-1.26.7.dist-info
docopt-0.6.2-py3.10.egg-info pipreqs-0.4.11.dist-info yarg
docopt.py pkg_resources yarg-0.1.9.dist-info
idna __pycache__
idna-3.3.dist-info requests
Why can I not import the module if it is in the packages?
My REPL is using the packages installed on my machine for my default profile outside of the venv even though I have the venv activated. and my python binary is the one in my venv
which python3
/home/dyl/Development/minesweeperautomation/minesweeper_api_flask/venv/bin/python3
I once had the problem that it was installed to another python version. I would recommend to check that.
Some also claim that it is due to the version of the lib:
https://www.edureka.co/community/77378/modulenotfounderror-no-module-named-mysql
I use this version on my machine and it runs just fine:
mysql-connector-python==8.0.22
The following command was executed in the tests directory inside the development version of django
./runtests.py
Traceback (most recent call last):
File "./runtests.py", line 26, in <module>
from django.test.utils import NullTimeKeeper, TimeKeeper, get_runner
ImportError: cannot import name 'NullTimeKeeper'
I am using python 3.8 and am following the instructions for contributing to django from https://docs.djangoproject.com/en/3.1/intro/contributing/ where I have resolved all errors up to this point. Could someone explain what I would have to do as I already ran
python3.8 -m pip install -r requirements/py3.txt
in my virtual environment that I created using
python3.8 -m venv /path/to/venv
Never mind I found the answer. It is solved by configuring python3 to 3.8 version instead of 3.6 in the following link configuring python and then executing all of this in the virtual environment.
Can someone please help me connecting python to mysql. I am new to Ubuntu OS and don't know much about it. I use PyCharm IDE.
I installed mysql on my system and also installed the mysql.connector module correctly( pip3 isntall mysql-connector-python )
But it fails t connect and gives the error as follows:
mysql.connector.errors.NotSupportedError: Authentication plugin 'caching_sha2_password' is not supported
When I run the same code in VS code I get an error which reads:
Traceback (most recent call last):
File "/home/velocity-linux/Desktop/Main Folder/Project.py", line 1, in
import mysql.connector
ImportError: No module named mysql.connector
Please tell what can I do
The code which I use for connection is:
mydb1 = mysql.connector.connect(host="localhost", user="root",
passwd="home#253144", database="school")```
[1]: https://i.stack.imgur.com/aGXKQ.png
It's likely you're getting the error in Visual Studio Code because you're using a virtual environment in PyCharm.
The PyCharm error is the error you should be focusing on.
What imports are you using for this project? The error seems to be caused by an unsupported library, I am unsure if this is from your script or a script from the mysql-connector library.
Have you tried reinstalling mysql-connector with both python -m pip uninstall mysql-connector and python -m pip install mysql-connector?
I have python2.7 and python 2.6 installed in my VM and I pip install some libraries such as:
sudo pip install gsconfig
The installation is successful and I can see that the package is installed by:
pip list
My default system's python is 2.6. In the terminal I enter python and try to import the library as:
python
import gsconfig
And then I get an error:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named gsconfig
I also tried with python2.7 as:
python2.7
import gsconfig
I get the same error message. I can not understand why this is happening as I don't have with other packages this issue (e.g. simplejson).
Can it be that the location of the package is different?
When I try this:
which gsconfig
I get:
/usr/bin/which: no gsconfig in (/usr/lib64/qt-3.3/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin)
EDITED
Also when I go to the site-packages folder of python2.7 I can see that the package is installed.
It looks like the package name is not gsconfig, but is something else.
Looking at the documentation, I think it's geoserver.