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
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)
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.
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
精彩评论