在python虚拟环境中找不到mariadb_config命令,没有虚拟环境会起作用吗?

时间:2020-10-27 09:03:30

标签: python mysql pycharm mariadb fedora

我使用Fedora 32 WS,该系统是全新安装的。我想使用PyCharm进行开发,我是通过Flathub安装的。我也有一个带有MariaDB数据库的Synology NAS,我想在我的开发环境中访问它。使用Mysql Workbench可以正常工作。但是,如果我使用Python 3.8和virtualenv在PyCharm中启动一个新项目,并且想要安装mariadb pip install mariadb,则会收到错误消息:

Collecting mariadb
  Using cached mariadb-1.0.4.tar.gz (66 kB)

DEPRECATION: The -b/--build/--build-dir/--build-directory option is deprecated. pip 20.3 will remove support for this functionality. A possible replacement is use the TMPDIR/TEMP/TMP environment variable, possibly combined with --no-clean. You can find discussion regarding this at https://github.com/pypa/pip/issues/8333.
    ERROR: Command errored out with exit status 1:
     command: /home/jonathan/PycharmProjects/RSSDB/venv/bin/python -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pycharm-packaging/mariadb/setup.py'"'"'; __file__='"'"'/tmp/pycharm-packaging/mariadb/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' egg_info --egg-base /tmp/pip-pip-egg-info-dzg8lim2
         cwd: /tmp/pycharm-packaging/mariadb/
    Complete output (17 lines):
    /bin/sh: mariadb_config: Command not found
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/tmp/pycharm-packaging/mariadb/setup.py", line 26, in <module>
        cfg = get_config(options)
      File "/tmp/pycharm-packaging/mariadb/mariadb_posix.py", line 59, in get_config
        cc_version = mariadb_config(config_prg, "cc_version")
      File "/tmp/pycharm-packaging/mariadb/mariadb_posix.py", line 28, in mariadb_config
        raise EnvironmentError(
    OSError: mariadb_config not found.
    
    Please make sure, that MariaDB Connector/C is installed on your system.
    Either set the environment variable MARIADB_CONFIG or edit the configuration
    file 'site.cfg' and set the 'mariadb_config option, which should point
    to the mariadb_config utility.
    The MariaDB Download website at <https://downloads.mariadb.com/Connectors/c/>
    provides latest stable releease of Connector/C.
    ----------------------------------------
ERROR: Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.

如果我只是在本地终端上执行命令pip install mariadb,则没有错误,因此在我看来虚拟环境中缺少某些内容。 有人有主意吗?

1 个答案:

答案 0 :(得分:0)

在激活虚拟环境之前和之后执行以下命令

which mariadb_config

激活虚拟环境可能是在激活目录时将其从PATH中删除。

如果两个报告其找到的位置都相同,则检查一下什么

head -1 $(which mariadb_config)

如果mariadb_config恰好是python脚本,则可能是它有奇怪的shebang,并且在虚拟环境中运行时会出现“未找到”错误。

编辑

根据此处的来源:https://github.com/mariadb-corporation/mariadb-connector-python/blob/master/mariadb_posix.py#L49

“最简单”的解决方法是:

export MARIADB_CONFIG=/usr/bin/mariadb_config
pip install mariadb
相关问题