Forums

ModuleNotFoundError: No module named 'pymysql'

hello, why am i getting this error if I already installed the module: ModuleNotFoundError: No module named 'pymysql'

(testing) 08:05 ~ $ python
Python 3.7.5 (default, Nov 14 2019, 22:26:37) 
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import pymysql
>>> dir(pymysql)
['BINARY', 'Binary', 'Connect', 'Connection', 'DATE', 'DATETIME', 'DBAPISet', 'DataError', 'DatabaseError', 'Date', 'DateFromTicks', 'Error', 'FIELD_TYPE', 'IntegrityError', 'Interfa
ceError', 'InternalError', 'MySQLError', 'NULL', 'NUMBER', 'NotSupportedError', 'OperationalError', 'PY2', 'ProgrammingError', 'ROWID', 'STRING', 'TIME', 'TIMESTAMP', 'Time', 'TimeFr
omTicks', 'Timestamp', 'TimestampFromTicks', 'VERSION', 'VERSION_STRING', 'Warning', '__all__', '__builtins__', '__cached__', '__doc__', '__file__', '__loader__', '__name__', '__pack
age__', '__path__', '__spec__', '__version__', '_auth', '_compat', 'apilevel', 'charset', 'connect', 'connections', 'constants', 'converters', 'cursors', 'err', 'escape_dict', 'escap
e_sequence', 'escape_string', 'get_client_info', 'install_as_MySQLdb', 'optionfile', 'paramstyle', 'protocol', 'sys', 'thread_safe', 'threadsafety', 'times', 'util', 'version_info']
>>>

I have a custom module that stores my custom functions, and in it I have the import line:

from flask import Flask, request
from werkzeug.utils import secure_filename
import os
import pymysql

When I run this file in the console, I see all imported modules, except pymysql, and that is when I see the error. Moreover, here is the output of the dir():

Traceback (most recent call last):
File "/home/najibfahs/testing/custom_functions.py", line 4, in <module>
import pymysql
ModuleNotFoundError: No module named 'pymysql'
>>> dir()
['Flask', '__annotations__', '__builtins__', '__doc__', '__file__', '__loader__', '__name__', '__old_modules', '__package__', '__spec__', '_pa_run', 'os', 'request', 'secure_filenam
e', 'sys', 'traceback', 'unicode_literals']
>>>

what is happening???

How do you run it?

same problem

That just looks like you have not installed the module into the Python version that you are using to run your code: https://help.pythonanywhere.com/pages/InstallingNewModules/