python3.4:虽然安装在我的系统上,但未加载pylirc模块

时间:2016-01-09 08:24:27

标签: python-3.4

您好! 在python3脚本中导入时无法找到pylirc。但对于python2,它的工作原理。 我使用pip3来安装pylirc,因为我的Linux发行版没有python3的包pylirc。但它有python2。 这是python3中的某个错误吗?你认为有解决方法吗?

> python3 -c 'import pylirc' 
Traceback (most recent call last):
  File "<string>", line 1, in <module>
ImportError: No module named 'pylirc'

> lsb_release -a
No LSB modules are available.
Distributor ID: LinuxMint
Description:    Linux Mint 17.3 Rosa
Release:    17.3
Codename:   rosa


> sudo pip3 install pylirc2            
Downloading/unpacking pylirc2
  Downloading pylirc2-0.1.tar.gz
  Running setup.py (path:/tmp/pip_build_root/pylirc2/setup.py) egg_info for package pylirc2

Installing collected packages: pylirc2
  Running setup.py install for pylirc2
    building 'pylircmodule' extension
    x86_64-linux-gnu-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -g -fstack-protector --param=ssp-buffer-size=4 -Wformat -Werror=format-security -D_FORTIFY_SOURCE=2 -fPIC -I/usr/include/python3.4m -c pylircmodule.c -o build/temp.linux-x86_64-3.4/pylircmodule.o
    pylircmodule.c: In function ‘initpylirc’:
    pylircmodule.c:272:5: warning: implicit declaration of function ‘Py_InitModule’ [-Wimplicit-function-declaration]
         (void) Py_InitModule("pylirc", pylircMethods);
         ^
    x86_64-linux-gnu-gcc -pthread -shared -Wl,-O1 -Wl,-Bsymbolic-functions -Wl,-Bsymbolic-functions -Wl,-z,relro -Wl,-Bsymbolic-functions -Wl,-z,relro -g -fstack-protector --param=ssp-buffer-size=4 -Wformat -Werror=format-security -D_FORTIFY_SOURCE=2 build/temp.linux-x86_64-3.4/pylircmodule.o -llirc_client -o build/lib.linux-x86_64-3.4/pylircmodule.cpython-34m.so

Successfully installed pylirc2
Cleaning up...

> find /usr/local/lib/python3.4/ -name '*pylirc*'
/usr/local/lib/python3.4/dist-packages/pylircmodule.cpython-34m.so
/usr/local/lib/python3.4/dist-packages/pylirc2-0.1.egg-info

> strace python3 -c 'import pylirc'
...
open("<string>", O_RDONLY|O_CLOEXEC)    = -1 ENOENT (No such file or directory)
open("<string>", O_RDONLY|O_CLOEXEC)    = -1 ENOENT (No such file or directory)
open("/usr/lib/python3.4/<string>", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
open("/usr/lib/python3.4/plat-x86_64-linux-gnu/<string>", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
open("/usr/lib/python3.4/lib-dynload/<string>", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
open("/usr/local/lib/python3.4/dist-packages/<string>", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
open("/usr/lib/python3/dist-packages/<string>", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
write(2, "ImportError: No module named 'py"..., 38ImportError: No module named 'pylirc'

从strace中可以看出python不会尝试在其路径中找到pylirc。这很奇怪(或者不是?)。不知何故,python正在寻找&lt;字符串&gt; 而不是pylirc。 这里的魔力是什么? : - )

更多信息: python3 -v key显示了我的其他信息

...
Python 3.4.3 (default, Oct 14 2015, 20:28:29) 
[GCC 4.8.4] on linux
Type "help", "copyright", "credits" or "license" for more information.
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "<frozen importlib._bootstrap>", line 2237, in _find_and_load
  File "<frozen importlib._bootstrap>", line 2224, in _find_and_load_unlocked
ImportError: No module named 'pylirc'
...

1 个答案:

答案 0 :(得分:0)

似乎pylirc c模块与python3不兼容。因为pylirc不像这里描述的https://docs.python.org/3/howto/cporting.html那样调用PyModule_Create()。 pylirc https://github.com/offlinehacker-playground/pylirc2/blob/master/pylircmodule.c

的代码