[英]How to import (mysql-connector-2.2.9) module package from local directory in python script
我在我的脚本中使用了这个 mysql-connector-2.2.9 模块,使用了 mysql 连接器。 now i need to execute the script in user system without installing module.user has installed only python.i have downloaded this package and stored locally but not able to import the module using sys.path.append
this function. 我收到类似未安装模块的错误。
import sys
sys.path.append("C:/newfolder/mysql-connector-2.2.9")
from mysql-connector-2.2.9 import mysql.connector
我想知道如何在本地导入这个 package。
我试过这个,它对我有用......
from pathlib import Path
import sys
path_root = Path('C:/newfolder/mysql-connector-2.2.9').parents[2]
sys.path.append(str(path_root))
from mysql-connector-2.2.9 import mysql.connector
但是你必须输入路径。我使用了这个页面https://fortierq.github.io/python-import/如果代码没有帮助,也许你可以在这里找到一些东西。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.