【问题标题】:ImportError: No module named _mssqlImportError:没有名为 _mssql 的模块
【发布时间】:2014-10-13 02:00:58
【问题描述】:

我在 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 并得到:

Warning: freetds-0.91 already installed, it's just not linked

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

编辑:我已经链接了它,所以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

【问题讨论】:

  • 我有点绝望了——我会尽可能地增加赏金(明天有资格),但如果有人能早点提供帮助,我保证我会给予无论如何,你是赏金!
  • 运行pip install pymssql时得到什么输出?
  • 看起来它正试图将它安装在您没有写入权限的主目录之外的某个位置。也许尝试以root身份运行pip install pymssql:p
  • 你试过简单的brew link freetds吗?
  • 您正在编译 64 位二进制文​​件并链接到 32 位架构,oracle 回溯显示您 x86_64

标签: python pymssql


【解决方案1】:

以 root 身份运行这些:

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

然后不得不做:

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

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

【讨论】:

  • 您应该在它被标记为未回答并被删除之前通过对您的问题进行编辑来移动它。
  • @AaronHall 为什么?这似乎是一个答案,如果不是一个确定的答案。
  • 好吧,我想我可能理解错了。
  • 不,我认为你是对的,事实上。我在安装时用手指交叉输入了它。
【解决方案2】:

尝试使用ldconfig

取自手册页:

ldconfig 创建必要的链接并缓存到在命令行指定的目录、文件 /etc/ld.so.conf 和受信任的目录中找到的最新共享库(/lib 和 /usr/lib)。

【讨论】:

    猜你喜欢
    • 2013-03-11
    • 2012-12-07
    • 2012-05-23
    • 2019-07-29
    • 2015-07-04
    • 2014-03-15
    • 2017-12-29
    • 2014-09-12
    • 2017-05-09
    相关资源
    最近更新 更多