在 Pydev Eclipse 中使用 MySQL
我正在尝试通过 Pydev Eclipse 使用 python 访问 MySQL 数据库。我已经安装了从 python 访问 Mysql 所需的文件,只有当我在 Python IDLE 环境中编写代码并从命令提示符运行它时,我才能访问数据库。但是我无法从 Pydev 运行我的应用程序。
当我使用这个“import MysqlDB”时,我收到一个错误,但在 IDLE 中没有错误,并且我的代码运行非常顺利。 有谁知道问题出在哪里? 谢谢
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我遇到了同样的问题,发现这个链接帮助我解决了它。 https://bohr.wlu.ca/cp363/notes/implementation/connectingPython。 php
从那里我能够导入 mysql.connector 并连接到安装在我的本地主机上的数据库
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
如果连接器在 IDLE 中工作但在 PyDev 中不起作用。打开 Eclipse 首选项,打开 PyDev 目录并转到解释器屏幕。删除解释器并从计算机上的位置(通常是 C 驱动器)再次添加它。关闭并重新加载 Eclipse,现在它应该可以工作了。
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.
如果将来 URL 发生更改,则发布答案
从 Eclipse 中,选择 Window / Preferences / PyDev / Interpreters / Python Interpreter,单击 Manage with pip 并输入命令:
install mysql-connector-python
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