Hossein
Hossein

Reputation: 41921

Using MySQL in Pydev Eclipse

I am trying to access a MySQL database with python through Pydev Eclipse. I have installed the necessary files to access MysQL from python and I can access the database only when I write code in Python IDLE environment and run it from command prompt. However I am not able to run my applications from Pydev.

when I use this "import MysqlDB" i get an error, but in IDLE no errors and my code runs very smoothly. Does anyone know were the problem is? Thanks

Upvotes: 2

Views: 7115

Answers (3)

Komal Prasad
Komal Prasad

Reputation: 125

Posting Answer in case URL changed in future

From Eclipse, choose Window / Preferences / PyDev / Interpreters / Python Interpreter, click on Manage with pip and enter the command:

install mysql-connector-python

Upvotes: 0

Christine Watts
Christine Watts

Reputation: 21

I was having this same problem and found this link which helped me resolve it. https://bohr.wlu.ca/cp363/notes/implementation/connectingPython.php

From there I was able to import mysql.connector and connect to the database installed on my localhost

import mysql.connector
import getpass

pswd = getpass.getpass(prompt='Enter database password for root user:')
dbCnx = mysql.connector.connect(user='root', password=pswd)

Here is a screen shot of how I was able to execute the pip install

Upvotes: 2

Rangbaz
Rangbaz

Reputation: 1

If the connector works in the IDLE but not in PyDev. Open Eclipse preferences, open PyDev directory and go to interpreter screen. Remove the interpreter and add it again from the location on your computer (Usually C drive). Close and reload Eclipse and now it should work.

Upvotes: 0

Related Questions