python - 导入错误 : No module named _mssql

标签 python pymssql

我在 OS 10.8.5 上运行 Python 2.7.2

尝试使用 pymssql,但出现以下错误:

  File "time_reporting.py", line 32, in <module>
    import pymssql
  File "/Users/xx/.virtualenvs/oracle/lib/python2.7/site-packages/pymssql.py", line 30, in <module>
    import _mssql, types, string, time, datetime, warnings
ImportError: No module named _mssql

我已经尝试使用 pip 和 brew 安装 mssql,但被告知没有该名称的包。文档似乎不包括安装。

编辑:

当我尝试 pip install pymssql 时,我得到:

Downloading/unpacking pymssql
  Running setup.py egg_info for package pymssql
    setup.py: platform.system() => 'Darwin'
    setup.py: platform.architecture() => ('32bit', '')
    setup.py: platform.linux_distribution() => ('', '', '')
    setup.py: platform.libc_ver() => ('', '')
    setup.py: Detected Darwin/Mac OS X.
        You can install FreeTDS with Homebrew or MacPorts, or by downloading
        and compiling it yourself.

        Homebrew (http://brew.sh/)
        --------------------------
        brew install freetds

        MacPorts (http://www.macports.org/)
        -----------------------------------
        sudo port install freetds

    setup.py: Not using bundled FreeTDS
    Traceback (most recent call last):
      File "<string>", line 16, in <module>
      File "/Users/xxx/.virtualenvs/oracle/build/pymssql/setup.py", line 181, in <module>
        if compiler.has_function('clock_gettime', libraries=['rt']):
      File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/distutils/ccompiler.py", line 808, in has_function
        objects = self.compile([fname], include_dirs=include_dirs)
      File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/distutils/ccompiler.py", line 616, in compile
        depends, extra_postargs)
      File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/distutils/ccompiler.py", line 412, in _setup_compile
        self.mkpath(os.path.dirname(obj))
      File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/distutils/ccompiler.py", line 931, in mkpath
        mkpath(name, mode, dry_run=self.dry_run)
      File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/distutils/dir_util.py", line 76, in mkpath
        "could not create '%s': %s" % (head, exc.args[-1]))
    distutils.errors.DistutilsFileError: could not create 'var': Permission denied
    Complete output from command python setup.py egg_info:
    setup.py: platform.system() => 'Darwin'

setup.py: platform.architecture() => ('32bit', '')

setup.py: platform.linux_distribution() => ('', '', '')

setup.py: platform.libc_ver() => ('', '')

setup.py: Detected Darwin/Mac OS X.

    You can install FreeTDS with Homebrew or MacPorts, or by downloading

    and compiling it yourself.



    Homebrew (http://brew.sh/)

    --------------------------

    brew install freetds



    MacPorts (http://www.macports.org/)

    -----------------------------------

    sudo port install freetds



setup.py: Not using bundled FreeTDS

Traceback (most recent call last):

  File "<string>", line 16, in <module>

  File "/Users/xxx/.virtualenvs/oracle/build/pymssql/setup.py", line 181, in <module>

    if compiler.has_function('clock_gettime', libraries=['rt']):

  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/distutils/ccompiler.py", line 808, in has_function

    objects = self.compile([fname], include_dirs=include_dirs)

  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/distutils/ccompiler.py", line 616, in compile

    depends, extra_postargs)

  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/distutils/ccompiler.py", line 412, in _setup_compile

    self.mkpath(os.path.dirname(obj))

  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/distutils/ccompiler.py", line 931, in mkpath

    mkpath(name, mode, dry_run=self.dry_run)

  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/distutils/dir_util.py", line 76, in mkpath

    "could not create '%s': %s" % (head, exc.args[-1]))

distutils.errors.DistutilsFileError: could not create 'var': Permission denied

所以我尝试 brew install freetds 我得到:

警告:freetds-0.91 已经安装,只是没有链接

这至少是有道理的,但我不知道如何解决它。

编辑:我已经链接了它,所以 brew install freetds 给出了它已经安装的消息,但是 pip install pymssql 仍然给出了上面的错误消息。

编辑:

export CFLAGS=-Qunused-arguments
export CPPFLAGS=-Qunused-arguments

pip uninstall MySQL-python
brew uninstall mysql
brew install mysql --universal
pip install MySQL-python

现在给我错误:

Traceback (most recent call last):
  File "time_reporting.py", line 34, in <module>
    import pymssql
ImportError: dlopen(/Users/xxx/.virtualenvs/oracle/lib/python2.7/site-packages/pymssql.so, 2): Symbol not found: _dbversion
  Referenced from: /Users/xxx/.virtualenvs/oracle/lib/python2.7/site-packages/pymssql.so
  Expected in: flat namespace
 in /Users/xxx/.virtualenvs/oracle/lib/python2.7/site-packages/pymssql.so

我以前有过并修复过,但我不记得我做了什么。

编辑:

好的,我已经重新安装了 32 位 oracle 并强制 Python 运行 32 位版本(我想。我真的不知道最后一句话是什么意思,但我认为我已经正确地按照说明进行操作).

无论如何,这是我现在的错误信息:

  File "time_reporting.py", line 31, in <module>
    import cx_Oracle
  File "build/bdist.macosx-10.8-x86_64/egg/cx_Oracle.py", line 7, in <module>
  File "build/bdist.macosx-10.8-x86_64/egg/cx_Oracle.py", line 6, in __bootstrap__
ImportError: dlopen(/Users/xxx/.python-eggs/cx_Oracle-5.1.3-py2.7-macosx-10.8-x86_64.egg-tmp/cx_Oracle.so, 2): no suitable image found.  Did find:
    /Users/xxx/.python-eggs/cx_Oracle-5.1.3-py2.7-macosx-10.8-x86_64.egg-tmp/cx_Oracle.so: mach-o, but wrong architecture

最佳答案

以 root 身份运行这些:

export CFLAGS=-Qunused-arguments
export CPPFLAGS=-Qunused-arguments

然后必须做的:

pip uninstall MySQL-python
brew uninstall mysql
brew install mysql --universal
pip install MySQL-python

不确定它是否会成功,但它至少是一条新的错误消息。

关于python - 导入错误 : No module named _mssql,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25392402/

相关文章:

python - 使用 python 3.3 访问 mssql 数据库的最佳方法

python - 带有 ArcGIS 的 Flask 应用程序,Arcpy 不运行

Python串行在shell中工作但在脚本中不起作用?

python - 如何在不写/读的情况下在 Python 中执行 JPEG 压缩

python - 无法从 linux pyodbc 连接到 SQL Server

python - pymssql执行许多插入值错误

python - 使用 python 列出服务器上所有可用的 MS SQL 数据库的名称

python - pymssql : Inserting mutliple values into a table

python - python中如何简单的使用兼容普通函数和协程函数的装饰器?

python - 当存在 2 个版本的 python 时安装 COCOAPI