1

I am trying to create a sample python program which needs to connect to MySQL database.

import mysql.connector 

# opens the file file.txt in read mode
fileptr = open("sample-table","r")  

if fileptr:  
    print("file is opened successfully") 

#running a for loop   
for i in fileptr:  
    print(i) # i contains each line of the file 

#closes the opened file  
fileptr.close()

But I am getting this error

Traceback (most recent call last):
  File "check-db.py", line 1, in <module>
    import mysql.connector 
ModuleNotFoundError: No module named 'mysql'

It looks like the required module is not present. Is it possible to include and install the module without root access?

3
  • maybe this this helps you pip.pypa.io/en/stable/installing Commented Feb 3, 2019 at 7:44
  • @markkeven, I am able to download it but installing it requires root privileges. I am looking for the solution to include mysql without root Commented Feb 3, 2019 at 7:50
  • Isn't that what virtual environments are for? You should be able to use them to install stuff locally without requiring additional privileges. Commented Feb 3, 2019 at 10:04

1 Answer 1

1

install pip like this:

apt install python-pip  #python 2
apt install python3-pip #python 3

Try install mysql using this command:

pip install pymysql
Sign up to request clarification or add additional context in comments.

9 Comments

I am getting the error as [username@archlinux ~]$ pip install pymysql bash: pip: command not found
Then use this: python -m pip install pymysql
Thanks for the reply. I am again getting the error as /usr/bin/python: No module named pip
Tried installing pip, but again error sudo pacman -S python3-pip error: target not found: python3-pip
what about sudo pacman -S python2-pip? are you using python3 or 2 ?
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.