ImportError:没有名为_mssql的模块

时间:2014-08-19 20:26:58

标签: 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并得到:

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

2 个答案:

答案 0 :(得分:2)

以root身份运行这些:

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

然后必须这样做:

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

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

答案 1 :(得分:0)

尝试使用ldconfig

摘自手册页:

  

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

相关问题