V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
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 · 2016-12-25 17:14:48 +08:00 · 2170 次点击
    这是一个创建于 2686 天前的主题,其中的信息可能已经有所发展或是发生改变。
    环境
    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 条回复    2016-12-26 10:11:12 +08:00
    phrack
        1
    phrack  
       2016-12-25 20:30:50 +08:00 via Android
    我本来还想等其他大神提出看法呢。。。等了这么久没人答。。。

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

    import 如果没有找到 module 不会报 fatal error 的,所以你这里的问题不是 Python 没有找到 test 这个模块,而是其他的问题。
    izoabr
        2
    izoabr  
       2016-12-25 21:33:49 +08:00
    我怎么记得 test 是个保留字呢
    glogo
        3
    glogo  
       2016-12-26 03:32:13 +08:00
    可以把 test.py 的内容列出来看下
    bin381
        4
    bin381  
    OP
       2016-12-26 10:10:41 +08:00
    @phrack 我也没有什么信息可以提供了。主要是在自带的终端下是可以 import 的,但是 active 一个 pyenv 之后, import 就不成功了。我试过在 Linux 上编译,并没有出现这样的情况。自己也百思不得其解
    bin381
        5
    bin381  
    OP
       2016-12-26 10:11:12 +08:00
    @izoabr 跟 test 没有关系,我换了个别的 module name 也是不行。
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   790 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 28ms · UTC 22:06 · PVG 06:06 · LAX 15:06 · JFK 18:06
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.