Python不加载\u fileio库

2024-10-02 22:36:00 发布

您现在位置:Python中文网/ 问答频道 /正文

我有个问题,Python不加载动态c库文件io

~ $ python
Python 2.7.1+ (r271:86832, Apr 11 2011, 18:05:24) 
[GCC 4.5.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
Could not open PYTHONSTARTUP
IOError: [Errno 2] No such file or directory: '/home/sven/.pythonrc'
>>> import io
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python2.6/io.py", line 63, in <module>
    import _fileio
ImportError: No module named _fileio
>>> 

~ $ locate _fileio
/usr/lib/python2.6/lib-dynload/_fileio.so 

~ $ echo $PYTHONPATH
/usr/lib/python2.6/

你好,斯文


Tags: or文件noinioimportlibusr
2条回答

似乎是一个环境问题,源于这一行:

IOError: [Errno 2] No such file or directory: '/home/sven/.pythonrc'

要解决此问题,请找到.pythonrc,并确保.bashrc文件中的PYTHONSTARTUP环境变量指向此文件位置。如果它实际上是正确的,请尝试使用硬编码路径/home/sven/.pythonrc,而不是使用{}之类的路径。在

另外,如果我没记错的话,.pythonrc实际上应该是一个*.py文件,但这可能会因分布而异。在

我的zshrc文件中有这一行

export PYTHONPATH=/usr/lib/python2.6

但是ubuntu默认使用python2.7.1

当我从上面删除这一行时,错误消息消失了。在

对不起,我的错。在

相关问题 更多 >