I have tried every answer I can find to install PyMySQL for example see below:
sudo pip install PyMySQL
Downloading/unpacking PyMySQL
Downloading PyMySQL-0.7.11-py2.py3-none-any.whl (78kB): 78kB downloaded
Installing collected packages: PyMySQL
Successfully installed PyMySQL
But still no luck, it just returns the following when .py script is run which uses pymysql:
python UpworkCode.py
Traceback (most recent call last):
File "UpworkCode.py", line 2, in <module>
import PyMySQL
ImportError: No module named PyMySQL
Please could someone help me out of this pit of despair thanks
Use import pymysql instead!In fact, the correct package name is pymysql, not PyMYSQL!
Remember,pip is not case sensitive, but python is!
Related
I'm trying to use the python MySQL connector on my Raspberry PI but I'm getting this error as soon as I add the import statement to the script.
import os
import mysql.connector
The same happens when I try to import only parts of it.
import os
from mysql.connector import connect, Error
The error:
Traceback (most recent call last):
File "script.py", line 2, in <module>
import mysql.connector
File "/home/pi/.local/lib/python2.7/site-packages/mysql/connector/__init__.py", line 53, in <module>
from .connection import MySQLConnection
File "/home/pi/.local/lib/python2.7/site-packages/mysql/connector/connection.py", line 442
f"This connection is using {tls_version} which is now "
I used PIP to install the connector ...
pip install mysql-connector-python
... and also already tried to force-reinstall it:
pip install --upgrade --force-reinstall mysql-connector-python
This problem appears to be caused by using the default Raspbian install of Python, which is Python 2.7.
Use Python 3 instead. It is also installed on Raspbian. Use python3 and pip3 in place of python and pip.
I would like to connect to Oracle database from VS Code. In the Terminal I ran
pip install cx_oracle
and it stated:
Requirement already satisfied: cx_oracle in c:\python38\lib\site-packages (8.1.0)
but when I ran the code: import cx_Oracle it returned:
---------------------------------------------------------------------------
ModuleNotFoundError Traceback (most recent call last)
<ipython-input-8-1e79d9171cfb> in <module>
----> 6 import cx_Oracle
ModuleNotFoundError: No module named 'cx_Oracle'
In Extensions in VS Code I entered cx_Oracle in the search bar and it showed No extensions found.
How to use 'cx_Oracle' in VS Code?
Update:
Changed the interpreter to python38 as seen in screenshot below but didn't seem to work.
Try to download the whl file of cx-Oracle from here.
For example download the file to F:/file.
Then use command pip install F:/file/cx_Oracle-8.1.0-cp38-cp38-win_amd64.whl to install.
[UPDATE] - An antivirus software installed on my computer was causing the issue. Disabling it solved the problem :)
I'm getting a weird error when I try to import psycopg2.
Using Python 3.7.7
Downloaded psycopg2 using pip
$ python -m pip install psycopg2
Collecting psycopg2
Using cached psycopg2-2.8.5-cp37-cp37m-win_amd64.whl (1.1 MB)
Installing collected packages: psycopg2
Successfully installed psycopg2-2.8.5
import psycopg2
if name =="main":
print("Hello World!")
Running the code gives me the below error:
$ python test2.py Traceback (most recent call last): File "test2.py", line 1, in <module>
import psycopg2
File "C:\Users\blah\AppData\Local\Programs\Python\Python37\lib\site-packages\psycopg2\__init__.py", line 51, in <module>
from psycopg2._psycopg import ( # noqa ImportError: dynamic module does not define module export function (PyInit__psycopg)
Have tried installing pscopg2-binary instead. Still getting the same error.
Any idea?
I've looked at every post concerning this issue. I've (re)installed PostgreSQL on my Mac using Homebrew. I've adjusted the PATH variables. I've installed/uninstalled/reinstalled psycopg2. I've watched videos. Still, I cannot figure out how psycopg2 can be squarely on my machine and yet unavailable to my database and, by extension, my Flask application. Here is my latest error message with confirmation that, yes, it's there and, no, I can't use it (or Python won't acknowledge it). Any help would be greatly appreciated. This is day two of this nonsense.
RCD#Ryans-MacBook-Pro ~ - $ sudo pip3 install psycopg2
Password:
Requirement already satisfied: psycopg2 in /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages (2.7.5)
RCD#Ryans-MacBook-Pro ~ - $ python
>>> import psycopg2
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/psycopg2/__init__.py", line 50, in <module>
from psycopg2._psycopg import ( # noqa
ImportError: No module named _psycopg
So you've installed psycopg2 into Python 3.7 but tried to use it in Python 2.7.
python and pip must be synchronized; the simplest way to do that is to run python -m pip instead of pip, that way you guarantee that you use correct pip for your current python.
Please remember that sudo uses a different $PATH so you'd better set the full path to your python:
sudo /Library/Frameworks/Python.framework/Versions/2.7/bin/python -m pip install -U psycopg2-binary
I have successfully installed PyMySQL in my Ubuntu 16.04 OS using pip command:
debarati#debarati-hp:~$ pip install PyMySQL
Collecting PyMySQL
Downloading PyMySQL-0.8.0-py2.py3-none-any.whl (83kB)
100% |████████████████████████████████| 92kB 159kB/s
Installing collected packages: PyMySQL
Successfully installed PyMySQL-0.8.0
Still when I am trying to execute a Python file called view_rows.py , it's giving the following error:
debarati#debarati-hp:~$ python view_rows.py
Traceback (most recent call last):
File "view_rows.py", line 5, in <module>
import PyMySQL
ModuleNotFoundError: No module named 'PyMySQL'
But, this does not give any error:
debarati#debarati-hp:~$ import PyMySQL
This is my Python version:
debarati#debarati-hp:~$ python -V
Python 3.6.3 :: Anaconda custom (64-bit)
The package name is "PyMySQL"; you use the package name to install it. To use the installed package, you need to use the module name, which may not be the same. In this case, the module is named "pymysql" (all lower-case).
The import should be import pymysql.
https://pymysql.readthedocs.io/en/latest/py-modindex.html