推荐学习书目
› Learn Python the Hard Way
Python Sites
› PyPI - Python Package Index
› http://diveintopython.org/toc/index.html
› Pocoo
值得关注的项目
› PyPy
› Celery
› Jinja2
› Read the Docs
› gevent
› pyenv
› virtualenv
› Stackless Python
› Beautiful Soup
› 结巴中文分词
› Green Unicorn
› Sentry
› Shovel
› Pyflakes
› pytest
Python 编程
› pep8 Checker
Styles
› PEP 8
› Google Python Style Guide
› Code Style from The Hitchhiker's Guide
bin381
V2EX  ›  Python

python 虚拟环境(pyenv)下 python 调用 C so 报错?

  •  
  •   bin381 · Dec 25, 2016 · 3378 views
    This topic created in 3562 days ago, the information mentioned may be changed or developed.
    环境
    osx version:10.11.5
    python version:2.7.10

    我编译一个 c 文件:
    gcc -fPIC test.c -shared -lpython2.7 -L /usr/lib/python2.7/ -I /usr/include/python2.7/ -o test.so

    然后我得到了一个 test.so

    如果在系统环境下的 python 执行 import test 是没有问题的。
    但是如果在 python 虚拟环境下(pyenv , python 版本是一样的), import test 就会报错

    Fatal Python error: PyThreadState_Get: no current thread
    [1] 97703 abort python
    5 replies  •  2016-12-26 10:11:12 +08:00
    phrack
        1
    phrack  
       Dec 25, 2016 via Android
    我本来还想等其他大神提出看法呢。。。等了这么久没人答。。。

    你的信息不是很足,可以多提供一点。

    import 如果没有找到 module 不会报 fatal error 的,所以你这里的问题不是 Python 没有找到 test 这个模块,而是其他的问题。
    izoabr
        2
    izoabr  
       Dec 25, 2016
    我怎么记得 test 是个保留字呢
    glogo
        3
    glogo  
       Dec 26, 2016
    可以把 test.py 的内容列出来看下
    bin381
        4
    bin381  
    OP
       Dec 26, 2016
    @phrack 我也没有什么信息可以提供了。主要是在自带的终端下是可以 import 的,但是 active 一个 pyenv 之后, import 就不成功了。我试过在 Linux 上编译,并没有出现这样的情况。自己也百思不得其解
    bin381
        5
    bin381  
    OP
       Dec 26, 2016
    @izoabr 跟 test 没有关系,我换了个别的 module name 也是不行。
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   2657 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 27ms · UTC 09:08 · PVG 17:08 · LAX 02:08 · JFK 05:08
    ♥ Do have faith in what you're doing.